Commit ea70661f authored by Martin Schultz's avatar Martin Schultz

* objLoader uses fast Atof implementation

parent 1ed3727b
......@@ -32,6 +32,39 @@ namespace
int normal;
};
// Really naive implementtion of atof but fast
// if parsing fails std::atof is used the format we expect is a float with a . as decimal point
float fastAtof(const char * _begin ,const char* _end) {
const char* p = _begin;
float r = 0.0;
bool neg = false;
if (*p == '-') {
neg = true;
++p;
}
while (*p >= '0' && *p <= '9' && p <= _end) {
r = (r*10.0) + (*p - '0');
++p;
}
if (*p == '.' && p <= _end) {
float f = 0.0;
int n = 0;
++p;
while (*p >= '0' && *p <= '9' && p <= _end) {
f = (f*10.0) + (*p - '0');
++p;
++n;
}
r += f / std::pow(10.0, n);
}
if (neg) {
r = -r;
}
if(p < _end) //we didnt reach the end something went wrong
return std::atof(_begin);
return r;
}
// Parses a string of space-separated numbers into a packed floating-point vector (_data) with a maximum number of _maxDimension elements
void parseVector(const char* _start , const char* _end, int _maxDimension, int& _dimension, float* _data)
{
......@@ -46,7 +79,7 @@ namespace
while (_dimension < _maxDimension && it < end)
{
found = std::find(it, end, ' ');
_data[_dimension++] = std::atof(it);
_data[_dimension++] = fastAtof(it,found-1);
it = found == end ? end : found + 1;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment