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())
}
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);
+ ObjFileParser parser(m_Buffer, modelName, pIOHandler, m_progress);
// And create the proper return structures out of it
CreateDataFromImport(parser.GetModel(), pScene);
// -------------------------------------------------------------------
// Constructor with loaded data and directories.
-ObjFileParser::ObjFileParser(std::vector<char> &data,const std::string &modelName, IOSystem *io ) :
+ObjFileParser::ObjFileParser(std::vector<char> &data,const std::string &modelName, IOSystem *io, ProgressHandler* progress ) :
m_DataIt(data.begin()),
m_DataItEnd(data.end()),
m_pModel(NULL),
m_uiLine(0),
- m_pIO( io )
+ m_pIO( io ),
+ m_progress(progress)
{
std::fill_n(m_buffer,Buffersize,0);
if (m_DataIt == m_DataItEnd)
return;
+ // only update every 100KB or it'll be too slow
+ const unsigned int updateProgressEveryBytes = 100 * 1024;
+ unsigned int progressCounter = 0;
+ const unsigned int bytesToProcess = std::distance(m_DataIt, m_DataItEnd);
+ const unsigned int progressTotal = 3 * bytesToProcess;
+ const unsigned int progressOffset = bytesToProcess;
+ unsigned int processed = 0;
+
+ DataArrayIt lastDataIt = m_DataIt;
+
while (m_DataIt != m_DataItEnd)
{
+ // Handle progress reporting
+ processed += std::distance(lastDataIt, m_DataIt);
+ lastDataIt = m_DataIt;
+ if (processed > (progressCounter * updateProgressEveryBytes))
+ {
+ progressCounter++;
+ m_progress->UpdateFileRead(progressOffset + processed*2, progressTotal);
+ }
+
+ // parse line
switch (*m_DataIt)
{
case 'v': // Parse a vertex texture coordinate
class ObjFileImporter;
class IOSystem;
+class ProgressHandler;
/// \class ObjFileParser
/// \brief Parser for a obj waveform file
public:
/// \brief Constructor with data array.
- ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io);
+ ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io, ProgressHandler* progress);
/// \brief Destructor
~ObjFileParser();
/// \brief Model getter.
char m_buffer[Buffersize];
/// Pointer to IO system instance.
IOSystem *m_pIO;
+ //! Pointer to progress handler
+ ProgressHandler* m_progress;
/// Path to the current model
};