some code cleanup for xml parsing and loading saved games
This commit is contained in:
parent
b7267c9176
commit
5249ecc45d
|
@ -6457,8 +6457,6 @@ string Game::saveGame(string name, string path) {
|
|||
infoNode->addAttribute("color",info.color.getString(), mapTagReplacements);
|
||||
}
|
||||
|
||||
gameNode->addAttribute("timeDisplay",intToStr(timeDisplay), mapTagReplacements);
|
||||
|
||||
gameNode->addAttribute("disableSpeedChange",intToStr(disableSpeedChange), mapTagReplacements);
|
||||
|
||||
xmlTree.save(saveGameFile);
|
||||
|
|
|
@ -287,17 +287,27 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||
if(fileExists(filename) == true) {
|
||||
Lang &lang= Lang::getInstance();
|
||||
|
||||
// Xerces is infinitely slower than rapidxml
|
||||
// XmlTree xmlTree(XML_XERCES_ENGINE);
|
||||
XmlTree xmlTree(XML_RAPIDXML_ENGINE);
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Before load of XML\n");
|
||||
std::map<string,string> mapExtraTagReplacementValues;
|
||||
xmlTree.load(filename, Properties::getTagReplacementValues(&mapExtraTagReplacementValues),true);
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("After load of XML\n");
|
||||
|
||||
const XmlNode *rootNode= xmlTree.getRootNode();
|
||||
if(rootNode->hasChild("megaglest-saved-game") == true) {
|
||||
if(rootNode != NULL && rootNode->hasChild("megaglest-saved-game") == true) {
|
||||
rootNode = rootNode->getChild("megaglest-saved-game");
|
||||
}
|
||||
|
||||
if(rootNode == NULL) {
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"Invalid XML saved game file: [%s]",filename.c_str());
|
||||
infoTextLabel.setText(szBuf);
|
||||
return;
|
||||
}
|
||||
|
||||
const XmlNode *versionNode= rootNode;
|
||||
string gameVer = versionNode->getAttribute("version")->getValue();
|
||||
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
||||
|
|
|
@ -97,7 +97,6 @@ public:
|
|||
class XmlIoRapid {
|
||||
private:
|
||||
static bool initialized;
|
||||
xml_document<> *doc;
|
||||
|
||||
private:
|
||||
XmlIoRapid();
|
||||
|
|
|
@ -289,22 +289,12 @@ XmlIoRapid::XmlIoRapid() {
|
|||
|
||||
void XmlIoRapid::init() {
|
||||
try{
|
||||
//printf("XmlIo init\n");
|
||||
|
||||
XmlIoRapid::initialized= true;
|
||||
}
|
||||
catch(const exception &e){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error initializing XML system, msg %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what());
|
||||
throw megaglest_runtime_error("Error initializing XML system");
|
||||
}
|
||||
|
||||
try {
|
||||
doc = new xml_document<>();
|
||||
}
|
||||
catch(const DOMException &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while creating XML parser, msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.getMessage());
|
||||
throw megaglest_runtime_error("Exception while creating XML parser");
|
||||
}
|
||||
}
|
||||
|
||||
bool XmlIoRapid::isInitialized() {
|
||||
|
@ -323,9 +313,6 @@ XmlIoRapid &XmlIoRapid::getInstance() {
|
|||
void XmlIoRapid::cleanup() {
|
||||
if(XmlIoRapid::initialized == true) {
|
||||
XmlIoRapid::initialized= false;
|
||||
//printf("XmlIo cleanup\n");
|
||||
delete doc;
|
||||
doc = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,11 +381,12 @@ XmlNode *XmlIoRapid::load(const string &path, const std::map<string,string> &map
|
|||
|
||||
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
doc->parse<parse_no_data_nodes>(&buffer.front());
|
||||
xml_document<> doc;
|
||||
doc.parse<parse_no_data_nodes>(&buffer.front());
|
||||
|
||||
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
rootNode= new XmlNode(doc->first_node(),mapTagReplacementValues);
|
||||
rootNode= new XmlNode(doc.first_node(),mapTagReplacementValues);
|
||||
|
||||
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
|
@ -521,6 +509,8 @@ static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheNam
|
|||
void XmlTree::load(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation,bool skipStackCheck) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] skipStackCheck = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),skipStackCheck);
|
||||
|
||||
clearRootNode();
|
||||
|
||||
this->skipStackCheck = skipStackCheck;
|
||||
if(this->skipStackCheck == false) {
|
||||
//printf("XmlTree::load p [%p]\n",this);
|
||||
|
@ -540,6 +530,7 @@ void XmlTree::load(const string &path, const std::map<string,string> &mapTagRepl
|
|||
}
|
||||
|
||||
loadPath = path;
|
||||
|
||||
if(this->engine_type == XML_XERCES_ENGINE) {
|
||||
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue