From 5b664fb1a25a1f595ac9e79ff9def8fa54d24f3a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 21 May 2013 20:28:42 +0000 Subject: [PATCH] - bugfix for transifex tutorial download files now loaded into UI - updated each thread to provide its name --- source/glest_game/ai/ai_interface.cpp | 1 + source/glest_game/game/commander.cpp | 1 + source/glest_game/game/game.cpp | 10 ++++++-- source/glest_game/game/game.h | 1 - source/glest_game/global/lang.cpp | 16 ++++++++++-- source/glest_game/global/lang.h | 2 +- .../menu/menu_state_connected_game.cpp | 10 +++++--- .../menu/menu_state_custom_game.cpp | 6 +++-- .../glest_game/menu/menu_state_scenario.cpp | 3 ++- .../glest_game/network/client_interface.cpp | 1 + source/glest_game/network/connection_slot.cpp | 2 ++ source/glest_game/type_instances/faction.cpp | 1 + source/glest_game/world/scenario.cpp | 25 ++++++++++++++++--- source/glest_game/world/scenario.h | 3 ++- .../platform/common/simple_threads.cpp | 4 +++ .../sources/platform/posix/ircclient.cpp | 1 + .../sources/platform/posix/miniftpclient.cpp | 2 ++ .../sources/platform/posix/miniftpserver.cpp | 2 ++ .../sources/platform/posix/socket.cpp | 2 ++ .../sources/platform/sdl/thread.cpp | 3 ++- 20 files changed, 79 insertions(+), 17 deletions(-) diff --git a/source/glest_game/ai/ai_interface.cpp b/source/glest_game/ai/ai_interface.cpp index 805aa683..aa0e18c9 100644 --- a/source/glest_game/ai/ai_interface.cpp +++ b/source/glest_game/ai/ai_interface.cpp @@ -40,6 +40,7 @@ AiInterfaceThread::AiInterfaceThread(AiInterface *aiIntf) : BaseThread() { this->masterController = NULL; this->triggerIdMutex = new Mutex(); this->aiIntf = aiIntf; + uniqueID = "AiInterfaceThread"; } AiInterfaceThread::~AiInterfaceThread() { diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index d9c77a55..986d5400 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -40,6 +40,7 @@ namespace Glest{ namespace Game{ CommanderNetworkThread::CommanderNetworkThread() : BaseThread() { this->idStatus = make_pair(-1,false); this->commanderInterface = NULL; + uniqueID = "CommanderNetworkThread"; } CommanderNetworkThread::CommanderNetworkThread(CommanderNetworkCallbackInterface *commanderInterface) : BaseThread() { diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 4577f67b..301a8bb5 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1134,7 +1134,11 @@ void Game::load(int loadTypes) { if((loadTypes & lgt_Scenario) == lgt_Scenario) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(scenarioName.empty() == false) { - Lang::getInstance().loadScenarioStrings(gameSettings.getScenarioDir(), scenarioName); + + bool isTutorial = Scenario::isGameTutorial(gameSettings.getScenarioDir()); + //printf("Loading scenario gameSettings.getScenarioDir() [%s] scenarioName [%s] isTutorial: %d\n",gameSettings.getScenarioDir().c_str(),scenarioName.c_str(),isTutorial); + + Lang::getInstance().loadScenarioStrings(gameSettings.getScenarioDir(), scenarioName, isTutorial); //printf("In [%s::%s Line: %d] rootNode [%p][%s]\n",__FILE__,__FUNCTION__,__LINE__,loadGameNode,(loadGameNode != NULL ? loadGameNode->getName().c_str() : "none")); world.loadScenario(gameSettings.getScenarioDir(), &checksum, false,loadGameNode); @@ -2451,8 +2455,10 @@ void Game::update() { //printf("\nname [%s] scenarioFile [%s] results.size() = " MG_SIZE_T_SPECIFIER "\n",name.c_str(),scenarioFile.c_str(),results.size()); //printf("[%s:%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + + bool isTutorial = Scenario::isGameTutorial(scenarioFile); ScenarioInfo scenarioInfo; - Scenario::loadScenarioInfo(scenarioFile, &scenarioInfo); + Scenario::loadScenarioInfo(scenarioFile, &scenarioInfo, isTutorial); //printf("[%s:%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); GameSettings gameSettings; diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 052a045b..355db9d2 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -373,7 +373,6 @@ private: bool switchSetupForSlots(ServerInterface *& serverInterface, int startIndex, int endIndex, bool onlyNetworkUnassigned); - }; }}//end namespace diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index a88f6873..def70ee1 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -206,12 +206,20 @@ bool Lang::isUTF8Language() const { return is_utf8_language; } -void Lang::loadScenarioStrings(string scenarioDir, string scenarioName){ +void Lang::loadScenarioStrings(string scenarioDir, string scenarioName, bool isTutorial) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scenarioDir = [%s] scenarioName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioDir.c_str(),scenarioName.c_str()); + //printf("Loading scenario scenarioDir [%s] scenarioName [%s]\n",scenarioDir.c_str(),scenarioName.c_str()); + // First try to find scenario lng file in userdata Config &config = Config::getInstance(); - vector scenarioPaths = config.getPathListForType(ptScenarios); + vector scenarioPaths; + if(isTutorial == false) { + scenarioPaths = config.getPathListForType(ptScenarios); + } + else { + scenarioPaths = config.getPathListForType(ptTutorials); + } if(scenarioPaths.size() > 1) { string &scenarioPath = scenarioPaths[1]; endPathWithSlash(scenarioPath); @@ -242,6 +250,8 @@ void Lang::loadScenarioStrings(string scenarioDir, string scenarioName){ //try to load the current language first if(fileExists(path)) { + //printf("#2 Loading scenario path [%s]\n",path.c_str()); + scenarioStrings.load(path); } else{ @@ -252,6 +262,8 @@ void Lang::loadScenarioStrings(string scenarioDir, string scenarioName){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); if(fileExists(path)){ + //printf("#3 Loading scenario path [%s]\n",path.c_str()); + scenarioStrings.load(path); } } diff --git a/source/glest_game/global/lang.h b/source/glest_game/global/lang.h index 02d8520f..155c2448 100644 --- a/source/glest_game/global/lang.h +++ b/source/glest_game/global/lang.h @@ -56,7 +56,7 @@ public: static Lang &getInstance(); void loadStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false); - void loadScenarioStrings(string scenarioDir, string scenarioName); + void loadScenarioStrings(string scenarioDir, string scenarioName, bool isTutorial); void loadTechTreeStrings(string techTree); void loadTilesetStrings(string tileset); diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 6cca2239..1d030373 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -466,7 +466,8 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM try { if(file != "") { - Scenario::loadScenarioInfo(file, &scenarioInfo); + bool isTutorial = Scenario::isGameTutorial(file); + Scenario::loadScenarioInfo(file, &scenarioInfo, isTutorial); bool isNetworkScenario = false; for(unsigned int j = 0; isNetworkScenario == false && j < GameConstants::maxPlayers; ++j) { @@ -4278,7 +4279,9 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, string scenario = gameSettings->getScenario(); listBoxScenario.setSelectedItem(formatString(scenario)); string file = Scenario::getScenarioPath(dirList, scenario); - Scenario::loadScenarioInfo(file, &scenarioInfo); + + bool isTutorial = Scenario::isGameTutorial(file); + Scenario::loadScenarioInfo(file, &scenarioInfo, isTutorial); gameSettings->setScenarioDir(Scenario::getScenarioPath(dirList, scenarioInfo.name)); @@ -4971,7 +4974,8 @@ void MenuStateConnectedGame::setupTilesetList(string scenario) { void MenuStateConnectedGame::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) { //printf("Load scenario file [%s]\n",file.c_str()); - Scenario::loadScenarioInfo(file, scenarioInfo); + bool isTutorial = Scenario::isGameTutorial(file); + Scenario::loadScenarioInfo(file, scenarioInfo, isTutorial); //cleanupPreviewTexture(); previewLoadDelayTimer=time(NULL); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 481f41c1..e577a229 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -668,7 +668,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, try { if(file != "") { - Scenario::loadScenarioInfo(file, &scenarioInfo); + bool isTutorial = Scenario::isGameTutorial(file); + Scenario::loadScenarioInfo(file, &scenarioInfo, isTutorial); bool isNetworkScenario = false; for(unsigned int j = 0; isNetworkScenario == false && j < GameConstants::maxPlayers; ++j) { @@ -4207,7 +4208,8 @@ int32 MenuStateCustomGame::getNetworkPlayerStatus() { void MenuStateCustomGame::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) { //printf("Load scenario file [%s]\n",file.c_str()); - Scenario::loadScenarioInfo(file, scenarioInfo); + bool isTutorial = Scenario::isGameTutorial(file); + Scenario::loadScenarioInfo(file, scenarioInfo, isTutorial); //cleanupPreviewTexture(); previewLoadDelayTimer=time(NULL); diff --git a/source/glest_game/menu/menu_state_scenario.cpp b/source/glest_game/menu/menu_state_scenario.cpp index 9cc6057d..94a1b79d 100644 --- a/source/glest_game/menu/menu_state_scenario.cpp +++ b/source/glest_game/menu/menu_state_scenario.cpp @@ -347,7 +347,8 @@ void MenuStateScenario::setScenario(int i) { } void MenuStateScenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) { - Scenario::loadScenarioInfo(file, scenarioInfo); + bool isTutorial = Scenario::isGameTutorial(file); + Scenario::loadScenarioInfo(file, scenarioInfo, isTutorial); cleanupPreviewTexture(); previewLoadDelayTimer=time(NULL); diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 2f473d25..36d5804a 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -45,6 +45,7 @@ const bool debugClientInterfacePerf = false; ClientInterfaceThread::ClientInterfaceThread(ClientInterface *client) : BaseThread() { this->clientInterface = client; + uniqueID = "ClientInterfaceThread"; } ClientInterfaceThread::~ClientInterfaceThread() { diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 6807ffc0..ee676f52 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -37,6 +37,7 @@ ConnectionSlotThread::ConnectionSlotThread(int slotIndex) : BaseThread() { this->triggerIdMutex = new Mutex(); this->slotIndex = slotIndex; this->slotInterface = NULL; + uniqueID = "ConnectionSlotThread"; //this->event = NULL; eventList.clear(); eventList.reserve(100); @@ -47,6 +48,7 @@ ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slot this->triggerIdMutex = new Mutex(); this->slotIndex = slotIndex; this->slotInterface = slotInterface; + uniqueID = "ConnectionSlotThread"; //this->event = NULL; eventList.clear(); } diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 4f2b0c53..7b30ab50 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -216,6 +216,7 @@ FactionThread::FactionThread(Faction *faction) : BaseThread() { this->triggerIdMutex = new Mutex(); this->faction = faction; this->masterController = NULL; + uniqueID = "FactionThread"; } FactionThread::~FactionThread() { diff --git a/source/glest_game/world/scenario.cpp b/source/glest_game/world/scenario.cpp index 38a9ab20..7d7f2a0d 100644 --- a/source/glest_game/world/scenario.cpp +++ b/source/glest_game/world/scenario.cpp @@ -54,7 +54,8 @@ Checksum Scenario::load(const string &path) { snprintf(szBuf,8096,Lang::getInstance().get("LogScreenGameLoadingScenario","",true).c_str(),formatString(name).c_str()); Logger::getInstance().add(szBuf, true); - Scenario::loadScenarioInfo(path, &info); + bool isTutorial = Scenario::isGameTutorial(path); + Scenario::loadScenarioInfo(path, &info, isTutorial); //parse xml XmlTree xmlTree; @@ -153,7 +154,25 @@ string Scenario::getFunctionName(const XmlNode *scriptNode){ return name; } -void Scenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) { +bool Scenario::isGameTutorial(string path) { + bool isTutorial = false; + Config &config = Config::getInstance(); + vector tutorialPaths = config.getPathListForType(ptTutorials); + if(tutorialPaths.empty() == false) { + for(unsigned int tutorialIndex = 0; tutorialIndex < tutorialPaths.size(); ++tutorialIndex) { + const string &tutorialPath = tutorialPaths[tutorialIndex]; + size_t pos = path.find( tutorialPath ); + if( pos != path.npos ) { + isTutorial = true; + break; + } + } + } + + return isTutorial; +} + +void Scenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo, bool isTutorial) { //printf("[%s:%s] Line: %d file [%s]\n",__FILE__,__FUNCTION__,__LINE__,file.c_str()); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,file.c_str()); //printf("In [%s::%s Line: %d] file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,file.c_str()); @@ -309,7 +328,7 @@ void Scenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) { //look for description and append it - lang.loadScenarioStrings(scenarioDir,scenarioName.c_str()); + lang.loadScenarioStrings(scenarioDir,scenarioName.c_str(),isTutorial); //string tmp_description = lang.getScenarioString("DESCRIPTION"); string tmp_description = ""; if(lang.hasScenarioString("DESCRIPTION") == true) { diff --git a/source/glest_game/world/scenario.h b/source/glest_game/world/scenario.h index da1e0e09..5711998d 100644 --- a/source/glest_game/world/scenario.h +++ b/source/glest_game/world/scenario.h @@ -135,12 +135,13 @@ public: ScenarioInfo getInfo() const { return info; } + static bool isGameTutorial(string path); static string getScenarioPath(const vector dir, const string &scenarioName, bool getMatchingRootScenarioPathOnly=false); static string getScenarioPath(const string &dir, const string &scenarioName); static int getScenarioPathIndex(const vector dirList, const string &scenarioName); static string getScenarioDir(const vector dir, const string &scenarioName); - static void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo); + static void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo,bool isTutorial); static ControlType strToControllerType(const string &str); static string controllerTypeToStr(const ControlType &ct); diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 52868fba..005d06de 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -31,6 +31,7 @@ FileCRCPreCacheThread::FileCRCPreCacheThread() : BaseThread() { techDataPaths.clear(); workerThreadTechPaths.clear(); processTechCB = NULL; + uniqueID = "FileCRCPreCacheThread"; } FileCRCPreCacheThread::FileCRCPreCacheThread(vector techDataPaths, @@ -39,6 +40,7 @@ FileCRCPreCacheThread::FileCRCPreCacheThread(vector techDataPaths, this->techDataPaths = techDataPaths; this->workerThreadTechPaths = workerThreadTechPaths; this->processTechCB = processTechCB; + uniqueID = "FileCRCPreCacheThread"; } bool FileCRCPreCacheThread::canShutdown(bool deleteSelfIfShutdownDelayed) { @@ -346,6 +348,7 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter bool needTaskSignal) : BaseThread(), simpleTaskInterface(NULL), overrideShutdownTask(NULL) { + uniqueID = "SimpleTaskThread"; this->simpleTaskInterface = simpleTaskInterface; this->executionCount = executionCount; this->millisecsBetweenExecutions = millisecsBetweenExecutions; @@ -525,6 +528,7 @@ bool SimpleTaskThread::getTaskSignalled() { // ------------------------------------------------- LogFileThread::LogFileThread() : BaseThread() { + uniqueID = "LogFileThread"; logList.clear(); lastSaveToDisk = time(NULL); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); diff --git a/source/shared_lib/sources/platform/posix/ircclient.cpp b/source/shared_lib/sources/platform/posix/ircclient.cpp index 70c35b35..c9cee377 100644 --- a/source/shared_lib/sources/platform/posix/ircclient.cpp +++ b/source/shared_lib/sources/platform/posix/ircclient.cpp @@ -517,6 +517,7 @@ void IRCThread::setEventDataDone(bool value) { } IRCThread::IRCThread(const std::vector &argv, IRCCallbackInterface *callbackObj) : BaseThread() { + uniqueID = "IRCThread"; this->argv = argv; this->callbackObj = callbackObj; ircSession = NULL; diff --git a/source/shared_lib/sources/platform/posix/miniftpclient.cpp b/source/shared_lib/sources/platform/posix/miniftpclient.cpp index d62e5d94..19c24057 100644 --- a/source/shared_lib/sources/platform/posix/miniftpclient.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpclient.cpp @@ -242,6 +242,8 @@ FTPClientThread::FTPClientThread(int portNumber, string serverUrl, string fileArchiveExtractCommandParameters, int fileArchiveExtractCommandSuccessResult, string tempFilesPath) : BaseThread() { + + uniqueID = "FTPClientThread"; this->portNumber = portNumber; this->serverUrl = serverUrl; this->mapsPath = mapsPath; diff --git a/source/shared_lib/sources/platform/posix/miniftpserver.cpp b/source/shared_lib/sources/platform/posix/miniftpserver.cpp index 13a2a9c6..5f299f74 100644 --- a/source/shared_lib/sources/platform/posix/miniftpserver.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpserver.cpp @@ -74,6 +74,8 @@ FTPServerThread::FTPServerThread(std::pair mapsPath, bool allowInternetTilesetFileTransfers, bool allowInternetTechtreeFileTransfers, int portNumber, int maxPlayers, FTPClientValidationInterface *ftpValidationIntf, string tempFilesPath) : BaseThread() { + + uniqueID = "FTPServerThread"; this->mapsPath = mapsPath; this->tilesetsPath = tilesetsPath; this->techtreesPath = techtreesPath; diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 2cb1dca3..b24d8c3a 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -2010,6 +2010,7 @@ BroadCastClientSocketThread::BroadCastClientSocketThread(DiscoveredServersInterf if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); discoveredServersCB = cb; + uniqueID = "BroadCastClientSocketThread"; if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } @@ -2782,6 +2783,7 @@ BroadCastSocketThread::BroadCastSocketThread(int boundPort) : BaseThread() { mutexPauseBroadcast = new Mutex(); setPauseBroadcast(false); this->boundPort = boundPort; + uniqueID = "BroadCastSocketThread"; //printf("new broadcast thread [%p]\n",this); } diff --git a/source/shared_lib/sources/platform/sdl/thread.cpp b/source/shared_lib/sources/platform/sdl/thread.cpp index ce4f298f..4a635632 100644 --- a/source/shared_lib/sources/platform/sdl/thread.cpp +++ b/source/shared_lib/sources/platform/sdl/thread.cpp @@ -48,7 +48,8 @@ protected: return false; } public: - ThreadGarbageCollector() : BaseThread() { + ThreadGarbageCollector() : BaseThread() { + uniqueID = "ThreadGarbageCollector"; removeThreadFromList(); } virtual ~ThreadGarbageCollector() {