Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
imt2531-assignment2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Overkill Studios
imt2531-assignment2
Commits
3d467987
Commit
3d467987
authored
7 years ago
by
Jonas Johan Solsvik
Browse files
Options
Downloads
Patches
Plain Diff
Parser.cpp - using naive string to float
parent
6405d813
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
assets/scenes/demo1.yml
+1
-1
1 addition, 1 deletion
assets/scenes/demo1.yml
src/Parser.cpp
+68
-18
68 additions, 18 deletions
src/Parser.cpp
with
69 additions
and
19 deletions
assets/scenes/demo1.yml
+
1
−
1
View file @
3d467987
...
...
@@ -61,7 +61,7 @@ entity: skybox
angleVelocity
:
0 0
0
entity
:
sun
model
:
Suzanne
model
:
Dragon
position
:
0 0
0
rotation
:
0 0
0
scale
:
10 10
10
...
...
This diff is collapsed.
Click to expand it.
src/Parser.cpp
+
68
−
18
View file @
3d467987
...
...
@@ -288,7 +288,56 @@ auto Parser::nextKeyFloat() -> KeyFloat
}
auto
Parser
::
nextVertex
()
->
Vertex
{
auto
Parser
::
nextVertex
()
->
Vertex
{
// @doc Reading material for optimizing this function https://tinodidriksen.com/2011/05/cpp-convert-string-to-double-speed/ - 06.05.2018
// @note This is not a 'correct' implementation of string to float, and neither is it intended that way.
// This is designed to parse the floats which are present in this system only, and ONLY in the model files.
// The function concerns performance only.
// This function replaces strtof() - which is a much more correct implemetation, but was a performance bottleneck loading
// bigger models - JSolsvik 06.05.2018
auto
naiveStringToFloat
=
[](
const
char
*
p
,
const
char
**
end
)
->
float
{
float
res
=
0.0f
;
// Eat spaces
while
(
*
p
==
' '
)
++
p
;
// If negative
bool
neg
=
false
;
if
(
*
p
==
'-'
)
{
neg
=
true
;
++
p
;
}
while
(
*
p
>=
'0'
&&
*
p
<=
'9'
)
{
res
=
(
res
*
10.0f
)
+
(
*
p
-
'0'
);
++
p
;
}
if
(
*
p
==
'.'
)
{
float
f
=
0.0f
;
int
n
=
0
;
++
p
;
while
(
*
p
>=
'0'
&&
*
p
<=
'9'
)
{
f
=
(
f
*
10.0f
)
+
(
*
p
-
'0'
);
++
p
;
++
n
;
}
// Trying to optimize pow below
//res += f / std::pow(10.0, n);
// This is 10-20x faster, than above
float
tenToThePowerOfN
=
1.0
;
while
(
n
)
{
tenToThePowerOfN
*=
10.0
;
--
n
;
}
res
+=
f
/
tenToThePowerOfN
;
}
if
(
neg
)
{
res
=
-
res
;
}
*
end
=
p
;
return
res
;
};
auto
[
key
,
vertexString
,
err
]
=
keyString
();
...
...
@@ -302,29 +351,30 @@ auto Parser::nextVertex() -> Vertex {
float
nx
,
ny
,
nz
;
const
char
*
it
=
vertexString
.
data
();
const
char
*
end_
;
char
*
end
;
// Position
vert
.
x
=
strtof
(
it
,
&
end
);
it
=
end
;
vert
.
y
=
strtof
(
it
,
&
end
);
it
=
end
;
vert
.
z
=
strtof
(
it
,
&
end
);
it
=
end
;
vert
.
x
=
naiveStringToFloat
(
it
,
&
end
_
);
it
=
end
_
;
vert
.
y
=
naiveStringToFloat
(
it
,
&
end
_
);
it
=
end
_
;
vert
.
z
=
naiveStringToFloat
(
it
,
&
end
_
);
it
=
end
_
;
// Normal
nx
=
strtof
(
it
,
&
end
);
it
=
end
;
ny
=
strtof
(
it
,
&
end
);
it
=
end
;
nz
=
strtof
(
it
,
&
end
);
it
=
end
;
nx
=
naiveStringToFloat
(
it
,
&
end
_
);
it
=
end
_
;
ny
=
naiveStringToFloat
(
it
,
&
end
_
);
it
=
end
_
;
nz
=
naiveStringToFloat
(
it
,
&
end
_
);
it
=
end
_
;
// uv
u
=
strtof
(
it
,
&
end
);
it
=
end
;
v
=
strtof
(
it
,
&
end
);
it
=
end
;
u
=
naiveStringToFloat
(
it
,
&
end
_
);
it
=
end
_
;
v
=
naiveStringToFloat
(
it
,
&
end
_
);
it
=
end
_
;
// Colors
vert
.
r
=
(
GLubyte
)
strtoul
(
it
,
&
end
,
10
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment