1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 14:38:30 +02:00

Optimize editorclass::getLevelMetaData()

Now whenever it looks at a level file, it NOT parse the entire XML
document, which is a huge slowdown. Loading levels should be really
quick now.
This commit is contained in:
Misa 2020-04-17 15:31:02 -07:00 committed by Ethan Lee
parent 9aeb9ad739
commit 9c4c76f609

View File

@ -202,100 +202,32 @@ void editorclass::getDirectoryData()
} }
bool editorclass::getLevelMetaData(std::string& _path, LevelMetaData& _data ) bool editorclass::getLevelMetaData(std::string& _path, LevelMetaData& _data )
{ {
TiXmlDocument doc; unsigned char *uMem = NULL;
if (!FILESYSTEM_loadTiXmlDocument(_path.c_str(), &doc)) FILESYSTEM_loadFileToMemory(_path.c_str(), &uMem, NULL, true);
if (uMem == NULL)
{ {
printf("Level %s not found :(\n", _path.c_str()); printf("Level %s not found :(\n", _path.c_str());
return false; return false;
} }
TiXmlHandle hDoc(&doc); std::string buf((char*) uMem);
TiXmlElement* pElem;
TiXmlHandle hRoot(0);
if (find_metadata(buf) == "")
{ {
pElem=hDoc.FirstChildElement().Element(); printf("Couldn't load metadata for %s\n", _path.c_str());
// should always have a valid root but handle gracefully if it does return false;
if (!pElem)
{
printf("No valid root! Corrupt level file?\n");
}
// save this for later
hRoot=TiXmlHandle(pElem);
} }
for( pElem = hRoot.FirstChild( "Data" ).FirstChild().Element(); pElem; pElem=pElem->NextSiblingElement()) _data.creator = find_creator(buf);
{ _data.title = find_title(buf);
std::string pKey(pElem->Value()); _data.Desc1 = find_desc1(buf);
const char* pText = pElem->GetText() ; _data.Desc2 = find_desc2(buf);
if(pText == NULL) _data.Desc3 = find_desc3(buf);
{ _data.website = find_desc3(buf);
pText = "";
}
if (pKey == "MetaData") _data.filename = _path;
{ return true;
for( TiXmlElement* subElem = pElem->FirstChildElement(); subElem; subElem= subElem->NextSiblingElement())
{
std::string pKey(subElem->Value());
const char* pText = subElem->GetText() ;
if(pText == NULL)
{
pText = "";
}
_data.filename = _path;
if(pKey == "Created")
{
_data.timeCreated = pText;
}
if(pKey == "Creator")
{
_data.creator = pText;
}
if(pKey == "Title")
{
_data.title = pText;
}
if(pKey == "Modified")
{
_data.timeModified = pText;
}
if(pKey == "Modifiers")
{
_data.modifier = pText;
}
if(pKey == "Desc1")
{
_data.Desc1 = pText;
}
if(pKey == "Desc2")
{
_data.Desc2 = pText;
}
if(pKey == "Desc3")
{
_data.Desc3 = pText;
}
if(pKey == "website")
{
_data.website = pText;
}
}
}
}
return (_data.filename != "");
} }
void editorclass::reset() void editorclass::reset()