mirror of
https://github.com/glest/glest-source.git
synced 2025-08-24 08:52:49 +02:00
some code cleanup for xml parsing and loading saved games
This commit is contained in:
@@ -6457,8 +6457,6 @@ string Game::saveGame(string name, string path) {
|
|||||||
infoNode->addAttribute("color",info.color.getString(), mapTagReplacements);
|
infoNode->addAttribute("color",info.color.getString(), mapTagReplacements);
|
||||||
}
|
}
|
||||||
|
|
||||||
gameNode->addAttribute("timeDisplay",intToStr(timeDisplay), mapTagReplacements);
|
|
||||||
|
|
||||||
gameNode->addAttribute("disableSpeedChange",intToStr(disableSpeedChange), mapTagReplacements);
|
gameNode->addAttribute("disableSpeedChange",intToStr(disableSpeedChange), mapTagReplacements);
|
||||||
|
|
||||||
xmlTree.save(saveGameFile);
|
xmlTree.save(saveGameFile);
|
||||||
|
@@ -287,17 +287,27 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
if(fileExists(filename) == true) {
|
if(fileExists(filename) == true) {
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
|
// Xerces is infinitely slower than rapidxml
|
||||||
|
// XmlTree xmlTree(XML_XERCES_ENGINE);
|
||||||
XmlTree xmlTree(XML_RAPIDXML_ENGINE);
|
XmlTree xmlTree(XML_RAPIDXML_ENGINE);
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Before load of XML\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Before load of XML\n");
|
||||||
std::map<string,string> mapExtraTagReplacementValues;
|
std::map<string,string> mapExtraTagReplacementValues;
|
||||||
xmlTree.load(filename, Properties::getTagReplacementValues(&mapExtraTagReplacementValues),true);
|
xmlTree.load(filename, Properties::getTagReplacementValues(&mapExtraTagReplacementValues),true);
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("After load of XML\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("After load of XML\n");
|
||||||
|
|
||||||
const XmlNode *rootNode= xmlTree.getRootNode();
|
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");
|
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;
|
const XmlNode *versionNode= rootNode;
|
||||||
string gameVer = versionNode->getAttribute("version")->getValue();
|
string gameVer = versionNode->getAttribute("version")->getValue();
|
||||||
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
||||||
|
@@ -97,7 +97,6 @@ public:
|
|||||||
class XmlIoRapid {
|
class XmlIoRapid {
|
||||||
private:
|
private:
|
||||||
static bool initialized;
|
static bool initialized;
|
||||||
xml_document<> *doc;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XmlIoRapid();
|
XmlIoRapid();
|
||||||
|
@@ -289,22 +289,12 @@ XmlIoRapid::XmlIoRapid() {
|
|||||||
|
|
||||||
void XmlIoRapid::init() {
|
void XmlIoRapid::init() {
|
||||||
try{
|
try{
|
||||||
//printf("XmlIo init\n");
|
|
||||||
|
|
||||||
XmlIoRapid::initialized= true;
|
XmlIoRapid::initialized= true;
|
||||||
}
|
}
|
||||||
catch(const exception &e){
|
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());
|
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");
|
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() {
|
bool XmlIoRapid::isInitialized() {
|
||||||
@@ -323,9 +313,6 @@ XmlIoRapid &XmlIoRapid::getInstance() {
|
|||||||
void XmlIoRapid::cleanup() {
|
void XmlIoRapid::cleanup() {
|
||||||
if(XmlIoRapid::initialized == true) {
|
if(XmlIoRapid::initialized == true) {
|
||||||
XmlIoRapid::initialized= false;
|
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());
|
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());
|
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());
|
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) {
|
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);
|
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;
|
this->skipStackCheck = skipStackCheck;
|
||||||
if(this->skipStackCheck == false) {
|
if(this->skipStackCheck == false) {
|
||||||
//printf("XmlTree::load p [%p]\n",this);
|
//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;
|
loadPath = path;
|
||||||
|
|
||||||
if(this->engine_type == XML_XERCES_ENGINE) {
|
if(this->engine_type == XML_XERCES_ENGINE) {
|
||||||
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation);
|
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user