ObjFileParser: Moved the parsing of line continuations (backslashes) to the parsing code.

Rather than removing all backslashes followed by newlines from the buffer,
and then parsing it. Handle removing the backslashes as we go. This means
we don't need to erase the backslashes from the buffer (which is O(n))
instead we just skip those characters as we parse the buffer line by line.

This time I've fixed the order of evaluation bug in the call to getFace().
This commit is contained in:
Andrew Parlane
2016-01-23 19:40:47 -04:00
parent c7d86e97cc
commit 109f6feb6e
3 changed files with 175 additions and 242 deletions

View File

@@ -145,38 +145,6 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
modelName = pFile;
}
// This next stage takes ~ 1/3th of the total readFile task
// so should amount for 1/3th of the progress
// only update every 100KB or it'll be too slow
unsigned int progress = 0;
unsigned int progressCounter = 0;
const unsigned int updateProgressEveryBytes = 100 * 1024;
const unsigned int progressTotal = (3*m_Buffer.size()/updateProgressEveryBytes);
// process all '\'
std::vector<char> ::iterator iter = m_Buffer.begin();
while (iter != m_Buffer.end())
{
if (*iter == '\\')
{
// remove '\'
iter = m_Buffer.erase(iter);
// remove next character
while (*iter == '\r' || *iter == '\n')
iter = m_Buffer.erase(iter);
}
else
++iter;
if (++progressCounter >= updateProgressEveryBytes)
{
m_progress->UpdateFileRead(++progress, progressTotal);
progressCounter = 0;
}
}
// 1/3rd progress
m_progress->UpdateFileRead(1, 3);
// parse the file into a temporary representation
ObjFileParser parser(m_Buffer, modelName, pIOHandler, m_progress);