C
Hm..
Also deine Version braucht bei mir ca. 140 Sekunden. Meine dagegen 1,4 Sekunden. Windows 7, Visual Studio 2010.
Ich hatte zwar erwartet, dass meine wesentlich schneller sein wird (die Datei wird halt in einem Rutsch ausgelesen und dann erst geparst), aber der Vorsprung scheint mir doch unrealistisch. Kann aber keine Messfehler finden.
Ich kann meinen Code hier schlecht ganz posten, da das etwas verschachtelter ist in einem großen Projekt, aber die Grundidee sieht so aus:
Timer<f32> timer;
auto filebuf = readFile(filename);
Parser<decltype(filebuf)> parser(filebuf);
std::vector<f32> vertices;
std::vector<f32> normals;
std::vector<f32> texture_coords;
std::vector<u16> vertex_faces;
std::vector<i32> normal_faces;
std::vector<i32> texture_faces;
while (parser.parseString())
{
if (parser.lastString() == "v")
{
vertices.push_back(parseFloat(parser));
vertices.push_back(parseFloat(parser));
vertices.push_back(parseFloat(parser));
if (std::isdigit(parser.peek()))
vertices.push_back(parseFloat(parser));
}
else if (parser.lastString() == "vt")
{
texture_coords.push_back(parseFloat(parser));
texture_coords.push_back(parseFloat(parser));
if (std::isdigit(parser.peek()))
texture_coords.push_back(parseFloat(parser));
}
else if (parser.lastString() == "vn")
{
normals.push_back(parseFloat(parser));
normals.push_back(parseFloat(parser));
normals.push_back(parseFloat(parser));
}
else if (parser.lastString() == "f")
{
while (std::isdigit(parser.peek()))
{
vertex_faces.push_back(parseInt(parser) - 1);
if (parser.peek() == '/')
{
parser.skipAfter('/');
if (std::isdigit(parser.peek()))
{
texture_faces.push_back(parseInt(parser) - 1);
}
if (parser.peek() == '/')
{
parser.skipAfter('/');
normal_faces.push_back(parseInt(parser) - 1);
}
}
}
}
else //if (*parser.lastString() == '#')
{
parser.skipAfter('\n');
}
}
sys::stdlog << "Time to parse model " << filename << ": " << timer.elapsed() << std::endl;
Der Parser arbeitet intern eigentlich nur mit Iteratoren, die halt über die Daten gehen und sie entsprechend parsen. Die IOStream-Umwandlungen sind leider nicht so schnell, deshalb habe ich das auch selbst geschrieben.
Falls doch jemand interesse an dem ganzen Code hat, eben bescheid sagen, dann frickel ich das schnell aus dem Projekt raus.