diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 55b68503..0c8e310b 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -511,6 +511,70 @@ string Game::extractFactionLogoFile(bool &loadingImageUsed, string factionName, break; } } + // Check if this is a linked faction + else { + //!!! + string factionXMLFile = path + factionName + ".xml"; + + //printf("A factionXMLFile [%s]\n",factionXMLFile.c_str()); + + if(fileExists(factionXMLFile) == true) { + XmlTree xmlTreeFaction(XML_RAPIDXML_ENGINE); + std::map mapExtraTagReplacementValues; + xmlTreeFaction.load(factionXMLFile, Properties::getTagReplacementValues(&mapExtraTagReplacementValues),true,true); + + const XmlNode *rootNode= xmlTreeFaction.getRootNode(); + + //printf("B factionXMLFile [%s] root name [%s] root first child name [%s]\n",factionXMLFile.c_str(),rootNode->getName().c_str(),rootNode->getChild(0)->getName().c_str()); + //printf("B factionXMLFile [%s] root name [%s]\n",factionXMLFile.c_str(),rootNode->getName().c_str()); + if(rootNode->hasChild("link") == true) { + rootNode = rootNode->getChild("link"); + } + if(rootNode->getName() == "link" && rootNode->hasChild("techtree") == true) { + const XmlNode *linkNode = rootNode; + + //printf("C factionXMLFile [%s]\n",factionXMLFile.c_str()); + + //if(linkNode->hasChild("techtree") == true) { + const XmlNode *techtreeNode = linkNode->getChild("techtree"); + + string linkedTechTreeName = techtreeNode->getAttribute("name")->getValue(); + + //printf("D factionXMLFile [%s] linkedTechTreeName [%s]\n",factionXMLFile.c_str(),linkedTechTreeName.c_str()); + + if(linkedTechTreeName != "") { + path = currentPath + linkedTechTreeName + "/" + "factions" + "/" + factionName; + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] possible loading screen dir '%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str()); + if(isdir(path.c_str()) == true) { + endPathWithSlash(path); + + //printf("E path [%s]\n",path.c_str()); + + loadScreenList.clear(); + findAll(path + factionLogoFilter, loadScreenList, false, false); + if(loadScreenList.empty() == false) { + string factionLogo = path + loadScreenList[0]; + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for loading screen '%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,factionLogo.c_str()); + + //printf("F factionLogo [%s]\n",factionLogo.c_str()); + + if(fileExists(factionLogo) == true) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found loading screen '%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,factionLogo.c_str()); + + result = factionLogo; + if(logger != NULL) { + logger->loadLoadingScreen(result); + } + loadingImageUsed = true; + break; + } + } + } + } + //} + } + } + } } if(loadingImageUsed == true) { diff --git a/source/shared_lib/include/xml/xml_parser.h b/source/shared_lib/include/xml/xml_parser.h index fe475257..17f5d0a1 100644 --- a/source/shared_lib/include/xml/xml_parser.h +++ b/source/shared_lib/include/xml/xml_parser.h @@ -64,7 +64,7 @@ public: ~XmlIo(); void cleanup(); - XmlNode *load(const string &path, std::map mapTagReplacementValues,bool noValidation=false); + XmlNode *load(const string &path, std::map mapTagReplacementValues,bool noValidation=false, bool skipStackCheck=false); void save(const string &path, const XmlNode *node); }; @@ -81,7 +81,7 @@ public: ~XmlIoRapid(); void cleanup(); - XmlNode *load(const string &path, std::map mapTagReplacementValues,bool noValidation=false); + XmlNode *load(const string &path, std::map mapTagReplacementValues,bool noValidation=false,bool skipStackCheck=false); void save(const string &path, const XmlNode *node); }; @@ -94,6 +94,7 @@ private: XmlNode *rootNode; string loadPath; xml_engine_parser_type engine_type; + bool skipStackCheck; private: XmlTree(XmlTree&); void operator =(XmlTree&); @@ -103,7 +104,7 @@ public: ~XmlTree(); void init(const string &name); - void load(const string &path, std::map mapTagReplacementValues, bool noValidation=false); + void load(const string &path, std::map mapTagReplacementValues, bool noValidation=false,bool skipStackCheck=false); void save(const string &path); XmlNode *getRootNode() const {return rootNode;} diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index c55570c4..7171fe5e 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -105,7 +105,7 @@ XmlIo::~XmlIo() { cleanup(); } -XmlNode *XmlIo::load(const string &path, std::map mapTagReplacementValues,bool noValidation) { +XmlNode *XmlIo::load(const string &path, std::map mapTagReplacementValues,bool noValidation,bool skipStackCheck) { //printf("Load file using Xerces engine [%s]\n",path.c_str()); try { @@ -263,7 +263,7 @@ XmlIoRapid::~XmlIoRapid() { cleanup(); } -XmlNode *XmlIoRapid::load(const string &path, std::map mapTagReplacementValues,bool noValidation) { +XmlNode *XmlIoRapid::load(const string &path, std::map mapTagReplacementValues,bool noValidation,bool skipStackCheck) { Chrono chrono; chrono.start(); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Using RapidXml to load file [%s]\n",path.c_str()); @@ -390,6 +390,7 @@ void XmlIoRapid::save(const string &path, const XmlNode *node){ XmlTree::XmlTree(xml_engine_parser_type engine_type) { rootNode= NULL; this->engine_type = engine_type; + this->skipStackCheck = false; } void XmlTree::init(const string &name){ @@ -400,30 +401,33 @@ typedef std::vector LoadStack; //static LoadStack loadStack; static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheName"); -void XmlTree::load(const string &path, std::map mapTagReplacementValues, bool noValidation) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str()); +void XmlTree::load(const string &path, std::map 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); - //printf("XmlTree::load p [%p]\n",this); - assert(!loadPath.size()); + this->skipStackCheck = skipStackCheck; + if(this->skipStackCheck == false) { + //printf("XmlTree::load p [%p]\n",this); + assert(!loadPath.size()); - LoadStack &loadStack = CacheManager::getCachedItem(loadStackCacheName); - Mutex &mutex = CacheManager::getMutexForItem(loadStackCacheName); - MutexSafeWrapper safeMutex(&mutex); + LoadStack &loadStack = CacheManager::getCachedItem(loadStackCacheName); + Mutex &mutex = CacheManager::getMutexForItem(loadStackCacheName); + MutexSafeWrapper safeMutex(&mutex); - for(LoadStack::iterator it= loadStack.begin(); it!= loadStack.end(); ++it){ - if((*it)->loadPath == path){ - throw megaglest_runtime_error(path + " recursively included"); + for(LoadStack::iterator it= loadStack.begin(); it!= loadStack.end(); ++it){ + if((*it)->loadPath == path){ + throw megaglest_runtime_error(path + " recursively included"); + } } + loadStack.push_back(this); + safeMutex.ReleaseLock(); } - loadStack.push_back(this); - safeMutex.ReleaseLock(); loadPath = path; if(this->engine_type == XML_XERCES_ENGINE) { - this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation); + this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation,this->skipStackCheck); } else { - this->rootNode= XmlIoRapid::getInstance().load(path, mapTagReplacementValues, noValidation); + this->rootNode= XmlIoRapid::getInstance().load(path, mapTagReplacementValues, noValidation,this->skipStackCheck); } if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str()); @@ -441,15 +445,17 @@ void XmlTree::save(const string &path){ XmlTree::~XmlTree() { //printf("XmlTree::~XmlTree p [%p]\n",this); - LoadStack &loadStack = CacheManager::getCachedItem(loadStackCacheName); - Mutex &mutex = CacheManager::getMutexForItem(loadStackCacheName); - MutexSafeWrapper safeMutex(&mutex); + if(this->skipStackCheck == false) { + LoadStack &loadStack = CacheManager::getCachedItem(loadStackCacheName); + Mutex &mutex = CacheManager::getMutexForItem(loadStackCacheName); + MutexSafeWrapper safeMutex(&mutex); - LoadStack::iterator it= find(loadStack.begin(),loadStack.end(),this); - if(it != loadStack.end()) { - loadStack.erase(it); + LoadStack::iterator it= find(loadStack.begin(),loadStack.end(),this); + if(it != loadStack.end()) { + loadStack.erase(it); + } + safeMutex.ReleaseLock(); } - safeMutex.ReleaseLock(); delete rootNode; }