diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index 6d356c7fe..c3a72d51a 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -37,885 +37,1236 @@ using namespace Shared::Platform; using namespace Shared::Util; using namespace std; -namespace Glest{ namespace Game{ +namespace Glest +{ + namespace Game + { -int GameConstants::networkFramePeriod = 20; -int GameConstants::updateFps = 40; -int GameConstants::cameraFps = 100; + int GameConstants::networkFramePeriod = 20; + int GameConstants::updateFps = 40; + int GameConstants::cameraFps = 100; -const float GameConstants::normalMultiplier = 1.0f; -const float GameConstants::easyMultiplier = 0.5f; -const float GameConstants::ultraMultiplier = 1.5f; -const float GameConstants::megaMultiplier = 2.5f; + const float GameConstants::normalMultiplier = 1.0f; + const float GameConstants::easyMultiplier = 0.5f; + const float GameConstants::ultraMultiplier = 1.5f; + const float GameConstants::megaMultiplier = 2.5f; -const char *GameConstants::folder_path_maps = "maps"; -const char *GameConstants::folder_path_scenarios = "scenarios"; -const char *GameConstants::folder_path_techs = "techs"; -const char *GameConstants::folder_path_tilesets = "tilesets"; -const char *GameConstants::folder_path_tutorials = "tutorials"; + const char *GameConstants::folder_path_maps = "maps"; + const char *GameConstants::folder_path_scenarios = "scenarios"; + const char *GameConstants::folder_path_techs = "techs"; + const char *GameConstants::folder_path_tilesets = "tilesets"; + const char *GameConstants::folder_path_tutorials = "tutorials"; -const char *GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME = "???"; -const char *GameConstants::NETWORK_SLOT_CLOSED_SLOTNAME = "Closed"; + const char *GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME = "???"; + const char *GameConstants::NETWORK_SLOT_CLOSED_SLOTNAME = "Closed"; -const char *GameConstants::folder_path_screenshots = "screens/"; + const char *GameConstants::folder_path_screenshots = "screens/"; -const char *GameConstants::OBSERVER_SLOTNAME = "*Observer*"; -const char *GameConstants::RANDOMFACTION_SLOTNAME = "*Random*"; + const char *GameConstants::OBSERVER_SLOTNAME = "*Observer*"; + const char *GameConstants::RANDOMFACTION_SLOTNAME = "*Random*"; -const char *GameConstants::steamCacheInstanceKey = "steamInstanceCache"; -const char *GameConstants::preCacheThreadCacheLookupKey = "preCacheThreadCache"; -const char *GameConstants::ircClientCacheLookupKey = "ircClientCache"; -const char *GameConstants::playerTextureCacheLookupKey = "playerTextureCache"; -const char *GameConstants::factionPreviewTextureCacheLookupKey = "factionPreviewTextureCache"; -const char *GameConstants::characterMenuScreenPositionListCacheLookupKey = "characterMenuScreenPositionListCache"; -const char *GameConstants::application_name = "ZetaGlest"; + const char *GameConstants::steamCacheInstanceKey = "steamInstanceCache"; + const char *GameConstants::preCacheThreadCacheLookupKey = + "preCacheThreadCache"; + const char *GameConstants::ircClientCacheLookupKey = "ircClientCache"; + const char *GameConstants::playerTextureCacheLookupKey = + "playerTextureCache"; + const char *GameConstants::factionPreviewTextureCacheLookupKey = + "factionPreviewTextureCache"; + const char *GameConstants::characterMenuScreenPositionListCacheLookupKey = + "characterMenuScreenPositionListCache"; + const char *GameConstants::application_name = "ZetaGlest"; -const char * GameConstants::LOADING_SCREEN_FILE = "loading_screen"; -const char * GameConstants::LOADING_SCREEN_FILE_FILTER = "loading_screen*.*"; -const char * GameConstants::PREVIEW_SCREEN_FILE = "preview_screen"; -const char * GameConstants::PREVIEW_SCREEN_FILE_FILTER = "preview_screen*.*"; -const char * GameConstants::HUD_SCREEN_FILE = "hud"; -const char * GameConstants::HUD_SCREEN_FILE_FILTER = "hud*.*"; + const char *GameConstants::LOADING_SCREEN_FILE = "loading_screen"; + const char *GameConstants::LOADING_SCREEN_FILE_FILTER = + "loading_screen*.*"; + const char *GameConstants::PREVIEW_SCREEN_FILE = "preview_screen"; + const char *GameConstants::PREVIEW_SCREEN_FILE_FILTER = + "preview_screen*.*"; + const char *GameConstants::HUD_SCREEN_FILE = "hud"; + const char *GameConstants::HUD_SCREEN_FILE_FILTER = "hud*.*"; -const char *GameConstants::pathCacheLookupKey = "pathCache_"; -const char *GameConstants::path_data_CacheLookupKey = "data"; -const char *GameConstants::path_ini_CacheLookupKey = "ini"; -const char *GameConstants::path_logs_CacheLookupKey = "logs"; + const char *GameConstants::pathCacheLookupKey = "pathCache_"; + const char *GameConstants::path_data_CacheLookupKey = "data"; + const char *GameConstants::path_ini_CacheLookupKey = "ini"; + const char *GameConstants::path_logs_CacheLookupKey = "logs"; -const char *GameConstants::saveNetworkGameFileServer = "zetaglest-saved-server.xml"; -const char *GameConstants::saveNetworkGameFileServerCompressed = "zetaglest-saved-server.zip"; + const char *GameConstants::saveNetworkGameFileServer = + "zetaglest-saved-server.xml"; + const char *GameConstants::saveNetworkGameFileServerCompressed = + "zetaglest-saved-server.zip"; -const char *GameConstants::saveNetworkGameFileClient = "zetaglest-saved-client.xml"; -const char *GameConstants::saveNetworkGameFileClientCompressed = "zetaglest-saved-client.zip"; + const char *GameConstants::saveNetworkGameFileClient = + "zetaglest-saved-client.xml"; + const char *GameConstants::saveNetworkGameFileClientCompressed = + "zetaglest-saved-client.zip"; -const char *GameConstants::saveGameFileDefault = "zetaglest-saved.xml"; -const char *GameConstants::saveGameFileAutoTestDefault = "zetaglest-auto-saved_%s.xml"; -const char *GameConstants::saveGameFilePattern = "zetaglest-saved_%s.xml"; + const char *GameConstants::saveGameFileDefault = "zetaglest-saved.xml"; + const char *GameConstants::saveGameFileAutoTestDefault = + "zetaglest-auto-saved_%s.xml"; + const char *GameConstants::saveGameFilePattern = "zetaglest-saved_%s.xml"; -const char *Config::glest_ini_filename = "glest.ini"; -const char *Config::glestuser_ini_filename = "glestuser.ini"; + const char *Config::glest_ini_filename = "glest.ini"; + const char *Config::glestuser_ini_filename = "glestuser.ini"; -const char *Config::glestkeys_ini_filename = "glestkeys.ini"; -const char *Config::glestuserkeys_ini_filename = "glestuserkeys.ini"; + const char *Config::glestkeys_ini_filename = "glestkeys.ini"; + const char *Config::glestuserkeys_ini_filename = "glestuserkeys.ini"; -const char *Config::ACTIVE_MOD_PROPERTY_NAME = "current_mod_name"; + const char *Config::ACTIVE_MOD_PROPERTY_NAME = "current_mod_name"; - const char *Config::colorPicking = "color"; - const char *Config::selectBufPicking = "selectbuf"; - const char *Config::frustumPicking = "frustum"; + const char *Config::colorPicking = "color"; + const char *Config::selectBufPicking = "selectbuf"; + const char *Config::frustumPicking = "frustum"; -map Config::customRuntimeProperties; + map < string, string > Config::customRuntimeProperties; // ===================================================== -// class Config +// class Config // ===================================================== -const string defaultNotFoundValue = "~~NOT FOUND~~"; + const string defaultNotFoundValue = "~~NOT FOUND~~"; -map Config::configList; + map < ConfigType, Config > Config::configList; -Config::Config() { - fileLoaded.first = false; - fileLoaded.second = false; - cfgType.first = cfgMainGame; - cfgType.second = cfgUserGame; - fileName.first = ""; - fileName.second = ""; - fileNameParameter.first = ""; - fileNameParameter.second = ""; - custom_path_parameter = ""; -} + Config::Config () + { + fileLoaded.first = false; + fileLoaded.second = false; + cfgType.first = cfgMainGame; + cfgType.second = cfgUserGame; + fileName.first = ""; + fileName.second = ""; + fileNameParameter.first = ""; + fileNameParameter.second = ""; + custom_path_parameter = ""; + } -bool Config::tryCustomPath(std::pair &type, std::pair &file, string custom_path) { - bool wasFound = false; - if((type.first == cfgMainGame && type.second == cfgUserGame && - file.first == glest_ini_filename && file.second == glestuser_ini_filename) || - (type.first == cfgMainKeys && type.second == cfgUserKeys && - file.first == glestkeys_ini_filename && file.second == glestuserkeys_ini_filename)) { + bool Config::tryCustomPath (std::pair < ConfigType, ConfigType > &type, + std::pair < string, string > &file, + string custom_path) + { + bool wasFound = false; + if ((type.first == cfgMainGame && type.second == cfgUserGame && + file.first == glest_ini_filename + && file.second == glestuser_ini_filename) + || (type.first == cfgMainKeys && type.second == cfgUserKeys + && file.first == glestkeys_ini_filename + && file.second == glestuserkeys_ini_filename)) + { - string linuxPath = custom_path; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("-=-=-=-=-=-=-= looking for file in possible location [%s]\n",linuxPath.c_str()); + string linuxPath = custom_path; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("-=-=-=-=-=-=-= looking for file in possible location [%s]\n", + linuxPath.c_str ()); #if defined(__linux__) - string nixFile = linuxPath + "linux_" + file.first; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("-=-=-=-=-=-=-= looking for linux specific file in possible location [%s]\n",nixFile.c_str()); + string nixFile = linuxPath + "linux_" + file.first; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("-=-=-=-=-=-=-= looking for linux specific file in possible location [%s]\n", + nixFile.c_str ()); - if(wasFound == false && fileExists(nixFile) == true) { - file.first = nixFile; - file.second = linuxPath + file.second; - wasFound = true; - } + if (wasFound == false && fileExists (nixFile) == true) + { + file.first = nixFile; + file.second = linuxPath + file.second; + wasFound = true; + } #elif defined(__WIN32__) - string winFile = linuxPath + "windows_" + file.first; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("-=-=-=-=-=-=-= looking for windows specific file in possible location [%s]\n",winFile.c_str()); + string winFile = linuxPath + "windows_" + file.first; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("-=-=-=-=-=-=-= looking for windows specific file in possible location [%s]\n", + winFile.c_str ()); - if(wasFound == false && fileExists(winFile) == true) { - file.first = winFile; - file.second = linuxPath + file.second; - wasFound = true; - } + if (wasFound == false && fileExists (winFile) == true) + { + file.first = winFile; + file.second = linuxPath + file.second; + wasFound = true; + } #endif - if(wasFound == false && fileExists(linuxPath + file.first) == true) { - file.first = linuxPath + file.first; - file.second = linuxPath + file.second; - wasFound = true; - } - } - return wasFound; -} - -Config::Config(std::pair type, std::pair file, std::pair fileMustExist,string custom_path) { - fileLoaded.first = false; - fileLoaded.second = false; - cfgType = type; - fileName = file; - fileNameParameter = file; - custom_path_parameter = custom_path; - - if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") { - fileName.first = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName.first; - fileName.second = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName.second; + if (wasFound == false && fileExists (linuxPath + file.first) == true) + { + file.first = linuxPath + file.first; + file.second = linuxPath + file.second; + wasFound = true; + } + } + return wasFound; } - bool foundPath = false; - string currentpath = custom_path; + Config::Config (std::pair < ConfigType, ConfigType > type, + std::pair < string, string > file, std::pair < bool, + bool > fileMustExist, string custom_path) + { + fileLoaded.first = false; + fileLoaded.second = false; + cfgType = type; + fileName = file; + fileNameParameter = file; + custom_path_parameter = custom_path; - if(custom_path != "") { - foundPath = tryCustomPath(cfgType, fileName, custom_path); - } + if (getGameReadWritePath (GameConstants::path_ini_CacheLookupKey) != "") + { + fileName.first = + getGameReadWritePath (GameConstants::path_ini_CacheLookupKey) + + fileName.first; + fileName.second = + getGameReadWritePath (GameConstants::path_ini_CacheLookupKey) + + fileName.second; + } - if(foundPath == false) { - currentpath = extractDirectoryPathFromFile(Properties::getApplicationPath()); - foundPath = tryCustomPath(cfgType, fileName, currentpath); - } + bool foundPath = false; + string currentpath = custom_path; + + if (custom_path != "") + { + foundPath = tryCustomPath (cfgType, fileName, custom_path); + } + + if (foundPath == false) + { + currentpath = + extractDirectoryPathFromFile (Properties::getApplicationPath ()); + foundPath = tryCustomPath (cfgType, fileName, currentpath); + } #if defined(CUSTOM_DATA_INSTALL_PATH) - if(foundPath == false) { - foundPath = tryCustomPath(cfgType, fileName, formatPath(TOSTRING(CUSTOM_DATA_INSTALL_PATH))); - } + if (foundPath == false) + { + foundPath = + tryCustomPath (cfgType, fileName, + formatPath (TOSTRING (CUSTOM_DATA_INSTALL_PATH))); + } #endif #if defined(MG_CMAKE_INSTALL_PREFIX) - if(foundPath == false) { - foundPath = tryCustomPath(cfgType, fileName, formatPath(TOSTRING(MG_CMAKE_INSTALL_PREFIX))); - } + if (foundPath == false) + { + foundPath = + tryCustomPath (cfgType, fileName, + formatPath (TOSTRING (MG_CMAKE_INSTALL_PREFIX))); + } #endif // Look in standard linux shared paths for ini files #if defined(__linux__) - if(foundPath == false) { - foundPath = tryCustomPath(cfgType, fileName, "/usr/share/zetaglest/"); - } - if(foundPath == false) { - foundPath = tryCustomPath(cfgType, fileName, "/usr/share/games/zetaglest/"); - } - if(foundPath == false) { - foundPath = tryCustomPath(cfgType, fileName, "/usr/local/share/zetaglest/"); - } - if(foundPath == false) { - foundPath = tryCustomPath(cfgType, fileName, "/usr/local/share/games/zetaglest/"); - } + if (foundPath == false) + { + foundPath = + tryCustomPath (cfgType, fileName, "/usr/share/zetaglest/"); + } + if (foundPath == false) + { + foundPath = + tryCustomPath (cfgType, fileName, "/usr/share/games/zetaglest/"); + } + if (foundPath == false) + { + foundPath = + tryCustomPath (cfgType, fileName, "/usr/local/share/zetaglest/"); + } + if (foundPath == false) + { + foundPath = + tryCustomPath (cfgType, fileName, + "/usr/local/share/games/zetaglest/"); + } #endif - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("foundPath = [%d]\n",foundPath); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("foundPath = [%d]\n", foundPath); - if(fileMustExist.first == true && fileExists(fileName.first) == false) { - //string currentpath = extractDirectoryPathFromFile(Properties::getApplicationPath()); - fileName.first = currentpath + fileName.first; - } + if (fileMustExist.first == true && fileExists (fileName.first) == false) + { + //string currentpath = extractDirectoryPathFromFile(Properties::getApplicationPath()); + fileName.first = currentpath + fileName.first; + } #if defined(WIN32) - //string test = "C:\\Code\\zetaglest\\mk\\windows\\.\\..\\..\\data\\glest_game\\glest.ini"; - //updatePathClimbingParts(test); + //string test = "C:\\Code\\zetaglest\\mk\\windows\\.\\..\\..\\data\\glest_game\\glest.ini"; + //updatePathClimbingParts(test); - updatePathClimbingParts(fileName.first); + updatePathClimbingParts (fileName.first); #endif - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("-=-=-=-=-=-=-= About to load fileName.first = [%s]\n",fileName.first.c_str()); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("-=-=-=-=-=-=-= About to load fileName.first = [%s]\n", + fileName.first.c_str ()); - if(fileMustExist.first == true || - (fileMustExist.first == false && fileExists(fileName.first) == true)) { - properties.first.load(fileName.first); - fileLoaded.first = true; - } + if (fileMustExist.first == true || + (fileMustExist.first == false + && fileExists (fileName.first) == true)) + { + properties.first.load (fileName.first); + fileLoaded.first = true; + } - if(cfgType.first == cfgMainGame) { - if( properties.first.getString("UserData_Root", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - string userData = properties.first.getString("UserData_Root"); - if(userData != "") { - endPathWithSlash(userData); - } - fileName.second = userData + fileNameParameter.second; + if (cfgType.first == cfgMainGame) + { + if (properties.first. + getString ("UserData_Root", + defaultNotFoundValue.c_str ()) != defaultNotFoundValue) + { + string userData = properties.first.getString ("UserData_Root"); + if (userData != "") + { + endPathWithSlash (userData); + } + fileName.second = userData + fileNameParameter.second; } - else if(properties.first.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - string userData = properties.first.getString("UserOverrideFile"); - if(userData != "") { - endPathWithSlash(userData); - } - fileName.second = userData + fileNameParameter.second; + else if (properties.first. + getString ("UserOverrideFile", + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + string userData = properties.first.getString ("UserOverrideFile"); + if (userData != "") + { + endPathWithSlash (userData); + } + fileName.second = userData + fileNameParameter.second; } #if defined(WIN32) - updatePathClimbingParts(fileName.second); + updatePathClimbingParts (fileName.second); #endif - } - else if(cfgType.first == cfgMainKeys) { - Config &mainCfg = Config::getInstance(); - if( mainCfg.getString("UserData_Root", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - string userData = mainCfg.getString("UserData_Root"); - if(userData != "") { - endPathWithSlash(userData); - } - fileName.second = userData + fileNameParameter.second; + } + else if (cfgType.first == cfgMainKeys) + { + Config & mainCfg = Config::getInstance (); + if (mainCfg. + getString ("UserData_Root", + defaultNotFoundValue.c_str ()) != defaultNotFoundValue) + { + string userData = mainCfg.getString ("UserData_Root"); + if (userData != "") + { + endPathWithSlash (userData); + } + fileName.second = userData + fileNameParameter.second; } - else if(mainCfg.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - string userData = mainCfg.getString("UserOverrideFile"); - if(userData != "") { - endPathWithSlash(userData); - } - fileName.second = userData + fileNameParameter.second; + else if (mainCfg. + getString ("UserOverrideFile", + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + string userData = mainCfg.getString ("UserOverrideFile"); + if (userData != "") + { + endPathWithSlash (userData); + } + fileName.second = userData + fileNameParameter.second; } #if defined(WIN32) - updatePathClimbingParts(fileName.second); + updatePathClimbingParts (fileName.second); #endif - } + } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("-=-=-=-=-=-=-= About to load fileName.second = [%s]\n",fileName.second.c_str()); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("-=-=-=-=-=-=-= About to load fileName.second = [%s]\n", + fileName.second.c_str ()); - if(fileMustExist.second == true || - (fileMustExist.second == false && fileExists(fileName.second) == true)) { - properties.second.load(fileName.second); - fileLoaded.second = true; - } + if (fileMustExist.second == true || + (fileMustExist.second == false + && fileExists (fileName.second) == true)) + { + properties.second.load (fileName.second); + fileLoaded.second = true; + } - try { - if(fileName.second != "" && fileExists(fileName.second) == false) { - if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] attempting to auto-create cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str()); + try + { + if (fileName.second != "" && fileExists (fileName.second) == false) + { + if (SystemFlags::VERBOSE_MODE_ENABLED) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] attempting to auto-create cfgFile.second = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + fileName.second.c_str ()); #if defined(WIN32) && !defined(__MINGW32__) - wstring wstr = utf8_decode(fileName.second); - FILE *fp = _wfopen(wstr.c_str(), L"w"); - std::ofstream userFile(fp); + wstring wstr = utf8_decode (fileName.second); + FILE *fp = _wfopen (wstr.c_str (), L"w"); + std::ofstream userFile (fp); #else - std::ofstream userFile; - userFile.open(fileName.second.c_str(), ios_base::out | ios_base::trunc); + std::ofstream userFile; + userFile.open (fileName.second.c_str (), + ios_base::out | ios_base::trunc); #endif - userFile.close(); + userFile.close (); #if defined(WIN32) && !defined(__MINGW32__) - if(fp) { - fclose(fp); - } + if (fp) + { + fclose (fp); + } #endif - fileLoaded.second = true; - properties.second.load(fileName.second); - } + fileLoaded.second = true; + properties.second.load (fileName.second); + } + } + catch (const exception & ex) + { + SystemFlags::OutputDebug (SystemFlags::debugError, + "In [%s::%s Line: %d] Error [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + ex.what ()); + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] ERROR trying to auto-create cfgFile.second = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + fileName.second.c_str ()); + } } - catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ERROR trying to auto-create cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str()); + + Config & Config::getInstance (std::pair < ConfigType, ConfigType > type, + std::pair < string, string > file, + std::pair < bool, bool > fileMustExist, + string custom_path) + { + if (configList.find (type.first) == configList.end ()) + { + if (SystemFlags::VERBOSE_MODE_ENABLED) + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); + + Config config (type, file, fileMustExist, custom_path); + + if (SystemFlags::VERBOSE_MODE_ENABLED) + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); + + configList.insert (map < ConfigType, + Config >::value_type (type.first, config)); + + if (SystemFlags::VERBOSE_MODE_ENABLED) + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); + } + + return configList.find (type.first)->second; } -} -Config &Config::getInstance(std::pair type, std::pair file, std::pair fileMustExist, string custom_path) { - if(configList.find(type.first) == configList.end()) { - if(SystemFlags::VERBOSE_MODE_ENABLED) if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + void Config::CopyAll (Config * src, Config * dest) + { - Config config(type, file, fileMustExist, custom_path); + dest->properties = src->properties; + dest->cfgType = src->cfgType; + dest->fileName = src->fileName; + dest->fileNameParameter = src->fileNameParameter; + dest->fileLoaded = src->fileLoaded; + } - if(SystemFlags::VERBOSE_MODE_ENABLED) if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + void Config::reload () + { + if (SystemFlags::VERBOSE_MODE_ENABLED) + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); - configList.insert(map::value_type(type.first,config)); + std::pair < ConfigType, ConfigType > type = + std::make_pair (cfgType.first, cfgType.second); + Config newconfig (type, + std::make_pair (fileNameParameter.first, + fileNameParameter.second), + std::make_pair (true, false), custom_path_parameter); - if(SystemFlags::VERBOSE_MODE_ENABLED) if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - } + if (SystemFlags::VERBOSE_MODE_ENABLED) + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); - return configList.find(type.first)->second; -} + Config & oldconfig = configList.find (type.first)->second; + CopyAll (&newconfig, &oldconfig); -void Config::CopyAll(Config *src, Config *dest) { + if (SystemFlags::VERBOSE_MODE_ENABLED) + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); + } - dest->properties = src->properties; - dest->cfgType = src->cfgType; - dest->fileName = src->fileName; - dest->fileNameParameter = src->fileNameParameter; - dest->fileLoaded = src->fileLoaded; -} + void Config::save (const string & path) + { + if (fileLoaded.second == true) + { + if (path != "") + { + fileName.second = path; + } + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("In [%s::%s Line: %d] save file [%s]\n", __FILE__, + __FUNCTION__, __LINE__, fileName.second.c_str ()); + properties.second.save (fileName.second); + return; + } -void Config::reload() { - if(SystemFlags::VERBOSE_MODE_ENABLED) if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if (path != "") + { + fileName.first = path; + } + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("In [%s::%s Line: %d] save file [%s]\n", __FILE__, + __FUNCTION__, __LINE__, fileName.first.c_str ()); + properties.first.save (fileName.first); + } - std::pair type = std::make_pair(cfgType.first,cfgType.second); - Config newconfig(type, std::make_pair(fileNameParameter.first,fileNameParameter.second), std::make_pair(true,false), custom_path_parameter); + int Config::getInt (const char *key, const char *defaultValueIfNotFound) const + { + if (tempProperties.getString (key, defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return tempProperties.getInt (key, defaultValueIfNotFound); + } + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return properties.second.getInt (key, defaultValueIfNotFound); + } + return properties.first.getInt (key, defaultValueIfNotFound); + } - if(SystemFlags::VERBOSE_MODE_ENABLED) if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + bool Config::getBool (const char *key, const char *defaultValueIfNotFound) const + { + if (tempProperties.getString (key, defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return tempProperties.getBool (key, defaultValueIfNotFound); + } - Config &oldconfig = configList.find(type.first)->second; - CopyAll(&newconfig, &oldconfig); + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return properties.second.getBool (key, defaultValueIfNotFound); + } - if(SystemFlags::VERBOSE_MODE_ENABLED) if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} + return properties.first.getBool (key, defaultValueIfNotFound); + } -void Config::save(const string &path){ - if(fileLoaded.second == true) { - if(path != "") { - fileName.second = path; - } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] save file [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str()); - properties.second.save(fileName.second); - return; - } + float Config::getFloat (const char *key, + const char *defaultValueIfNotFound) const + { + if (tempProperties.getString (key, defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return tempProperties.getFloat (key, defaultValueIfNotFound); + } - if(path != "") { - fileName.first = path; - } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] save file [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str()); - properties.first.save(fileName.first); -} + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return properties.second.getFloat (key, defaultValueIfNotFound); + } -int Config::getInt(const char *key,const char *defaultValueIfNotFound) const { - if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return tempProperties.getInt(key,defaultValueIfNotFound); - } - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return properties.second.getInt(key,defaultValueIfNotFound); - } - return properties.first.getInt(key,defaultValueIfNotFound); -} + return properties.first.getFloat (key, defaultValueIfNotFound); + } -bool Config::getBool(const char *key,const char *defaultValueIfNotFound) const { - if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return tempProperties.getBool(key,defaultValueIfNotFound); - } + const string Config::getString (const char *key, + const char *defaultValueIfNotFound) const + { + if (tempProperties.getString (key, defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return tempProperties.getString (key, defaultValueIfNotFound); + } - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return properties.second.getBool(key,defaultValueIfNotFound); - } + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return properties.second.getString (key, defaultValueIfNotFound); + } - return properties.first.getBool(key,defaultValueIfNotFound); -} + return properties.first.getString (key, defaultValueIfNotFound); + } -float Config::getFloat(const char *key,const char *defaultValueIfNotFound) const { - if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return tempProperties.getFloat(key,defaultValueIfNotFound); - } + int Config::getInt (const string & key, + const char *defaultValueIfNotFound) const + { + if (tempProperties.getString (key, defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return tempProperties.getInt (key, defaultValueIfNotFound); + } - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return properties.second.getFloat(key,defaultValueIfNotFound); - } + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return properties.second.getInt (key, defaultValueIfNotFound); + } - return properties.first.getFloat(key,defaultValueIfNotFound); -} + return properties.first.getInt (key, defaultValueIfNotFound); + } -const string Config::getString(const char *key,const char *defaultValueIfNotFound) const { - if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return tempProperties.getString(key,defaultValueIfNotFound); - } + bool Config::getBool (const string & key, + const char *defaultValueIfNotFound) const + { + if (tempProperties.getString (key, defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return tempProperties.getBool (key, defaultValueIfNotFound); + } - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return properties.second.getString(key,defaultValueIfNotFound); - } + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return properties.second.getBool (key, defaultValueIfNotFound); + } - return properties.first.getString(key,defaultValueIfNotFound); -} + return properties.first.getBool (key, defaultValueIfNotFound); + } -int Config::getInt(const string &key,const char *defaultValueIfNotFound) const{ - if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return tempProperties.getInt(key,defaultValueIfNotFound); - } + float Config::getFloat (const string & key, + const char *defaultValueIfNotFound) const + { + if (tempProperties.getString (key, defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return tempProperties.getFloat (key, defaultValueIfNotFound); + } - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return properties.second.getInt(key,defaultValueIfNotFound); - } + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return properties.second.getFloat (key, defaultValueIfNotFound); + } - return properties.first.getInt(key,defaultValueIfNotFound); -} + return properties.first.getFloat (key, defaultValueIfNotFound); + } -bool Config::getBool(const string &key,const char *defaultValueIfNotFound) const{ - if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return tempProperties.getBool(key,defaultValueIfNotFound); - } + const string Config::getString (const string & key, + const char *defaultValueIfNotFound) const + { + if (tempProperties.getString (key, defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return tempProperties.getString (key, defaultValueIfNotFound); + } - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return properties.second.getBool(key,defaultValueIfNotFound); - } + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { + return properties.second.getString (key, defaultValueIfNotFound); + } - return properties.first.getBool(key,defaultValueIfNotFound); -} + return properties.first.getString (key, defaultValueIfNotFound); + } -float Config::getFloat(const string &key,const char *defaultValueIfNotFound) const{ - if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return tempProperties.getFloat(key,defaultValueIfNotFound); - } + SDL_Keycode Config::translateStringToSDLKey (const string & value) const + { + SDL_Keycode result = SDLK_UNKNOWN; - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return properties.second.getFloat(key,defaultValueIfNotFound); - } + if (IsNumeric (value.c_str ()) == true) + { + result = (SDL_Keycode) strToInt (value); + } + else if (value.substr (0, 2) == "vk") + { + if (value == "vkLeft") + { + result = SDLK_LEFT; + } + else if (value == "vkRight") + { + result = SDLK_RIGHT; + } + else if (value == "vkUp") + { + result = SDLK_UP; + } + else if (value == "vkDown") + { + result = SDLK_DOWN; + } + else if (value == "vkAdd") + { + result = SDLK_PLUS; + } + else if (value == "vkSubtract") + { + result = SDLK_MINUS; + } + else if (value == "vkEscape") + { + result = SDLK_ESCAPE; + } + else if (value == "vkF1") + { + result = SDLK_F1; + } + else if (value == "vkF2") + { + result = SDLK_F2; + } + else if (value == "vkF3") + { + result = SDLK_F3; + } + else if (value == "vkF4") + { + result = SDLK_F4; + } + else if (value == "vkF5") + { + result = SDLK_F5; + } + else if (value == "vkF6") + { + result = SDLK_F6; + } + else if (value == "vkF7") + { + result = SDLK_F7; + } + else if (value == "vkF8") + { + result = SDLK_F8; + } + else if (value == "vkF9") + { + result = SDLK_F9; + } + else if (value == "vkF10") + { + result = SDLK_F10; + } + else if (value == "vkF11") + { + result = SDLK_F11; + } + else if (value == "vkF12") + { + result = SDLK_F12; + } + else if (value == "vkPrint") + { + result = SDLK_PRINTSCREEN; + } + else if (value == "vkPause") + { + result = SDLK_PAUSE; + } + else + { + string sError = "Unsupported key translation [" + value + "]"; + throw megaglest_runtime_error (sError.c_str ()); + } + } + else if (value.length () >= 1) + { + if (value.length () == 3 && value[0] == '\'' && value[2] == '\'') + { + result = (SDL_Keycode) value[1]; + } + else + { + bool foundKey = false; + if (value.length () > 1) + { + SDL_Keycode lookup = SDL_GetKeyFromName (value.c_str ()); + if (lookup != SDLK_UNKNOWN) + { + result = lookup; + foundKey = true; + } + } - return properties.first.getFloat(key,defaultValueIfNotFound); -} + if (foundKey == false) + { + result = (SDL_Keycode) value[0]; + } + } + } + else + { + string sError = "Unsupported key translation" + value; + throw megaglest_runtime_error (sError.c_str ()); + } -const string Config::getString(const string &key,const char *defaultValueIfNotFound) const{ - if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return tempProperties.getString(key,defaultValueIfNotFound); - } + // Because SDL is based on lower Ascii + //result = tolower(result); + return result; + } - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - return properties.second.getString(key,defaultValueIfNotFound); - } + SDL_Keycode Config::getSDLKey (const char *key) const + { + if (fileLoaded.second == true && + properties.second.getString (key, + defaultNotFoundValue.c_str ()) != + defaultNotFoundValue) + { - return properties.first.getString(key,defaultValueIfNotFound); -} - -SDL_Keycode Config::translateStringToSDLKey(const string &value) const { - SDL_Keycode result = SDLK_UNKNOWN; - - if(IsNumeric(value.c_str()) == true) { - result = (SDL_Keycode)strToInt(value); - } - else if(value.substr(0,2) == "vk") { - if(value == "vkLeft") { - result = SDLK_LEFT; - } - else if(value == "vkRight") { - result = SDLK_RIGHT; - } - else if(value == "vkUp") { - result = SDLK_UP; - } - else if(value == "vkDown") { - result = SDLK_DOWN; - } - else if(value == "vkAdd") { - result = SDLK_PLUS; - } - else if(value == "vkSubtract") { - result = SDLK_MINUS; - } - else if(value == "vkEscape") { - result = SDLK_ESCAPE; - } - else if(value == "vkF1") { - result = SDLK_F1; - } - else if(value == "vkF2") { - result = SDLK_F2; - } - else if(value == "vkF3") { - result = SDLK_F3; - } - else if(value == "vkF4") { - result = SDLK_F4; - } - else if(value == "vkF5") { - result = SDLK_F5; - } - else if(value == "vkF6") { - result = SDLK_F6; - } - else if(value == "vkF7") { - result = SDLK_F7; - } - else if(value == "vkF8") { - result = SDLK_F8; - } - else if(value == "vkF9") { - result = SDLK_F9; - } - else if(value == "vkF10") { - result = SDLK_F10; - } - else if(value == "vkF11") { - result = SDLK_F11; - } - else if(value == "vkF12") { - result = SDLK_F12; - } - else if(value == "vkPrint") { - result = SDLK_PRINTSCREEN; - } - else if(value == "vkPause") { - result = SDLK_PAUSE; - } - else { - string sError = "Unsupported key translation [" + value + "]"; - throw megaglest_runtime_error(sError.c_str()); - } - } - else if(value.length() >= 1) { - if(value.length() == 3 && value[0] == '\'' && value[2] == '\'') { - result = (SDL_Keycode)value[1]; - } - else { - bool foundKey = false; - if(value.length() > 1) { - SDL_Keycode lookup = SDL_GetKeyFromName(value.c_str()); - if(lookup != SDLK_UNKNOWN) { - result = lookup; - foundKey = true; - } - } - - if(foundKey == false) { - result = (SDL_Keycode)value[0]; - } - } - } - else { - string sError = "Unsupported key translation" + value; - throw megaglest_runtime_error(sError.c_str()); - } - - // Because SDL is based on lower Ascii - //result = tolower(result); - return result; -} - -SDL_Keycode Config::getSDLKey(const char *key) const { - if(fileLoaded.second == true && - properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - - string value = properties.second.getString(key); - return translateStringToSDLKey(value); - } - string value = properties.first.getString(key); - return translateStringToSDLKey(value); -} + string value = properties.second.getString (key); + return translateStringToSDLKey (value); + } + string value = properties.first.getString (key); + return translateStringToSDLKey (value); + } //char Config::getCharKey(const char *key) const { -// if(fileLoaded.second == true && -// properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { +// if(fileLoaded.second == true && +// properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { // -// string value = properties.second.getString(key); -// return translateStringToCharKey(value); -// } -// string value = properties.first.getString(key); -// return translateStringToCharKey(value); +// string value = properties.second.getString(key); +// return translateStringToCharKey(value); +// } +// string value = properties.first.getString(key); +// return translateStringToCharKey(value); //} -void Config::setInt(const string &key, int value, bool tempBuffer) { - if(tempBuffer == true) { - tempProperties.setInt(key, value); - return; - } - if(fileLoaded.second == true) { - properties.second.setInt(key, value); - return; - } - properties.first.setInt(key, value); -} + void Config::setInt (const string & key, int value, bool tempBuffer) + { + if (tempBuffer == true) + { + tempProperties.setInt (key, value); + return; + } + if (fileLoaded.second == true) + { + properties.second.setInt (key, value); + return; + } + properties.first.setInt (key, value); + } -void Config::setBool(const string &key, bool value, bool tempBuffer) { - if(tempBuffer == true) { - tempProperties.setBool(key, value); - return; - } + void Config::setBool (const string & key, bool value, bool tempBuffer) + { + if (tempBuffer == true) + { + tempProperties.setBool (key, value); + return; + } - if(fileLoaded.second == true) { - properties.second.setBool(key, value); - return; - } + if (fileLoaded.second == true) + { + properties.second.setBool (key, value); + return; + } - properties.first.setBool(key, value); -} + properties.first.setBool (key, value); + } -void Config::setFloat(const string &key, float value, bool tempBuffer) { - if(tempBuffer == true) { - tempProperties.setFloat(key, value); - return; - } + void Config::setFloat (const string & key, float value, bool tempBuffer) + { + if (tempBuffer == true) + { + tempProperties.setFloat (key, value); + return; + } - if(fileLoaded.second == true) { - properties.second.setFloat(key, value); - return; - } + if (fileLoaded.second == true) + { + properties.second.setFloat (key, value); + return; + } - properties.first.setFloat(key, value); -} + properties.first.setFloat (key, value); + } -void Config::setString(const string &key, const string &value, bool tempBuffer) { - if(tempBuffer == true) { - tempProperties.setString(key, value); - return; - } + void Config::setString (const string & key, const string & value, + bool tempBuffer) + { + if (tempBuffer == true) + { + tempProperties.setString (key, value); + return; + } - if(fileLoaded.second == true) { - properties.second.setString(key, value); - return; - } + if (fileLoaded.second == true) + { + properties.second.setString (key, value); + return; + } - properties.first.setString(key, value); -} + properties.first.setString (key, value); + } -vector > Config::getPropertiesFromContainer(const Properties &propertiesObj) const { - vector > result; + vector < pair < string, + string > + >Config:: + getPropertiesFromContainer (const Properties & propertiesObj) const + { + vector < pair < string, string > >result; - int count = propertiesObj.getPropertyCount(); - for(int i = 0; i < count; ++i) { - pair property; - property.first = propertiesObj.getKey(i); - property.second = propertiesObj.getString(i); - result.push_back(property); - } + int count = propertiesObj.getPropertyCount (); + for (int i = 0; i < count; ++i) + { + pair < string, string > property; + property.first = propertiesObj.getKey (i); + property.second = propertiesObj.getString (i); + result.push_back (property); + } - return result; -} + return result; + } -vector > Config::getMergedProperties() const { - vector > result = getMasterProperties(); - vector > resultUser = getUserProperties(); - for(unsigned int i = 0; i < resultUser.size(); ++i) { - const pair &propertyUser = resultUser[i]; + vector < pair < string, string > >Config::getMergedProperties ()const + { + vector < pair < string, string > >result = getMasterProperties (); + vector < pair < string, string > >resultUser = getUserProperties (); + for (unsigned int i = 0; i < resultUser.size (); ++i) + { + const pair < string, string > &propertyUser = resultUser[i]; bool overrideProperty = false; - for(unsigned int j = 0; j < result.size(); ++j) { - pair &property = result[j]; - // Take the user property and override the original value - if(property.first == propertyUser.first) { - overrideProperty = true; - property.second = propertyUser.second; - break; - } + for (unsigned int j = 0; j < result.size (); ++j) + { + pair < string, string > &property = result[j]; + // Take the user property and override the original value + if (property.first == propertyUser.first) + { + overrideProperty = true; + property.second = propertyUser.second; + break; + } } - if(overrideProperty == false) { - result.push_back(propertyUser); + if (overrideProperty == false) + { + result.push_back (propertyUser); } + } + + return result; } - return result; -} - -vector > Config::getMasterProperties() const { - return getPropertiesFromContainer(properties.first); -} - -vector > Config::getUserProperties() const { - return getPropertiesFromContainer(properties.second); -} - -void Config::setUserProperties(const vector > &valueList) { - Properties &propertiesObj = properties.second; - - for(unsigned int idx = 0; idx < valueList.size(); ++ idx) { - const pair &nameValuePair = valueList[idx]; - propertiesObj.setString(nameValuePair.first,nameValuePair.second); - } -} - -string Config::getFileName(bool userFilename) const { - string result = fileName.second; - if(userFilename == false) { - result = fileName.first; + vector < pair < string, string > >Config::getMasterProperties ()const + { + return getPropertiesFromContainer (properties.first); } - return result; -} + vector < pair < string, string > >Config::getUserProperties () const + { + return getPropertiesFromContainer (properties.second); + } -string Config::toString(){ - return properties.first.toString(); -} + void Config::setUserProperties (const vector < pair < string, + string > >&valueList) + { + Properties & propertiesObj = properties.second; -vector Config::getPathListForType(PathType type, string scenarioDir) { - vector pathList; - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + for (unsigned int idx = 0; idx < valueList.size (); ++idx) + { + const pair < string, string > &nameValuePair = valueList[idx]; + propertiesObj.setString (nameValuePair.first, nameValuePair.second); + } + } - string userData = getString("UserData_Root",""); - if(userData != "") { - endPathWithSlash(userData); + string Config::getFileName (bool userFilename) const + { + string result = fileName.second; + if (userFilename == false) + { + result = fileName.first; + } + + return result; + } + + string Config::toString () + { + return properties.first.toString (); + } + + vector < string > Config::getPathListForType (PathType type, + string scenarioDir) + { + vector < string > pathList; + string data_path = + getGameReadWritePath (GameConstants::path_data_CacheLookupKey); + + string userData = getString ("UserData_Root", ""); + if (userData != "") + { + endPathWithSlash (userData); //if(data_path == "") { - // userData = userData; + // userData = userData; //} //else { - // if(SystemFlags::VERBOSE_MODE_ENABLED) printf("extractLastDirectoryFromPath(userData) [%s] from userData [%s]\n",extractLastDirectoryFromPath(userData).c_str(),userData.c_str()); - // userData = data_path + extractLastDirectoryFromPath(userData); + // if(SystemFlags::VERBOSE_MODE_ENABLED) printf("extractLastDirectoryFromPath(userData) [%s] from userData [%s]\n",extractLastDirectoryFromPath(userData).c_str(),userData.c_str()); + // userData = data_path + extractLastDirectoryFromPath(userData); //} //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] userData path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userData.c_str()); - if(isdir(userData.c_str()) == false) { - createDirectoryPaths(userData); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userData.c_str()); + if (isdir (userData.c_str ()) == false) + { + createDirectoryPaths (userData); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("In [%s::%s Line: %d] creating path [%s]\n", __FILE__, + __FUNCTION__, __LINE__, userData.c_str ()); } string userDataMaps = userData + GameConstants::folder_path_maps; - if(isdir(userDataMaps.c_str()) == false) { - createDirectoryPaths(userDataMaps); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataMaps.c_str()); + if (isdir (userDataMaps.c_str ()) == false) + { + createDirectoryPaths (userDataMaps); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("In [%s::%s Line: %d] creating path [%s]\n", __FILE__, + __FUNCTION__, __LINE__, userDataMaps.c_str ()); } - string userDataScenarios = userData + GameConstants::folder_path_scenarios; - if(isdir(userDataScenarios.c_str()) == false) { - createDirectoryPaths(userDataScenarios); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataScenarios.c_str()); + string userDataScenarios = + userData + GameConstants::folder_path_scenarios; + if (isdir (userDataScenarios.c_str ()) == false) + { + createDirectoryPaths (userDataScenarios); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("In [%s::%s Line: %d] creating path [%s]\n", __FILE__, + __FUNCTION__, __LINE__, userDataScenarios.c_str ()); } string userDataTechs = userData + GameConstants::folder_path_techs; - if(isdir(userDataTechs.c_str()) == false) { - createDirectoryPaths(userDataTechs); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataTechs.c_str()); + if (isdir (userDataTechs.c_str ()) == false) + { + createDirectoryPaths (userDataTechs); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("In [%s::%s Line: %d] creating path [%s]\n", __FILE__, + __FUNCTION__, __LINE__, userDataTechs.c_str ()); } - string userDataTilesets = userData + GameConstants::folder_path_tilesets; - if(isdir(userDataTilesets.c_str()) == false) { - createDirectoryPaths(userDataTilesets); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataTilesets.c_str()); + string userDataTilesets = + userData + GameConstants::folder_path_tilesets; + if (isdir (userDataTilesets.c_str ()) == false) + { + createDirectoryPaths (userDataTilesets); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("In [%s::%s Line: %d] creating path [%s]\n", __FILE__, + __FUNCTION__, __LINE__, userDataTilesets.c_str ()); } - string userDataTutorials = userData + GameConstants::folder_path_tutorials; - if(isdir(userDataTutorials.c_str()) == false) { - createDirectoryPaths(userDataTutorials); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataTutorials.c_str()); + string userDataTutorials = + userData + GameConstants::folder_path_tutorials; + if (isdir (userDataTutorials.c_str ()) == false) + { + createDirectoryPaths (userDataTutorials); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("In [%s::%s Line: %d] creating path [%s]\n", __FILE__, + __FUNCTION__, __LINE__, userDataTutorials.c_str ()); + } + } + if (scenarioDir != "") + { + if (EndsWith (scenarioDir, ".xml") == true) + { + scenarioDir = extractDirectoryPathFromFile (scenarioDir); } - } - if(scenarioDir != "") { - if(EndsWith(scenarioDir, ".xml") == true) { - scenarioDir = extractDirectoryPathFromFile(scenarioDir); - } - //string scenarioLocation = data_path + scenarioDir; - string scenarioLocation = scenarioDir; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Scenario path [%s]\n",scenarioLocation.c_str()); - pathList.push_back(scenarioLocation); + //string scenarioLocation = data_path + scenarioDir; + string scenarioLocation = scenarioDir; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Scenario path [%s]\n", scenarioLocation.c_str ()); + pathList.push_back (scenarioLocation); + } + + switch (type) + { + case ptMaps: + pathList.push_back (data_path + GameConstants::folder_path_maps); + if (userData != "") + { + pathList.push_back (userData + + string (GameConstants::folder_path_maps)); + } + break; + case ptScenarios: + pathList.push_back (data_path + GameConstants::folder_path_scenarios); + if (userData != "") + { + pathList.push_back (userData + + string (GameConstants::folder_path_scenarios)); + } + break; + case ptTechs: + pathList.push_back (data_path + GameConstants::folder_path_techs); + if (userData != "") + { + pathList.push_back (userData + + string (GameConstants::folder_path_techs)); + } + break; + case ptTilesets: + pathList.push_back (data_path + GameConstants::folder_path_tilesets); + if (userData != "") + { + pathList.push_back (userData + + string (GameConstants::folder_path_tilesets)); + } + break; + case ptTutorials: + pathList.push_back (data_path + GameConstants::folder_path_tutorials); + if (userData != "") + { + pathList.push_back (userData + + string (GameConstants::folder_path_tutorials)); + } + break; + } + + return pathList; } - switch(type) { - case ptMaps: - pathList.push_back(data_path+GameConstants::folder_path_maps); - if(userData != "") { - pathList.push_back(userData + string(GameConstants::folder_path_maps)); - } - break; - case ptScenarios: - pathList.push_back(data_path+GameConstants::folder_path_scenarios); - if(userData != "") { - pathList.push_back(userData + string(GameConstants::folder_path_scenarios)); - } - break; - case ptTechs: - pathList.push_back(data_path+GameConstants::folder_path_techs); - if(userData != "") { - pathList.push_back(userData + string(GameConstants::folder_path_techs)); - } - break; - case ptTilesets: - pathList.push_back(data_path+GameConstants::folder_path_tilesets); - if(userData != "") { - pathList.push_back(userData + string(GameConstants::folder_path_tilesets)); - } - break; - case ptTutorials: - pathList.push_back(data_path+GameConstants::folder_path_tutorials); - if(userData != "") { - pathList.push_back(userData + string(GameConstants::folder_path_tutorials)); - } - break; + bool Config::replaceFileWithLocalFile (const vector < string > &dirList, + string fileNamePart, + string & resultToReplace) + { + bool found = false; + for (unsigned int i = 0; i < dirList.size (); ++i) + { + string path = dirList[i]; + endPathWithSlash (path); + string newFileName = path + fileNamePart; + if (fileExists (newFileName) == true) + { + resultToReplace = newFileName; + found = true; + break; + } + } + return found; } - return pathList; -} - -bool Config::replaceFileWithLocalFile(const vector &dirList, string fileNamePart, string &resultToReplace) { - bool found = false; - for(unsigned int i = 0; i < dirList.size(); ++i) { - string path = dirList[i]; - endPathWithSlash(path); - string newFileName = path + fileNamePart; - if(fileExists(newFileName) == true) { - resultToReplace = newFileName; - found = true; - break; - } - } - return found; -} + string Config::findValidLocalFileFromPath (string fileName) + { + string result = fileName; -string Config::findValidLocalFileFromPath(string fileName) { - string result = fileName; + if (fileName.find ("maps/") != fileName.npos) + { + size_t pos = fileName.find ("maps/"); + string fileNamePart = fileName.substr (pos + 5); + Config & config = Config::getInstance (); + vector < string > dirList = config.getPathListForType (ptMaps); + replaceFileWithLocalFile (dirList, fileNamePart, result); - if(fileName.find("maps/") != fileName.npos ) { - size_t pos = fileName.find("maps/"); - string fileNamePart = fileName.substr(pos+5); - Config &config = Config::getInstance(); - vector dirList = config.getPathListForType(ptMaps); - replaceFileWithLocalFile(dirList, fileNamePart, result); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Found file [%s] @ " MG_SIZE_T_SPECIFIER + " [%s]\nNew File [%s]\n", fileName.c_str (), pos, + fileNamePart.c_str (), result.c_str ()); + } + else if (fileName.find ("tilesets/") != fileName.npos) + { + size_t pos = fileName.find ("tilesets/"); + string fileNamePart = fileName.substr (pos + 9); + Config & config = Config::getInstance (); + vector < string > dirList = config.getPathListForType (ptTilesets); + replaceFileWithLocalFile (dirList, fileNamePart, result); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found file [%s] @ " MG_SIZE_T_SPECIFIER " [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str()); - } - else if(fileName.find("tilesets/") != fileName.npos ) { - size_t pos = fileName.find("tilesets/"); - string fileNamePart = fileName.substr(pos+9); - Config &config = Config::getInstance(); - vector dirList = config.getPathListForType(ptTilesets); - replaceFileWithLocalFile(dirList, fileNamePart, result); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Found file [%s] @ " MG_SIZE_T_SPECIFIER + " [%s]\nNew File [%s]\n", fileName.c_str (), pos, + fileNamePart.c_str (), result.c_str ()); + } + else if (fileName.find ("techs/") != fileName.npos) + { + size_t pos = fileName.find ("techs/"); + string fileNamePart = fileName.substr (pos + 6); + Config & config = Config::getInstance (); + vector < string > dirList = config.getPathListForType (ptTechs); + replaceFileWithLocalFile (dirList, fileNamePart, result); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found file [%s] @ " MG_SIZE_T_SPECIFIER " [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str()); - } - else if(fileName.find("techs/") != fileName.npos ) { - size_t pos = fileName.find("techs/"); - string fileNamePart = fileName.substr(pos+6); - Config &config = Config::getInstance(); - vector dirList = config.getPathListForType(ptTechs); - replaceFileWithLocalFile(dirList, fileNamePart, result); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Found file [%s] @ " MG_SIZE_T_SPECIFIER + " [%s]\nNew File [%s]\n", fileName.c_str (), pos, + fileNamePart.c_str (), result.c_str ()); + } + else if (fileName.find ("scenarios/") != fileName.npos) + { + size_t pos = fileName.find ("scenarios/"); + string fileNamePart = fileName.substr (pos + 10); + Config & config = Config::getInstance (); + vector < string > dirList = config.getPathListForType (ptScenarios); + replaceFileWithLocalFile (dirList, fileNamePart, result); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found file [%s] @ " MG_SIZE_T_SPECIFIER " [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str()); - } - else if(fileName.find("scenarios/") != fileName.npos) { - size_t pos = fileName.find("scenarios/"); - string fileNamePart = fileName.substr(pos+10); - Config &config = Config::getInstance(); - vector dirList = config.getPathListForType(ptScenarios); - replaceFileWithLocalFile(dirList, fileNamePart, result); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Found file [%s] @ " MG_SIZE_T_SPECIFIER + " [%s]\nNew File [%s]\n", fileName.c_str (), pos, + fileNamePart.c_str (), result.c_str ()); + } + else if (fileName.find ("tutorials/") != fileName.npos) + { + size_t pos = fileName.find ("tutorials/"); + string fileNamePart = fileName.substr (pos + 10); + Config & config = Config::getInstance (); + vector < string > dirList = config.getPathListForType (ptTutorials); + replaceFileWithLocalFile (dirList, fileNamePart, result); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found file [%s] @ " MG_SIZE_T_SPECIFIER " [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str()); - } - else if(fileName.find("tutorials/") != fileName.npos) { - size_t pos = fileName.find("tutorials/"); - string fileNamePart = fileName.substr(pos+10); - Config &config = Config::getInstance(); - vector dirList = config.getPathListForType(ptTutorials); - replaceFileWithLocalFile(dirList, fileNamePart, result); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Found file [%s] @ " MG_SIZE_T_SPECIFIER + " [%s]\nNew File [%s]\n", fileName.c_str (), pos, + fileNamePart.c_str (), result.c_str ()); + } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found file [%s] @ " MG_SIZE_T_SPECIFIER " [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str()); - } - - return result; -} + return result; + } // static -string Config::getMapPath(const string &mapName, string scenarioDir, bool errorOnNotFound) { + string Config::getMapPath (const string & mapName, string scenarioDir, + bool errorOnNotFound) + { - Config &config = Config::getInstance(); - vector pathList = config.getPathListForType(ptMaps,scenarioDir); + Config & config = Config::getInstance (); + vector < string > pathList = + config.getPathListForType (ptMaps, scenarioDir); - for(int idx = 0; idx < (int)pathList.size(); idx++) { + for (int idx = 0; idx < (int) pathList.size (); idx++) + { string map_path = pathList[idx]; - endPathWithSlash(map_path); + endPathWithSlash (map_path); const string mega = map_path + mapName + ".mgm"; const string glest = map_path + mapName + ".gbm"; - if (fileExists(mega)) { - return mega; + if (fileExists (mega)) + { + return mega; } - else if (fileExists(glest)) { - return glest; + else if (fileExists (glest)) + { + return glest; } + } + + if (errorOnNotFound == true) + { + //abort(); + throw megaglest_runtime_error ("Map not found [" + mapName + + "]\nScenario [" + scenarioDir + "]"); + } + + return ""; } - if(errorOnNotFound == true) { - //abort(); - throw megaglest_runtime_error("Map not found [" + mapName + "]\nScenario [" + scenarioDir + "]"); - } - - return ""; -} - -}}// end namespace + } +} // end namespace diff --git a/source/glest_game/global/config.h b/source/glest_game/global/config.h index bbeeeb5ee..752d0ec44 100644 --- a/source/glest_game/global/config.h +++ b/source/glest_game/global/config.h @@ -21,122 +21,161 @@ // along with this program. If not, see #ifndef _GLEST_GAME_CONFIG_H_ -#define _GLEST_GAME_CONFIG_H_ +# define _GLEST_GAME_CONFIG_H_ -#ifdef WIN32 - #include - #include -#endif +# ifdef WIN32 +# include +# include +# endif -#include "properties.h" -#include -#include "game_constants.h" -#include -#include "leak_dumper.h" +# include "properties.h" +# include +# include "game_constants.h" +# include +# include "leak_dumper.h" -namespace Glest{ namespace Game{ +namespace Glest +{ + namespace Game + { -using Shared::Util::Properties; + using Shared::Util::Properties; // ===================================================== -// class Config +// class Config // -// Game configuration +// Game configuration // ===================================================== -enum ConfigType { - cfgMainGame, - cfgUserGame, - cfgTempGame, - cfgMainKeys, - cfgUserKeys, - cfgTempKeys -}; + enum ConfigType + { + cfgMainGame, + cfgUserGame, + cfgTempGame, + cfgMainKeys, + cfgUserKeys, + cfgTempKeys + }; -class Config { -private: + class Config + { + private: - std::pair properties; - Properties tempProperties; - std::pair cfgType; - std::pair fileNameParameter; - std::pair fileName; - std::pair fileLoaded; - string custom_path_parameter; + std::pair < Properties, Properties > properties; + Properties tempProperties; + std::pair < ConfigType, ConfigType > cfgType; + std::pair < string, string > fileNameParameter; + std::pair < string, string > fileName; + std::pair < bool, bool > fileLoaded; + string custom_path_parameter; - static map configList; + static map < ConfigType, Config > configList; - static const char *glest_ini_filename; - static const char *glestuser_ini_filename; + static const char *glest_ini_filename; + static const char *glestuser_ini_filename; - static map customRuntimeProperties; + static map < string, string > customRuntimeProperties; -public: + public: - static const char *glestkeys_ini_filename; - static const char *glestuserkeys_ini_filename; + static const char *glestkeys_ini_filename; + static const char *glestuserkeys_ini_filename; - static const char *ACTIVE_MOD_PROPERTY_NAME; + static const char *ACTIVE_MOD_PROPERTY_NAME; - static const char *colorPicking; - static const char *selectBufPicking; - static const char *frustumPicking; + static const char *colorPicking; + static const char *selectBufPicking; + static const char *frustumPicking; -protected: + protected: - Config(); - Config(std::pair type, std::pair file, std::pair fileMustExist,string custom_path=""); - bool tryCustomPath(std::pair &type, std::pair &file, string custom_path); - static void CopyAll(Config *src,Config *dest); - vector > getPropertiesFromContainer(const Properties &propertiesObj) const; - static bool replaceFileWithLocalFile(const vector &dirList, string fileNamePart, string &resultToReplace); + Config (); + Config (std::pair < ConfigType, ConfigType > type, std::pair < string, + string > file, std::pair < bool, bool > fileMustExist, + string custom_path = ""); + bool tryCustomPath (std::pair < ConfigType, ConfigType > &type, + std::pair < string, string > &file, + string custom_path); + static void CopyAll (Config * src, Config * dest); + vector < pair < string, + string > + >getPropertiesFromContainer (const Properties & propertiesObj) const; + static bool replaceFileWithLocalFile (const vector < string > &dirList, + string fileNamePart, + string & resultToReplace); -public: + public: - static Config &getInstance(std::pair type = std::make_pair(cfgMainGame,cfgUserGame) , - std::pair file = std::make_pair(glest_ini_filename,glestuser_ini_filename) , - std::pair fileMustExist = std::make_pair(true,false),string custom_path="" ); - void save(const string &path=""); - void reload(); + static Config & getInstance (std::pair < ConfigType, ConfigType > type = + std::make_pair (cfgMainGame, cfgUserGame), + std::pair < string, string > file = + std::make_pair (glest_ini_filename, + glestuser_ini_filename), + std::pair < bool, bool > fileMustExist = + std::make_pair (true, false), + string custom_path = ""); + void save (const string & path = ""); + void reload (); - int getInt(const string &key,const char *defaultValueIfNotFound=NULL) const; - bool getBool(const string &key,const char *defaultValueIfNotFound=NULL) const; - float getFloat(const string &key,const char *defaultValueIfNotFound=NULL) const; - const string getString(const string &key,const char *defaultValueIfNotFound=NULL) const; + int getInt (const string & key, const char *defaultValueIfNotFound = + NULL) const; + bool getBool (const string & key, const char *defaultValueIfNotFound = + NULL) const; + float getFloat (const string & key, const char *defaultValueIfNotFound = + NULL) const; + const string getString (const string & key, + const char *defaultValueIfNotFound = + NULL) const; - int getInt(const char *key,const char *defaultValueIfNotFound=NULL) const; - bool getBool(const char *key,const char *defaultValueIfNotFound=NULL) const; - float getFloat(const char *key,const char *defaultValueIfNotFound=NULL) const; - const string getString(const char *key,const char *defaultValueIfNotFound=NULL) const; - //char getCharKey(const char *key) const; - SDL_Keycode getSDLKey(const char *key) const; + int getInt (const char *key, const char *defaultValueIfNotFound = + NULL) const; + bool getBool (const char *key, const char *defaultValueIfNotFound = + NULL) const; + float getFloat (const char *key, const char *defaultValueIfNotFound = + NULL) const; + const string getString (const char *key, + const char *defaultValueIfNotFound = + NULL) const; + //char getCharKey(const char *key) const; + SDL_Keycode getSDLKey (const char *key) const; - void setInt(const string &key, int value, bool tempBuffer=false); - void setBool(const string &key, bool value, bool tempBuffer=false); - void setFloat(const string &key, float value, bool tempBuffer=false); - void setString(const string &key, const string &value, bool tempBuffer=false); + void setInt (const string & key, int value, bool tempBuffer = false); + void setBool (const string & key, bool value, bool tempBuffer = false); + void setFloat (const string & key, float value, bool tempBuffer = + false); + void setString (const string & key, const string & value, + bool tempBuffer = false); - vector getPathListForType(PathType type, string scenarioDir = ""); + vector < string > getPathListForType (PathType type, + string scenarioDir = ""); - vector > getMergedProperties() const; - vector > getMasterProperties() const; - vector > getUserProperties() const; - void setUserProperties(const vector > &valueList); + vector < pair < string, string > >getMergedProperties () const; + vector < pair < string, string > >getMasterProperties () const; + vector < pair < string, string > >getUserProperties () const; + void setUserProperties (const vector < pair < string, + string > >&valueList); - string getFileName(bool userFilename) const; + string getFileName (bool userFilename) const; - SDL_Keycode translateStringToSDLKey(const string &value) const; + SDL_Keycode translateStringToSDLKey (const string & value) const; - string toString(); + string toString (); - static string getCustomRuntimeProperty(string key) { return customRuntimeProperties[key]; } - static void setCustomRuntimeProperty(string key, string value) { customRuntimeProperties[key] = value; } + static string getCustomRuntimeProperty (string key) + { + return customRuntimeProperties[key]; + } + static void setCustomRuntimeProperty (string key, string value) + { + customRuntimeProperties[key] = value; + } - static string findValidLocalFileFromPath(string fileName); + static string findValidLocalFileFromPath (string fileName); - static string getMapPath(const string &mapName, string scenarioDir="", bool errorOnNotFound=true); -}; + static string getMapPath (const string & mapName, string scenarioDir = + "", bool errorOnNotFound = true); + }; -}}//end namespace +}} //end namespace #endif diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 9e696585a..6a050f8a8 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -38,1515 +38,2054 @@ using namespace Shared::Sound; using namespace Shared::Graphics; using namespace Shared::Util; -namespace Glest{ namespace Game{ +namespace Glest +{ + namespace Game + { // ===================================================== -// class CoreData +// class CoreData // ===================================================== -static string tempDataLocation = getUserHome(); + static string tempDataLocation = getUserHome (); // ===================== PUBLIC ======================== -static const string CORE_PATH = "data/core/"; -static const string CORE_MISC_TEXTURES_PATH = CORE_PATH + "misc_textures/"; - -static const string CORE_MENU_PATH = CORE_PATH + "menu/"; -static const string CORE_MENU_TEXTURES_PATH = CORE_MENU_PATH + "textures/"; -static const string CORE_MENU_SOUND_PATH = CORE_MENU_PATH + "sound/"; -static const string CORE_MENU_MUSIC_PATH = CORE_MENU_PATH + "music/"; -static const string CORE_MENU_VIDEOS_PATH = CORE_MENU_PATH + "videos/"; - -static const string CORE_WATER_SOUNDS_PATH = CORE_PATH + "/water_sounds/"; - -CoreData &CoreData::getInstance() { - static CoreData coreData; - return coreData; -} - -CoreData::CoreData() { - logoTexture=NULL; - logoTextureList.clear(); - backgroundTexture=NULL; - fireTexture=NULL; - teamColorTexture=NULL; - snowTexture=NULL; - waterSplashTexture=NULL; - customTexture=NULL; - buttonSmallTexture=NULL; - buttonBigTexture=NULL; - horizontalLineTexture=NULL; - verticalLineTexture=NULL; - checkBoxTexture=NULL; - checkedCheckBoxTexture=NULL; - gameWinnerTexture=NULL; - notOnServerTexture=NULL; - onServerDifferentTexture=NULL; - onServerTexture=NULL; - onServerInstalledTexture=NULL; - statusReadyTexture=NULL; - statusNotReadyTexture=NULL; - statusBRBTexture=NULL; - - healthbarTexture=NULL; - healthbarBackgroundTexture=NULL; - - miscTextureList.clear(); - - displayFont=NULL; - menuFontNormal=NULL; - displayFontSmall=NULL; - menuFontBig=NULL; - menuFontVeryBig=NULL; - consoleFont=NULL; - - displayFont3D=NULL; - menuFontNormal3D=NULL; - displayFontSmall3D=NULL; - menuFontBig3D=NULL; - menuFontVeryBig3D=NULL; - consoleFont3D=NULL; - - introVideoFilename=""; - mainMenuVideoFilename=""; - - battleEndWinVideoFilename=""; - battleEndWinVideoFilenameFallback=""; - battleEndWinMusicFilename=""; - battleEndLoseVideoFilename=""; - battleEndLoseVideoFilenameFallback=""; - battleEndLoseMusicFilename=""; -} - -CoreData::~CoreData() { - cleanup(); -} - -void CoreData::cleanup() { - deleteValues(waterSounds.getSoundsPtr()->begin(), waterSounds.getSoundsPtr()->end()); - waterSounds.getSoundsPtr()->clear(); -} - -Texture2D *CoreData::getTextureBySystemId(TextureSystemType type) { - Texture2D *result = NULL; - switch(type) { - case tsyst_logoTexture: - result = getLogoTexture(); - break; - //std::vector logoTextureList; - case tsyst_backgroundTexture: - result = getBackgroundTexture(); - break; - case tsyst_fireTexture: - result = getFireTexture(); - break; - case tsyst_teamColorTexture: - result = getTeamColorTexture(); - break; - case tsyst_snowTexture: - result = getSnowTexture(); - break; - case tsyst_waterSplashTexture: - result = getWaterSplashTexture(); - break; - case tsyst_customTexture: - result = getCustomTexture(); - break; - case tsyst_buttonSmallTexture: - result = buttonSmallTexture; - break; - case tsyst_buttonBigTexture: - result = buttonBigTexture; - break; - case tsyst_horizontalLineTexture: - result = horizontalLineTexture; - break; - case tsyst_verticalLineTexture: - result = verticalLineTexture; - break; - case tsyst_checkBoxTexture: - result = checkBoxTexture; - break; - case tsyst_checkedCheckBoxTexture: - result = checkedCheckBoxTexture; - break; - case tsyst_gameWinnerTexture: - result = gameWinnerTexture; - break; - case tsyst_notOnServerTexture: - result = notOnServerTexture; - break; - case tsyst_onServerDifferentTexture: - result = onServerDifferentTexture; - break; - case tsyst_onServerTexture: - result = onServerTexture; - break; - case tsyst_onServerInstalledTexture: - result = onServerInstalledTexture; - break; - case tsyst_statusReadyTexture: - result = statusReadyTexture; - break; - case tsyst_statusNotReadyTexture: - result = statusNotReadyTexture; - break; - case tsyst_statusBRBTexture: - result = statusBRBTexture; - break; - case tsyst_healthbarTexture: - result = healthbarTexture; - break; - case tsyst_healthbarBackgroundTexture: - result = healthbarBackgroundTexture; - break; - - //std::vector miscTextureList; - } - return result; -} - -void CoreData::cleanupTexture(Texture2D **texture) { - Renderer &renderer= Renderer::getInstance(); - renderer.endTexture(rsGlobal, *texture); - *texture=NULL; -} - -void CoreData::loadTextureIfRequired(Texture2D **tex,string data_path, - string uniqueFilePath, int texSystemId, - bool setMipMap, bool setAlpha, - bool loadUniqueFilePath, bool compressionDisabled) { - if(*tex == NULL) { - bool attemptToLoadTexture = (texSystemId == tsyst_NONE); - if(attemptToLoadTexture == false && - itemLoadAttempted.find(texSystemId) == itemLoadAttempted.end()) { - - attemptToLoadTexture = true; - itemLoadAttempted[texSystemId] = true; - } - - if(attemptToLoadTexture == true) { - Renderer &renderer = Renderer::getInstance(); - *tex = renderer.newTexture2D(rsGlobal); - if (*tex) { - - (*tex)->setForceCompressionDisabled(compressionDisabled); - (*tex)->setMipmap(setMipMap); - if(setAlpha == true) { - - (*tex)->setFormat(Texture::fAlpha); - (*tex)->getPixmap()->init(1); - } - - try { - string fileToLoad = uniqueFilePath; - if(loadUniqueFilePath == false) { - - fileToLoad = getGameCustomCoreDataPath(data_path,uniqueFilePath); - } - (*tex)->getPixmap()->load(fileToLoad); - (*tex)->setTextureSystemId(texSystemId); - - renderer.initTexture(rsGlobal,*tex); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(),GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (tex); - } - } - } - } -} - -string CoreData::getDataPath() { - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - if(data_path != "") { - endPathWithSlash(data_path); - } - return data_path; -} - -Texture2D * CoreData::getBackgroundTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&backgroundTexture, getDataPath(), - CORE_MENU_TEXTURES_PATH + "back.tga", tsyst_backgroundTexture, - false, false, false); - - return backgroundTexture; -} -Texture2D *CoreData::getFireTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&fireTexture,data_path, - CORE_MISC_TEXTURES_PATH + "fire_particle.tga", tsyst_fireTexture, - true, true, false); - - return fireTexture; -} -Texture2D *CoreData::getTeamColorTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&teamColorTexture,data_path, - CORE_MISC_TEXTURES_PATH + "team_color_texture.tga", tsyst_teamColorTexture, - true, true, false); - - return teamColorTexture; -} -Texture2D *CoreData::getSnowTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&snowTexture,data_path, - CORE_MISC_TEXTURES_PATH + "snow_particle.tga", tsyst_snowTexture, - false, true, false); - - return snowTexture; -} -Texture2D *CoreData::getLogoTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&logoTexture,data_path, - CORE_MENU_TEXTURES_PATH + "logo.tga", tsyst_logoTexture, - false, false, false); - - return logoTexture; -} -Texture2D *CoreData::getWaterSplashTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&waterSplashTexture,data_path, - CORE_MISC_TEXTURES_PATH + "water_splash.tga", tsyst_waterSplashTexture, - true, true, false); - - return waterSplashTexture; -} -Texture2D *CoreData::getCustomTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&customTexture,data_path, - CORE_MENU_TEXTURES_PATH + "custom_texture.tga", tsyst_customTexture, - true, false, false); - - return customTexture; -} -Texture2D *CoreData::getButtonSmallTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&buttonSmallTexture,data_path, - CORE_MENU_TEXTURES_PATH + "button_small.tga", tsyst_buttonSmallTexture, - true, false, false, true); - - return buttonSmallTexture; -} -Texture2D *CoreData::getButtonBigTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&buttonBigTexture,data_path, - CORE_MENU_TEXTURES_PATH + "button_big.tga", tsyst_buttonBigTexture, - true, false, false, true); - - return buttonBigTexture; -} -Texture2D *CoreData::getHorizontalLineTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&horizontalLineTexture,data_path, - CORE_MENU_TEXTURES_PATH + "line_horizontal.tga", tsyst_horizontalLineTexture, - true, false, false, true); - - return horizontalLineTexture; -} -Texture2D *CoreData::getVerticalLineTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&verticalLineTexture,data_path, - CORE_MENU_TEXTURES_PATH + "line_vertical.tga", tsyst_verticalLineTexture, - true, false, false, true); - - return verticalLineTexture; -} -Texture2D *CoreData::getCheckBoxTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&checkBoxTexture,data_path, - CORE_MENU_TEXTURES_PATH + "checkbox.tga", tsyst_checkBoxTexture, - true, false, false, true); - - return checkBoxTexture; -} -Texture2D *CoreData::getCheckedCheckBoxTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&checkedCheckBoxTexture,data_path, - CORE_MENU_TEXTURES_PATH + "checkbox_checked.tga", tsyst_checkedCheckBoxTexture, - true, false, false, true); - - return checkedCheckBoxTexture; -} -Texture2D *CoreData::getNotOnServerTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(¬OnServerTexture,data_path, - CORE_MENU_TEXTURES_PATH + "not_on_server.tga", tsyst_notOnServerTexture, - true, false, false); - - return notOnServerTexture; -} -Texture2D *CoreData::getOnServerDifferentTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&onServerDifferentTexture,data_path, - CORE_MENU_TEXTURES_PATH + "on_server_different.tga", tsyst_onServerDifferentTexture, - true, false, false); - - return onServerDifferentTexture; -} -Texture2D *CoreData::getOnServerTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&onServerTexture,data_path, - CORE_MENU_TEXTURES_PATH + "on_server.tga", tsyst_onServerTexture, - true, false, false); - - return onServerTexture; -} -Texture2D *CoreData::getOnServerInstalledTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&onServerInstalledTexture,data_path, - CORE_MENU_TEXTURES_PATH + "on_server_installed.tga", tsyst_onServerInstalledTexture, - true, false, false); - - return onServerInstalledTexture; -} -Texture2D *CoreData::getStatusReadyTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&statusReadyTexture,data_path, - CORE_MENU_TEXTURES_PATH + "status_ready.png", tsyst_statusReadyTexture, - true, false, false); - - return statusReadyTexture; -} -Texture2D *CoreData::getStatusNotReadyTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&statusNotReadyTexture,data_path, - CORE_MENU_TEXTURES_PATH + "status_notready.png", tsyst_statusNotReadyTexture, - true, false, false); - - return statusNotReadyTexture; -} -Texture2D *CoreData::getStatusBRBTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&statusBRBTexture,data_path, - CORE_MENU_TEXTURES_PATH + "status_brb.png", tsyst_statusBRBTexture, - true, false, false); - - return statusBRBTexture; -} -Texture2D *CoreData::getGameWinnerTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&gameWinnerTexture,data_path, - CORE_MISC_TEXTURES_PATH + "game_winner.png", tsyst_gameWinnerTexture, - true, false, false, true); - - return gameWinnerTexture; -} - -Texture2D *CoreData::getHealthbarTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&healthbarTexture,data_path, - CORE_MISC_TEXTURES_PATH + "healthbar.png", tsyst_healthbarTexture, - true, false, false, true); - - return healthbarTexture; -} - -Texture2D *CoreData::getHealthbarBackgroundTexture() { - string data_path = getDataPath(); - loadTextureIfRequired(&healthbarBackgroundTexture,data_path, - CORE_MISC_TEXTURES_PATH + "healthbarBackground.png", tsyst_healthbarBackgroundTexture, - true, false, false, true); - - return healthbarBackgroundTexture; -} - -void CoreData::loadLogoTextureExtraIfRequired() { - int loadAttemptLookupKey = tsyst_COUNT + 1; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - string data_path = getDataPath(); - logoTextureList.clear(); - string logosPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + "logo*.*"; - vector logoFilenames; - findAll(logosPath, logoFilenames, false, false); - for (int index = 0; index < (int)logoFilenames.size(); ++index) { - - string logo = logoFilenames[index]; - if (strcmp("logo.tga", logo.c_str()) != 0) { - - Texture2D* logoTextureExtra = NULL; - loadTextureIfRequired(&logoTextureExtra,data_path, - getGameCustomCoreDataPath(data_path, "") + - CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, - true, false, true); - logoTextureList.push_back(logoTextureExtra); - } - } - if (logoTextureList.empty() == true) { - - logosPath = data_path + CORE_MENU_TEXTURES_PATH + "logo*.*"; - vector logoFilenames; - findAll(logosPath, logoFilenames, false, false); - for (int index = 0; index < (int)logoFilenames.size(); ++index) { - - string logo = logoFilenames[index]; - if (strcmp("logo.tga", logo.c_str()) != 0) { - - Texture2D* logoTextureExtra = NULL; - loadTextureIfRequired(&logoTextureExtra,data_path, - data_path + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, - true, false, true); - logoTextureList.push_back(logoTextureExtra); - } - } - } - } -} -size_t CoreData::getLogoTextureExtraCount() { - loadLogoTextureExtraIfRequired(); - return logoTextureList.size(); -} -Texture2D *CoreData::getLogoTextureExtra(int idx) { - loadLogoTextureExtraIfRequired(); - return logoTextureList[idx]; -} - -void CoreData::loadMiscTextureListIfRequired() { - int loadAttemptLookupKey = tsyst_COUNT + 2; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - string data_path = getDataPath(); - - miscTextureList.clear(); - string introPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + "intro*.*"; - vector introFilenames; - findAll(introPath, introFilenames, false, false); - for (int i = 0; i < (int)introFilenames.size(); ++i) { - string logo = introFilenames[i]; - - Texture2D* logoTextureExtra = NULL; - loadTextureIfRequired(&logoTextureExtra,data_path, - getGameCustomCoreDataPath(data_path, "") + CORE_MENU_TEXTURES_PATH + - logo, tsyst_NONE, - true, false, true); - miscTextureList.push_back(logoTextureExtra); - } - if (miscTextureList.empty() == true) { - introPath = data_path + CORE_MENU_TEXTURES_PATH + "intro*.*"; - vector introFilenames; - findAll(introPath, introFilenames, false, false); - for (int i = 0; i < (int)introFilenames.size(); ++i) { - string logo = introFilenames[i]; - - Texture2D* logoTextureExtra = NULL; - loadTextureIfRequired(&logoTextureExtra,data_path, - data_path + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, - true, false, true); - miscTextureList.push_back(logoTextureExtra); - } - } - - } -} - -std::vector & CoreData::getMiscTextureList() { - loadMiscTextureListIfRequired(); - return miscTextureList; -} - -void CoreData::loadTextures(string data_path) { - // Required to be loaded at program startup as they may be accessed in - // threads or some other dangerous way so lazy loading is not an option - getCustomTexture(); -} - -StaticSound *CoreData::getClickSoundA() { - int loadAttemptLookupKey = tsyst_COUNT + 3; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try { - string data_path = getDataPath(); - clickSoundA.load(getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_a.wav")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - } - return &clickSoundA; -} - -StaticSound *CoreData::getClickSoundB() { - int loadAttemptLookupKey = tsyst_COUNT + 4; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try { - string data_path = getDataPath(); - clickSoundB.load(getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_b.wav")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - } - - return &clickSoundB; -} -StaticSound *CoreData::getClickSoundC() { - int loadAttemptLookupKey = tsyst_COUNT + 5; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try { - string data_path = getDataPath(); - clickSoundC.load(getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_c.wav")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - } - - return &clickSoundC; -} -StaticSound *CoreData::getAttentionSound() { - int loadAttemptLookupKey = tsyst_COUNT + 6; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try { - static Config &config = Config::getInstance(); - attentionSound.load(config.getString ("PlaySoundAttention", "")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - } - - return &attentionSound; -} -StaticSound *CoreData::getHighlightSound() { - int loadAttemptLookupKey = tsyst_COUNT + 7; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try { - static Config &config = Config::getInstance(); - highlightSound.load(config.getString ("PlaySoundHighlight", "")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - } - - return &highlightSound; -} -StaticSound *CoreData::getMarkerSound() { - int loadAttemptLookupKey = tsyst_COUNT + 8; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try { - string data_path = getDataPath(); - markerSound.load(getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "sonar.wav")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - } - - return &markerSound; -} - -void CoreData::loadWaterSoundsIfRequired() { - int loadAttemptLookupKey = tsyst_COUNT + 9; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - string data_path = getDataPath(); - cleanup(); - waterSounds.resize(6); - - for (int index = 0; index < 6; ++index) { - waterSounds[index] = new StaticSound(); - if (waterSounds[index] != NULL) { - try { - waterSounds[index]->load(getGameCustomCoreDataPath(data_path, - CORE_WATER_SOUNDS_PATH + - "water" + intToStr(index) + ".wav")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - } - } - } -} - -StaticSound *CoreData::getWaterSound() { - loadWaterSoundsIfRequired(); - return waterSounds.getRandSound(); -} - -void CoreData::loadSounds(string data_path) { - // sounds -// try { -// clickSoundA.load( -// getGameCustomCoreDataPath(data_path, -// CORE_MENU_SOUND_PATH + "click_a.wav")); -// clickSoundB.load( -// getGameCustomCoreDataPath(data_path, -// CORE_MENU_SOUND_PATH + "click_b.wav")); -// clickSoundC.load( -// getGameCustomCoreDataPath(data_path, -// CORE_MENU_SOUND_PATH + "click_c.wav")); -// attentionSound.load( -// getGameCustomCoreDataPath(data_path, -// CORE_MENU_SOUND_PATH + "attention.wav")); -// highlightSound.load( -// getGameCustomCoreDataPath(data_path, -// CORE_MENU_SOUND_PATH + "highlight.wav")); -// markerSound.load( -// getGameCustomCoreDataPath(data_path, -// CORE_MENU_SOUND_PATH + "sonar.wav")); -// } -// catch (const megaglest_runtime_error& ex) { -// message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), -// tempDataLocation); -// } - -// cleanup(); -// waterSounds.resize(6); + static const string CORE_PATH = "data/core/"; + static const string CORE_MISC_TEXTURES_PATH = + CORE_PATH + "misc_textures/"; + + static const string CORE_MENU_PATH = CORE_PATH + "menu/"; + static const string CORE_MENU_TEXTURES_PATH = + CORE_MENU_PATH + "textures/"; + static const string CORE_MENU_SOUND_PATH = CORE_MENU_PATH + "sound/"; + static const string CORE_MENU_MUSIC_PATH = CORE_MENU_PATH + "music/"; + static const string CORE_MENU_VIDEOS_PATH = CORE_MENU_PATH + "videos/"; + + static const string CORE_WATER_SOUNDS_PATH = CORE_PATH + "/water_sounds/"; + + CoreData & CoreData::getInstance () + { + static CoreData coreData; + return coreData; + } + + CoreData::CoreData () + { + logoTexture = NULL; + logoTextureList.clear (); + backgroundTexture = NULL; + fireTexture = NULL; + teamColorTexture = NULL; + snowTexture = NULL; + waterSplashTexture = NULL; + customTexture = NULL; + buttonSmallTexture = NULL; + buttonBigTexture = NULL; + horizontalLineTexture = NULL; + verticalLineTexture = NULL; + checkBoxTexture = NULL; + checkedCheckBoxTexture = NULL; + gameWinnerTexture = NULL; + notOnServerTexture = NULL; + onServerDifferentTexture = NULL; + onServerTexture = NULL; + onServerInstalledTexture = NULL; + statusReadyTexture = NULL; + statusNotReadyTexture = NULL; + statusBRBTexture = NULL; + + healthbarTexture = NULL; + healthbarBackgroundTexture = NULL; + + miscTextureList.clear (); + + displayFont = NULL; + menuFontNormal = NULL; + displayFontSmall = NULL; + menuFontBig = NULL; + menuFontVeryBig = NULL; + consoleFont = NULL; + + displayFont3D = NULL; + menuFontNormal3D = NULL; + displayFontSmall3D = NULL; + menuFontBig3D = NULL; + menuFontVeryBig3D = NULL; + consoleFont3D = NULL; + + introVideoFilename = ""; + mainMenuVideoFilename = ""; + + battleEndWinVideoFilename = ""; + battleEndWinVideoFilenameFallback = ""; + battleEndWinMusicFilename = ""; + battleEndLoseVideoFilename = ""; + battleEndLoseVideoFilenameFallback = ""; + battleEndLoseMusicFilename = ""; + } + + CoreData::~CoreData () + { + cleanup (); + } + + void CoreData::cleanup () + { + deleteValues (waterSounds.getSoundsPtr ()->begin (), + waterSounds.getSoundsPtr ()->end ()); + waterSounds.getSoundsPtr ()->clear (); + } + + Texture2D *CoreData::getTextureBySystemId (TextureSystemType type) + { + Texture2D *result = NULL; + switch (type) + { + case tsyst_logoTexture: + result = getLogoTexture (); + break; + //std::vector logoTextureList; + case tsyst_backgroundTexture: + result = getBackgroundTexture (); + break; + case tsyst_fireTexture: + result = getFireTexture (); + break; + case tsyst_teamColorTexture: + result = getTeamColorTexture (); + break; + case tsyst_snowTexture: + result = getSnowTexture (); + break; + case tsyst_waterSplashTexture: + result = getWaterSplashTexture (); + break; + case tsyst_customTexture: + result = getCustomTexture (); + break; + case tsyst_buttonSmallTexture: + result = buttonSmallTexture; + break; + case tsyst_buttonBigTexture: + result = buttonBigTexture; + break; + case tsyst_horizontalLineTexture: + result = horizontalLineTexture; + break; + case tsyst_verticalLineTexture: + result = verticalLineTexture; + break; + case tsyst_checkBoxTexture: + result = checkBoxTexture; + break; + case tsyst_checkedCheckBoxTexture: + result = checkedCheckBoxTexture; + break; + case tsyst_gameWinnerTexture: + result = gameWinnerTexture; + break; + case tsyst_notOnServerTexture: + result = notOnServerTexture; + break; + case tsyst_onServerDifferentTexture: + result = onServerDifferentTexture; + break; + case tsyst_onServerTexture: + result = onServerTexture; + break; + case tsyst_onServerInstalledTexture: + result = onServerInstalledTexture; + break; + case tsyst_statusReadyTexture: + result = statusReadyTexture; + break; + case tsyst_statusNotReadyTexture: + result = statusNotReadyTexture; + break; + case tsyst_statusBRBTexture: + result = statusBRBTexture; + break; + case tsyst_healthbarTexture: + result = healthbarTexture; + break; + case tsyst_healthbarBackgroundTexture: + result = healthbarBackgroundTexture; + break; + + //std::vector miscTextureList; + } + return result; + } + + void CoreData::cleanupTexture (Texture2D ** texture) + { + Renderer & renderer = Renderer::getInstance (); + renderer.endTexture (rsGlobal, *texture); + *texture = NULL; + } + + void CoreData::loadTextureIfRequired (Texture2D ** tex, string data_path, + string uniqueFilePath, + int texSystemId, bool setMipMap, + bool setAlpha, + bool loadUniqueFilePath, + bool compressionDisabled) + { + if (*tex == NULL) + { + bool attemptToLoadTexture = (texSystemId == tsyst_NONE); + if (attemptToLoadTexture == false && + itemLoadAttempted.find (texSystemId) == itemLoadAttempted.end ()) + { + + attemptToLoadTexture = true; + itemLoadAttempted[texSystemId] = true; + } + + if (attemptToLoadTexture == true) + { + Renderer & renderer = Renderer::getInstance (); + *tex = renderer.newTexture2D (rsGlobal); + if (*tex) + { + + (*tex)->setForceCompressionDisabled (compressionDisabled); + (*tex)->setMipmap (setMipMap); + if (setAlpha == true) + { + + (*tex)->setFormat (Texture::fAlpha); + (*tex)->getPixmap ()->init (1); + } + + try + { + string fileToLoad = uniqueFilePath; + if (loadUniqueFilePath == false) + { + + fileToLoad = + getGameCustomCoreDataPath (data_path, uniqueFilePath); + } + (*tex)->getPixmap ()->load (fileToLoad); + (*tex)->setTextureSystemId (texSystemId); + + renderer.initTexture (rsGlobal, *tex); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + cleanupTexture (tex); + } + } + } + } + } + + string CoreData::getDataPath () + { + string data_path = + getGameReadWritePath (GameConstants::path_data_CacheLookupKey); + if (data_path != "") + { + endPathWithSlash (data_path); + } + return data_path; + } + + Texture2D *CoreData::getBackgroundTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&backgroundTexture, getDataPath (), + CORE_MENU_TEXTURES_PATH + "back.tga", + tsyst_backgroundTexture, false, false, false); + + return backgroundTexture; + } + Texture2D *CoreData::getFireTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&fireTexture, data_path, + CORE_MISC_TEXTURES_PATH + "fire_particle.tga", + tsyst_fireTexture, true, true, false); + + return fireTexture; + } + Texture2D *CoreData::getTeamColorTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&teamColorTexture, data_path, + CORE_MISC_TEXTURES_PATH + + "team_color_texture.tga", tsyst_teamColorTexture, + true, true, false); + + return teamColorTexture; + } + Texture2D *CoreData::getSnowTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&snowTexture, data_path, + CORE_MISC_TEXTURES_PATH + "snow_particle.tga", + tsyst_snowTexture, false, true, false); + + return snowTexture; + } + Texture2D *CoreData::getLogoTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&logoTexture, data_path, + CORE_MENU_TEXTURES_PATH + "logo.tga", + tsyst_logoTexture, false, false, false); + + return logoTexture; + } + Texture2D *CoreData::getWaterSplashTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&waterSplashTexture, data_path, + CORE_MISC_TEXTURES_PATH + "water_splash.tga", + tsyst_waterSplashTexture, true, true, false); + + return waterSplashTexture; + } + Texture2D *CoreData::getCustomTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&customTexture, data_path, + CORE_MENU_TEXTURES_PATH + "custom_texture.tga", + tsyst_customTexture, true, false, false); + + return customTexture; + } + Texture2D *CoreData::getButtonSmallTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&buttonSmallTexture, data_path, + CORE_MENU_TEXTURES_PATH + "button_small.tga", + tsyst_buttonSmallTexture, true, false, false, + true); + + return buttonSmallTexture; + } + Texture2D *CoreData::getButtonBigTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&buttonBigTexture, data_path, + CORE_MENU_TEXTURES_PATH + "button_big.tga", + tsyst_buttonBigTexture, true, false, false, + true); + + return buttonBigTexture; + } + Texture2D *CoreData::getHorizontalLineTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&horizontalLineTexture, data_path, + CORE_MENU_TEXTURES_PATH + "line_horizontal.tga", + tsyst_horizontalLineTexture, true, false, false, + true); + + return horizontalLineTexture; + } + Texture2D *CoreData::getVerticalLineTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&verticalLineTexture, data_path, + CORE_MENU_TEXTURES_PATH + "line_vertical.tga", + tsyst_verticalLineTexture, true, false, false, + true); + + return verticalLineTexture; + } + Texture2D *CoreData::getCheckBoxTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&checkBoxTexture, data_path, + CORE_MENU_TEXTURES_PATH + "checkbox.tga", + tsyst_checkBoxTexture, true, false, false, true); + + return checkBoxTexture; + } + Texture2D *CoreData::getCheckedCheckBoxTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&checkedCheckBoxTexture, data_path, + CORE_MENU_TEXTURES_PATH + "checkbox_checked.tga", + tsyst_checkedCheckBoxTexture, true, false, false, + true); + + return checkedCheckBoxTexture; + } + Texture2D *CoreData::getNotOnServerTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (¬OnServerTexture, data_path, + CORE_MENU_TEXTURES_PATH + "not_on_server.tga", + tsyst_notOnServerTexture, true, false, false); + + return notOnServerTexture; + } + Texture2D *CoreData::getOnServerDifferentTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&onServerDifferentTexture, data_path, + CORE_MENU_TEXTURES_PATH + + "on_server_different.tga", + tsyst_onServerDifferentTexture, true, false, + false); + + return onServerDifferentTexture; + } + Texture2D *CoreData::getOnServerTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&onServerTexture, data_path, + CORE_MENU_TEXTURES_PATH + "on_server.tga", + tsyst_onServerTexture, true, false, false); + + return onServerTexture; + } + Texture2D *CoreData::getOnServerInstalledTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&onServerInstalledTexture, data_path, + CORE_MENU_TEXTURES_PATH + + "on_server_installed.tga", + tsyst_onServerInstalledTexture, true, false, + false); + + return onServerInstalledTexture; + } + Texture2D *CoreData::getStatusReadyTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&statusReadyTexture, data_path, + CORE_MENU_TEXTURES_PATH + "status_ready.png", + tsyst_statusReadyTexture, true, false, false); + + return statusReadyTexture; + } + Texture2D *CoreData::getStatusNotReadyTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&statusNotReadyTexture, data_path, + CORE_MENU_TEXTURES_PATH + "status_notready.png", + tsyst_statusNotReadyTexture, true, false, false); + + return statusNotReadyTexture; + } + Texture2D *CoreData::getStatusBRBTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&statusBRBTexture, data_path, + CORE_MENU_TEXTURES_PATH + "status_brb.png", + tsyst_statusBRBTexture, true, false, false); + + return statusBRBTexture; + } + Texture2D *CoreData::getGameWinnerTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&gameWinnerTexture, data_path, + CORE_MISC_TEXTURES_PATH + "game_winner.png", + tsyst_gameWinnerTexture, true, false, false, + true); + + return gameWinnerTexture; + } + + Texture2D *CoreData::getHealthbarTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&healthbarTexture, data_path, + CORE_MISC_TEXTURES_PATH + "healthbar.png", + tsyst_healthbarTexture, true, false, false, + true); + + return healthbarTexture; + } + + Texture2D *CoreData::getHealthbarBackgroundTexture () + { + string data_path = getDataPath (); + loadTextureIfRequired (&healthbarBackgroundTexture, data_path, + CORE_MISC_TEXTURES_PATH + + "healthbarBackground.png", + tsyst_healthbarBackgroundTexture, true, false, + false, true); + + return healthbarBackgroundTexture; + } + + void CoreData::loadLogoTextureExtraIfRequired () + { + int loadAttemptLookupKey = tsyst_COUNT + 1; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath (); + logoTextureList.clear (); + string logosPath = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_TEXTURES_PATH + "logo*.*"; + vector < string > logoFilenames; + findAll (logosPath, logoFilenames, false, false); + for (int index = 0; index < (int) logoFilenames.size (); ++index) + { + + string logo = logoFilenames[index]; + if (strcmp ("logo.tga", logo.c_str ()) != 0) + { + + Texture2D *logoTextureExtra = NULL; + loadTextureIfRequired (&logoTextureExtra, data_path, + getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, + true, false, true); + logoTextureList.push_back (logoTextureExtra); + } + } + if (logoTextureList.empty () == true) + { + + logosPath = data_path + CORE_MENU_TEXTURES_PATH + "logo*.*"; + vector < string > logoFilenames; + findAll (logosPath, logoFilenames, false, false); + for (int index = 0; index < (int) logoFilenames.size (); ++index) + { + + string logo = logoFilenames[index]; + if (strcmp ("logo.tga", logo.c_str ()) != 0) + { + + Texture2D *logoTextureExtra = NULL; + loadTextureIfRequired (&logoTextureExtra, data_path, + data_path + CORE_MENU_TEXTURES_PATH + + logo, tsyst_NONE, true, false, true); + logoTextureList.push_back (logoTextureExtra); + } + } + } + } + } + size_t CoreData::getLogoTextureExtraCount () + { + loadLogoTextureExtraIfRequired (); + return logoTextureList.size (); + } + Texture2D *CoreData::getLogoTextureExtra (int idx) + { + loadLogoTextureExtraIfRequired (); + return logoTextureList[idx]; + } + + void CoreData::loadMiscTextureListIfRequired () + { + int loadAttemptLookupKey = tsyst_COUNT + 2; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath (); + + miscTextureList.clear (); + string introPath = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_TEXTURES_PATH + "intro*.*"; + vector < string > introFilenames; + findAll (introPath, introFilenames, false, false); + for (int i = 0; i < (int) introFilenames.size (); ++i) + { + string logo = introFilenames[i]; + + Texture2D *logoTextureExtra = NULL; + loadTextureIfRequired (&logoTextureExtra, data_path, + getGameCustomCoreDataPath (data_path, + "") + + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, + true, false, true); + miscTextureList.push_back (logoTextureExtra); + } + if (miscTextureList.empty () == true) + { + introPath = data_path + CORE_MENU_TEXTURES_PATH + "intro*.*"; + vector < string > introFilenames; + findAll (introPath, introFilenames, false, false); + for (int i = 0; i < (int) introFilenames.size (); ++i) + { + string logo = introFilenames[i]; + + Texture2D *logoTextureExtra = NULL; + loadTextureIfRequired (&logoTextureExtra, data_path, + data_path + CORE_MENU_TEXTURES_PATH + logo, + tsyst_NONE, true, false, true); + miscTextureList.push_back (logoTextureExtra); + } + } + + } + } + + std::vector < Texture2D * >&CoreData::getMiscTextureList () + { + loadMiscTextureListIfRequired (); + return miscTextureList; + } + + void CoreData::loadTextures (string data_path) + { + // Required to be loaded at program startup as they may be accessed in + // threads or some other dangerous way so lazy loading is not an option + getCustomTexture (); + } + + StaticSound *CoreData::getClickSoundA () + { + int loadAttemptLookupKey = tsyst_COUNT + 3; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try + { + string data_path = getDataPath (); + clickSoundA.load (getGameCustomCoreDataPath (data_path, + CORE_MENU_SOUND_PATH + + "click_a.wav")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + return &clickSoundA; + } + + StaticSound *CoreData::getClickSoundB () + { + int loadAttemptLookupKey = tsyst_COUNT + 4; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try + { + string data_path = getDataPath (); + clickSoundB.load (getGameCustomCoreDataPath (data_path, + CORE_MENU_SOUND_PATH + + "click_b.wav")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + + return &clickSoundB; + } + StaticSound *CoreData::getClickSoundC () + { + int loadAttemptLookupKey = tsyst_COUNT + 5; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try + { + string data_path = getDataPath (); + clickSoundC.load (getGameCustomCoreDataPath (data_path, + CORE_MENU_SOUND_PATH + + "click_c.wav")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + + return &clickSoundC; + } + StaticSound *CoreData::getAttentionSound () + { + int loadAttemptLookupKey = tsyst_COUNT + 6; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try + { + static Config & config = Config::getInstance (); + attentionSound.load (config.getString ("PlaySoundAttention", "")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + + return &attentionSound; + } + StaticSound *CoreData::getHighlightSound () + { + int loadAttemptLookupKey = tsyst_COUNT + 7; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try + { + static Config & config = Config::getInstance (); + highlightSound.load (config.getString ("PlaySoundHighlight", "")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + + return &highlightSound; + } + StaticSound *CoreData::getMarkerSound () + { + int loadAttemptLookupKey = tsyst_COUNT + 8; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try + { + string data_path = getDataPath (); + markerSound.load (getGameCustomCoreDataPath (data_path, + CORE_MENU_SOUND_PATH + + "sonar.wav")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + + return &markerSound; + } + + void CoreData::loadWaterSoundsIfRequired () + { + int loadAttemptLookupKey = tsyst_COUNT + 9; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath (); + cleanup (); + waterSounds.resize (6); + + for (int index = 0; index < 6; ++index) + { + waterSounds[index] = new StaticSound (); + if (waterSounds[index] != NULL) + { + try + { + waterSounds[index]->load (getGameCustomCoreDataPath (data_path, + CORE_WATER_SOUNDS_PATH + + "water" + + intToStr + (index) + + ".wav")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + } + } + } + + StaticSound *CoreData::getWaterSound () + { + loadWaterSoundsIfRequired (); + return waterSounds.getRandSound (); + } + + void CoreData::loadSounds (string data_path) + { + // sounds +// try { +// clickSoundA.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_a.wav")); +// clickSoundB.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_b.wav")); +// clickSoundC.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_c.wav")); +// attentionSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "attention.wav")); +// highlightSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "highlight.wav")); +// markerSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "sonar.wav")); +// } +// catch (const megaglest_runtime_error& ex) { +// message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), +// tempDataLocation); +// } + +// cleanup(); +// waterSounds.resize(6); // -// for (int i = 0; i < 6; ++i) { -// waterSounds[i] = new StaticSound(); -// if (waterSounds[i]) { -// try { -// waterSounds[i]->load( -// getGameCustomCoreDataPath(data_path, -// CORE_WATER_SOUNDS_PATH + "water" + intToStr(i) -// + ".wav")); -// } catch (const megaglest_runtime_error& ex) { -// message(ex.what(), -// GlobalStaticFlags::getIsNonGraphicalModeEnabled(), -// tempDataLocation); -// } -// } -// } -} +// for (int i = 0; i < 6; ++i) { +// waterSounds[i] = new StaticSound(); +// if (waterSounds[i]) { +// try { +// waterSounds[i]->load( +// getGameCustomCoreDataPath(data_path, +// CORE_WATER_SOUNDS_PATH + "water" + intToStr(i) +// + ".wav")); +// } catch (const megaglest_runtime_error& ex) { +// message(ex.what(), +// GlobalStaticFlags::getIsNonGraphicalModeEnabled(), +// tempDataLocation); +// } +// } +// } + } -void CoreData::loadMusicIfRequired() { - int loadAttemptLookupKey = tsyst_COUNT + 10; - if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + void CoreData::loadMusicIfRequired () + { + int loadAttemptLookupKey = tsyst_COUNT + 10; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { - itemLoadAttempted[loadAttemptLookupKey] = true; + itemLoadAttempted[loadAttemptLookupKey] = true; - string data_path = getDataPath(); + string data_path = getDataPath (); - XmlTree xmlTree; - xmlTree.load( - getGameCustomCoreDataPath(data_path, CORE_MENU_PATH + "menu.xml"), - Properties::getTagReplacementValues()); - const XmlNode* menuNode = xmlTree.getRootNode(); - string menuMusicPath = "/menu/music/"; - string menuIntroMusicFile = "intro_music.ogg"; - string menuMusicFile = "menu_music.ogg"; - if (menuNode->hasChild("intro") == true) { - const XmlNode* introNode = menuNode->getChild("intro"); - // intro info - const XmlNode* menuPathNode = introNode->getChild("menu-music-path"); - menuMusicPath = - menuPathNode->getAttribute("value")->getRestrictedValue(); - const XmlNode* menuIntroMusicNode = introNode->getChild( - "menu-intro-music"); - menuIntroMusicFile = - menuIntroMusicNode->getAttribute("value")->getRestrictedValue(); - const XmlNode* menuMusicNode = introNode->getChild("menu-music"); - menuMusicFile = - menuMusicNode->getAttribute("value")->getRestrictedValue(); - } - try { - introMusic.open( - getGameCustomCoreDataPath(data_path, - CORE_PATH + menuMusicPath + menuIntroMusicFile)); - introMusic.setNext(&menuMusic); - menuMusic.open( - getGameCustomCoreDataPath(data_path, - CORE_PATH + menuMusicPath + menuMusicFile)); - menuMusic.setNext(&menuMusic); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - } -} + XmlTree xmlTree; + xmlTree. + load (getGameCustomCoreDataPath + (data_path, CORE_MENU_PATH + "menu.xml"), + Properties::getTagReplacementValues ()); + const XmlNode *menuNode = xmlTree.getRootNode (); + string menuMusicPath = "/menu/music/"; + string menuIntroMusicFile = "intro_music.ogg"; + string menuMusicFile = "menu_music.ogg"; + if (menuNode->hasChild ("intro") == true) + { + const XmlNode *introNode = menuNode->getChild ("intro"); + // intro info + const XmlNode *menuPathNode = + introNode->getChild ("menu-music-path"); + menuMusicPath = + menuPathNode->getAttribute ("value")->getRestrictedValue (); + const XmlNode *menuIntroMusicNode = + introNode->getChild ("menu-intro-music"); + menuIntroMusicFile = + menuIntroMusicNode->getAttribute ("value")->getRestrictedValue (); + const XmlNode *menuMusicNode = introNode->getChild ("menu-music"); + menuMusicFile = + menuMusicNode->getAttribute ("value")->getRestrictedValue (); + } + try + { + introMusic.open (getGameCustomCoreDataPath (data_path, + CORE_PATH + + menuMusicPath + + menuIntroMusicFile)); + introMusic.setNext (&menuMusic); + menuMusic.open (getGameCustomCoreDataPath (data_path, + CORE_PATH + + menuMusicPath + + menuMusicFile)); + menuMusic.setNext (&menuMusic); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + } -StrSound *CoreData::getIntroMusic() { - loadMusicIfRequired(); - return &introMusic; -} + StrSound *CoreData::getIntroMusic () + { + loadMusicIfRequired (); + return &introMusic; + } -StrSound *CoreData::getMenuMusic() { - loadMusicIfRequired(); - return &menuMusic; -} + StrSound *CoreData::getMenuMusic () + { + loadMusicIfRequired (); + return &menuMusic; + } -void CoreData::loadMusic(string data_path) { -} + void CoreData::loadMusic (string data_path) + { + } -void CoreData::loadIntroMedia(string data_path) { - Config &config= Config::getInstance(); + void CoreData::loadIntroMedia (string data_path) + { + Config & config = Config::getInstance (); - introVideoFilename = config.getString("IntroVideoURL", ""); - introVideoFilenameFallback = config.getString("IntroVideoURLFallback", ""); - if (introVideoFilename == "") { - string introVideoPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_VIDEOS_PATH + "intro.*"; - vector introVideos; - findAll(introVideoPath, introVideos, false, false); - for (int i = 0; i < (int)introVideos.size(); ++i) { - string video = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_VIDEOS_PATH + introVideos[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if intro video [%s] exists\n", video.c_str()); + introVideoFilename = config.getString ("IntroVideoURL", ""); + introVideoFilenameFallback = + config.getString ("IntroVideoURLFallback", ""); + if (introVideoFilename == "") + { + string introVideoPath = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_VIDEOS_PATH + "intro.*"; + vector < string > introVideos; + findAll (introVideoPath, introVideos, false, false); + for (int i = 0; i < (int) introVideos.size (); ++i) + { + string video = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_VIDEOS_PATH + introVideos[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if intro video [%s] exists\n", video.c_str ()); - if (fileExists(video)) { - introVideoFilename = video; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("FOUND intro video [%s] will use this file\n", - video.c_str()); + if (fileExists (video)) + { + introVideoFilename = video; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("FOUND intro video [%s] will use this file\n", + video.c_str ()); - break; - } - } - if (introVideoFilename == "") { - introVideoPath = data_path + CORE_MENU_VIDEOS_PATH + "intro.*"; - introVideos.clear(); - findAll(introVideoPath, introVideos, false, false); - for (int i = 0; i < (int)introVideos.size(); ++i) { - string video = data_path + CORE_MENU_VIDEOS_PATH - + introVideos[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if intro video [%s] exists\n", - video.c_str()); + break; + } + } + if (introVideoFilename == "") + { + introVideoPath = data_path + CORE_MENU_VIDEOS_PATH + "intro.*"; + introVideos.clear (); + findAll (introVideoPath, introVideos, false, false); + for (int i = 0; i < (int) introVideos.size (); ++i) + { + string video = data_path + CORE_MENU_VIDEOS_PATH + introVideos[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if intro video [%s] exists\n", + video.c_str ()); - if (fileExists(video)) { - introVideoFilename = video; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("FOUND intro video [%s] will use this file\n", - video.c_str()); + if (fileExists (video)) + { + introVideoFilename = video; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("FOUND intro video [%s] will use this file\n", + video.c_str ()); - break; - } - } - } - } -} + break; + } + } + } + } + } -void CoreData::loadMainMenuMedia(string data_path) { - Config &config= Config::getInstance(); + void CoreData::loadMainMenuMedia (string data_path) + { + Config & config = Config::getInstance (); - mainMenuVideoFilename = config.getString("MainMenuVideoURL", ""); - mainMenuVideoFilenameFallback = config.getString("MainMenuVideoURLFallback", - ""); - if (mainMenuVideoFilename == "") { - string mainVideoPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_VIDEOS_PATH + "main.*"; - vector mainVideos; - findAll(mainVideoPath, mainVideos, false, false); - for (int i = 0; i < (int)mainVideos.size(); ++i) { - string video = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_VIDEOS_PATH + mainVideos[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if mainmenu video [%s] exists\n", - video.c_str()); + mainMenuVideoFilename = config.getString ("MainMenuVideoURL", ""); + mainMenuVideoFilenameFallback = + config.getString ("MainMenuVideoURLFallback", ""); + if (mainMenuVideoFilename == "") + { + string mainVideoPath = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_VIDEOS_PATH + "main.*"; + vector < string > mainVideos; + findAll (mainVideoPath, mainVideos, false, false); + for (int i = 0; i < (int) mainVideos.size (); ++i) + { + string video = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_VIDEOS_PATH + mainVideos[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if mainmenu video [%s] exists\n", + video.c_str ()); - if (fileExists(video)) { - mainMenuVideoFilename = video; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("FOUND mainmenu video [%s] will use this file\n", - video.c_str()); + if (fileExists (video)) + { + mainMenuVideoFilename = video; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("FOUND mainmenu video [%s] will use this file\n", + video.c_str ()); - break; - } - } - if (mainMenuVideoFilename == "") { - mainVideoPath = data_path + CORE_MENU_VIDEOS_PATH + "main.*"; - mainVideos.clear(); - findAll(mainVideoPath, mainVideos, false, false); - for (int i = 0; i < (int)mainVideos.size(); ++i) { - string video = data_path + CORE_MENU_VIDEOS_PATH - + mainVideos[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if mainmenu video [%s] exists\n", - video.c_str()); + break; + } + } + if (mainMenuVideoFilename == "") + { + mainVideoPath = data_path + CORE_MENU_VIDEOS_PATH + "main.*"; + mainVideos.clear (); + findAll (mainVideoPath, mainVideos, false, false); + for (int i = 0; i < (int) mainVideos.size (); ++i) + { + string video = data_path + CORE_MENU_VIDEOS_PATH + mainVideos[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if mainmenu video [%s] exists\n", + video.c_str ()); - if (fileExists(video)) { - mainMenuVideoFilename = video; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("FOUND mainmenu video [%s] will use this file\n", - video.c_str()); + if (fileExists (video)) + { + mainMenuVideoFilename = video; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("FOUND mainmenu video [%s] will use this file\n", + video.c_str ()); - break; - } - } - } - } -} + break; + } + } + } + } + } -void CoreData::loadBattleEndMedia(string data_path) { - Config &config= Config::getInstance(); + void CoreData::loadBattleEndMedia (string data_path) + { + Config & config = Config::getInstance (); - battleEndWinVideoFilename = config.getString("BattleEndWinVideoURL", ""); - battleEndWinVideoFilenameFallback = config.getString( - "BattleEndWinVideoURLFallback", ""); - if (battleEndWinVideoFilename == "") { - string battleEndWinVideoPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_VIDEOS_PATH + "battle_end_win.*"; - vector battleEndWinVideos; - findAll(battleEndWinVideoPath, battleEndWinVideos, false, false); - for (int i = 0; i < (int)battleEndWinVideos.size(); ++i) { - string video = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_VIDEOS_PATH + battleEndWinVideos[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if battle end win video [%s] exists\n", - video.c_str()); + battleEndWinVideoFilename = + config.getString ("BattleEndWinVideoURL", ""); + battleEndWinVideoFilenameFallback = + config.getString ("BattleEndWinVideoURLFallback", ""); + if (battleEndWinVideoFilename == "") + { + string battleEndWinVideoPath = + getGameCustomCoreDataPath (data_path, + "") + CORE_MENU_VIDEOS_PATH + + "battle_end_win.*"; + vector < string > battleEndWinVideos; + findAll (battleEndWinVideoPath, battleEndWinVideos, false, false); + for (int i = 0; i < (int) battleEndWinVideos.size (); ++i) + { + string video = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_VIDEOS_PATH + battleEndWinVideos[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if battle end win video [%s] exists\n", + video.c_str ()); - if (fileExists(video)) { - battleEndWinVideoFilename = video; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf( - "FOUND battle end win video [%s] will use this file\n", - video.c_str()); + if (fileExists (video)) + { + battleEndWinVideoFilename = video; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("FOUND battle end win video [%s] will use this file\n", + video.c_str ()); - break; - } - } - if (battleEndWinVideoFilename == "") { - battleEndWinVideoPath = data_path + CORE_MENU_VIDEOS_PATH - + "battle_end_win.*"; - battleEndWinVideos.clear(); - findAll(battleEndWinVideoPath, battleEndWinVideos, false, false); - for (int i = 0; i < (int)battleEndWinVideos.size(); ++i) { - string video = data_path + CORE_MENU_VIDEOS_PATH - + battleEndWinVideos[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if battle end win video [%s] exists\n", - video.c_str()); + break; + } + } + if (battleEndWinVideoFilename == "") + { + battleEndWinVideoPath = data_path + CORE_MENU_VIDEOS_PATH + + "battle_end_win.*"; + battleEndWinVideos.clear (); + findAll (battleEndWinVideoPath, battleEndWinVideos, false, false); + for (int i = 0; i < (int) battleEndWinVideos.size (); ++i) + { + string video = data_path + CORE_MENU_VIDEOS_PATH + + battleEndWinVideos[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if battle end win video [%s] exists\n", + video.c_str ()); - if (fileExists(video)) { - battleEndWinVideoFilename = video; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf( - "FOUND battle end video win [%s] will use this file\n", - video.c_str()); + if (fileExists (video)) + { + battleEndWinVideoFilename = video; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("FOUND battle end video win [%s] will use this file\n", + video.c_str ()); - break; - } - } - } - } - battleEndWinMusicFilename = config.getString("BattleEndWinMusicFilename", - ""); - if (battleEndWinMusicFilename == "") { - string battleEndWinPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_MUSIC_PATH + "battle_end_win.*"; - vector battleEndWinMusic; - findAll(battleEndWinPath, battleEndWinMusic, false, false); - for (int i = 0; i < (int)battleEndWinMusic.size(); ++i) { - string music = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_MUSIC_PATH + battleEndWinMusic[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if battle end win music [%s] exists\n", - music.c_str()); + break; + } + } + } + } + battleEndWinMusicFilename = + config.getString ("BattleEndWinMusicFilename", ""); + if (battleEndWinMusicFilename == "") + { + string battleEndWinPath = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_MUSIC_PATH + "battle_end_win.*"; + vector < string > battleEndWinMusic; + findAll (battleEndWinPath, battleEndWinMusic, false, false); + for (int i = 0; i < (int) battleEndWinMusic.size (); ++i) + { + string music = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_MUSIC_PATH + battleEndWinMusic[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if battle end win music [%s] exists\n", + music.c_str ()); - if (fileExists(music)) { - battleEndWinMusicFilename = music; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf( - "FOUND battle end win music [%s] will use this file\n", - music.c_str()); + if (fileExists (music)) + { + battleEndWinMusicFilename = music; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("FOUND battle end win music [%s] will use this file\n", + music.c_str ()); - break; - } - } - if (battleEndWinMusicFilename == "") { - battleEndWinPath = data_path + CORE_MENU_MUSIC_PATH - + "battle_end_win.*"; - battleEndWinMusic.clear(); - findAll(battleEndWinPath, battleEndWinMusic, false, false); - for (int i = 0; i < (int)battleEndWinMusic.size(); ++i) { - string music = data_path + CORE_MENU_MUSIC_PATH - + battleEndWinMusic[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if battle end win music [%s] exists\n", - music.c_str()); + break; + } + } + if (battleEndWinMusicFilename == "") + { + battleEndWinPath = data_path + CORE_MENU_MUSIC_PATH + + "battle_end_win.*"; + battleEndWinMusic.clear (); + findAll (battleEndWinPath, battleEndWinMusic, false, false); + for (int i = 0; i < (int) battleEndWinMusic.size (); ++i) + { + string music = data_path + CORE_MENU_MUSIC_PATH + + battleEndWinMusic[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if battle end win music [%s] exists\n", + music.c_str ()); - if (fileExists(music)) { - battleEndWinMusicFilename = music; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf( - "FOUND battle end music win [%s] will use this file\n", - music.c_str()); + if (fileExists (music)) + { + battleEndWinMusicFilename = music; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("FOUND battle end music win [%s] will use this file\n", + music.c_str ()); - break; - } - } - } - } - battleEndLoseVideoFilename = config.getString("BattleEndLoseVideoURL", ""); - battleEndLoseVideoFilenameFallback = config.getString( - "BattleEndLoseVideoURLFallback", ""); - if (battleEndLoseVideoFilename == "") { - string battleEndLoseVideoPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_VIDEOS_PATH + "battle_end_lose.*"; - vector battleEndLoseVideos; - findAll(battleEndLoseVideoPath, battleEndLoseVideos, false, false); - for (int i = 0; i < (int)battleEndLoseVideos.size(); ++i) { - string video = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_VIDEOS_PATH + battleEndLoseVideos[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if battle end lose video [%s] exists\n", - video.c_str()); + break; + } + } + } + } + battleEndLoseVideoFilename = + config.getString ("BattleEndLoseVideoURL", ""); + battleEndLoseVideoFilenameFallback = + config.getString ("BattleEndLoseVideoURLFallback", ""); + if (battleEndLoseVideoFilename == "") + { + string battleEndLoseVideoPath = + getGameCustomCoreDataPath (data_path, + "") + CORE_MENU_VIDEOS_PATH + + "battle_end_lose.*"; + vector < string > battleEndLoseVideos; + findAll (battleEndLoseVideoPath, battleEndLoseVideos, false, false); + for (int i = 0; i < (int) battleEndLoseVideos.size (); ++i) + { + string video = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_VIDEOS_PATH + battleEndLoseVideos[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if battle end lose video [%s] exists\n", + video.c_str ()); - if (fileExists(video)) { - battleEndLoseVideoFilename = video; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf( - "FOUND battle end lose video [%s] will use this file\n", - video.c_str()); + if (fileExists (video)) + { + battleEndLoseVideoFilename = video; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("FOUND battle end lose video [%s] will use this file\n", + video.c_str ()); - break; - } - } - if (battleEndLoseVideoFilename == "") { - battleEndLoseVideoPath = data_path + CORE_MENU_VIDEOS_PATH - + "battle_end_lose.*"; - battleEndLoseVideos.clear(); - findAll(battleEndLoseVideoPath, battleEndLoseVideos, false, false); - for (int i = 0; i < (int)battleEndLoseVideos.size(); ++i) { - string video = data_path + CORE_MENU_VIDEOS_PATH - + battleEndLoseVideos[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if battle end lose video [%s] exists\n", - video.c_str()); + break; + } + } + if (battleEndLoseVideoFilename == "") + { + battleEndLoseVideoPath = data_path + CORE_MENU_VIDEOS_PATH + + "battle_end_lose.*"; + battleEndLoseVideos.clear (); + findAll (battleEndLoseVideoPath, battleEndLoseVideos, false, false); + for (int i = 0; i < (int) battleEndLoseVideos.size (); ++i) + { + string video = data_path + CORE_MENU_VIDEOS_PATH + + battleEndLoseVideos[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if battle end lose video [%s] exists\n", + video.c_str ()); - if (fileExists(video)) { - battleEndLoseVideoFilename = video; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf( - "FOUND battle end video lose [%s] will use this file\n", - video.c_str()); + if (fileExists (video)) + { + battleEndLoseVideoFilename = video; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("FOUND battle end video lose [%s] will use this file\n", + video.c_str ()); - break; - } - } - } - } - battleEndLoseMusicFilename = config.getString("BattleEndLoseMusicFilename", - ""); - if (battleEndLoseMusicFilename == "") { - string battleEndLosePath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_MUSIC_PATH + "battle_end_lose.*"; - vector battleEndLoseMusic; - findAll(battleEndLosePath, battleEndLoseMusic, false, false); - for (int i = 0; i < (int)battleEndLoseMusic.size(); ++i) { - string music = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_MUSIC_PATH + battleEndLoseMusic[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if battle end lose music [%s] exists\n", - music.c_str()); + break; + } + } + } + } + battleEndLoseMusicFilename = + config.getString ("BattleEndLoseMusicFilename", ""); + if (battleEndLoseMusicFilename == "") + { + string battleEndLosePath = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_MUSIC_PATH + "battle_end_lose.*"; + vector < string > battleEndLoseMusic; + findAll (battleEndLosePath, battleEndLoseMusic, false, false); + for (int i = 0; i < (int) battleEndLoseMusic.size (); ++i) + { + string music = getGameCustomCoreDataPath (data_path, "") + + CORE_MENU_MUSIC_PATH + battleEndLoseMusic[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if battle end lose music [%s] exists\n", + music.c_str ()); - if (fileExists(music)) { - battleEndLoseMusicFilename = music; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf( - "FOUND battle end lose music [%s] will use this file\n", - music.c_str()); + if (fileExists (music)) + { + battleEndLoseMusicFilename = music; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("FOUND battle end lose music [%s] will use this file\n", + music.c_str ()); - break; - } - } - if (battleEndLoseMusicFilename == "") { - battleEndLosePath = data_path + CORE_MENU_MUSIC_PATH - + "battle_end_lose.*"; - battleEndLoseMusic.clear(); - findAll(battleEndLosePath, battleEndLoseMusic, false, false); - for (int i = 0; i < (int)battleEndLoseMusic.size(); ++i) { - string music = data_path + CORE_MENU_MUSIC_PATH - + battleEndLoseMusic[i]; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Checking if battle end lose music [%s] exists\n", - music.c_str()); + break; + } + } + if (battleEndLoseMusicFilename == "") + { + battleEndLosePath = data_path + CORE_MENU_MUSIC_PATH + + "battle_end_lose.*"; + battleEndLoseMusic.clear (); + findAll (battleEndLosePath, battleEndLoseMusic, false, false); + for (int i = 0; i < (int) battleEndLoseMusic.size (); ++i) + { + string music = data_path + CORE_MENU_MUSIC_PATH + + battleEndLoseMusic[i]; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Checking if battle end lose music [%s] exists\n", + music.c_str ()); - if (fileExists(music)) { - battleEndLoseMusicFilename = music; - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf( - "FOUND battle end music lose [%s] will use this file\n", - music.c_str()); + if (fileExists (music)) + { + battleEndLoseMusicFilename = music; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("FOUND battle end music lose [%s] will use this file\n", + music.c_str ()); - break; - } - } - } - } -} + break; + } + } + } + } + } -void CoreData::load() { - string data_path = CoreData::getDataPath(); + void CoreData::load () + { + string data_path = CoreData::getDataPath (); - Logger::getInstance().add(Lang::getInstance().getString("LogScreenCoreDataLoading","",true)); + Logger::getInstance ().add (Lang::getInstance (). + getString ("LogScreenCoreDataLoading", "", + true)); - // textures - loadTextures(data_path); + // textures + loadTextures (data_path); - // fonts - loadFonts(); + // fonts + loadFonts (); - // sounds - loadSounds(data_path); + // sounds + loadSounds (data_path); - // music - loadMusic(data_path); + // music + loadMusic (data_path); - if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && - Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) { + if (GlobalStaticFlags::getIsNonGraphicalModeEnabled () == false && + Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer () == true) + { - loadIntroMedia(data_path); + loadIntroMedia (data_path); - loadMainMenuMedia(data_path); + loadMainMenuMedia (data_path); - loadBattleEndMedia(data_path); - } -} + loadBattleEndMedia (data_path); + } + } -bool CoreData::hasIntroVideoFilename() const { - bool result = (introVideoFilename != ""); - return result; -} + bool CoreData::hasIntroVideoFilename () const + { + bool result = (introVideoFilename != ""); + return result; + } -bool CoreData::hasMainMenuVideoFilename() const { - bool result = (mainMenuVideoFilename != ""); - return result; -} + bool CoreData::hasMainMenuVideoFilename () const + { + bool result = (mainMenuVideoFilename != ""); + return result; + } //bool CoreData::hasBattleEndVideoFilename(bool won) const { -// bool result = false; -// if(won == true) { -// result =(battleEndWinVideoFilename != ""); -// } -// else { -// result =(battleEndLoseVideoFilename != ""); -// } -// return result; +// bool result = false; +// if(won == true) { +// result =(battleEndWinVideoFilename != ""); +// } +// else { +// result =(battleEndLoseVideoFilename != ""); +// } +// return result; //} -void CoreData::registerFontChangedCallback(std::string entityName, FontChangedCallbackInterface *cb) { - if(entityName == "") { - printf("Register Font Callback detected a blank entityName!\n"); - throw megaglest_runtime_error("Register Font Callback detected a blank entityName!"); - } - if (entityName != "") { - registeredFontChangedCallbacks[entityName].push_back(cb); - } -} -void CoreData::unRegisterFontChangedCallback(std::string entityName) { - if (entityName == "") { - printf("UnRegister Font Callback detected a blank entityName!\n"); - throw megaglest_runtime_error("UnRegister Font Callback detected a blank entityName!"); - } - if(entityName != "") { - registeredFontChangedCallbacks.erase(entityName); - } -} -void CoreData::triggerFontChangedCallbacks(std::string fontUniqueId, Font *font) { - for (std::map >::const_iterator iterMap = - registeredFontChangedCallbacks.begin(); - iterMap != registeredFontChangedCallbacks.end(); ++iterMap) { - for (unsigned int index = 0; index < iterMap->second.size(); ++index) { - //printf("Font Callback detected calling: Control [%s] for Font: [%s] value [%p]\n",iterMap->first.c_str(),fontUniqueId.c_str(),font); - FontChangedCallbackInterface *cb = iterMap->second[index]; - cb->FontChangedCallback(fontUniqueId, font); - } - } -} -void CoreData::loadFonts() { - Lang &lang= Lang::getInstance(); - - //display font - Config &config= Config::getInstance(); - - string displayFontNamePrefix = config.getString("FontDisplayPrefix"); - string displayFontNamePostfix = config.getString("FontDisplayPostfix"); - int displayFontSize = computeFontSize(config.getInt("FontDisplayBaseSize")); - - if(lang.hasString("FontDisplayPrefix") == true) { - displayFontNamePrefix = lang.getString("FontDisplayPrefix"); - } - if(lang.hasString("FontDisplayPostfix") == true) { - displayFontNamePostfix = lang.getString("FontDisplayPostfix"); - } - if(lang.hasString("FontDisplayBaseSize") == true) { - displayFontSize = computeFontSize(strToInt(lang.getString("FontDisplayBaseSize"))); - } - string displayFontName = displayFontNamePrefix + intToStr(displayFontSize) + displayFontNamePostfix; - - displayFont = loadFont(displayFont, displayFontName, displayFontSize, "FontDisplay", "FontDisplayFamily", "displayFont"); - displayFont3D = loadFont(displayFont3D, displayFontName, displayFontSize, "FontDisplay", "FontDisplayFamily", "displayFont3D"); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontName = [%s] displayFontSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontName.c_str(),displayFontSize); - - //menu fonts - string displayFontNameSmallPrefix = config.getString("FontDisplayPrefix"); - string displayFontNameSmallPostfix = config.getString("FontDisplayPostfix"); - int displayFontNameSmallSize = computeFontSize(config.getInt("FontDisplaySmallBaseSize")); - - if(lang.hasString("FontDisplayPrefix") == true) { - displayFontNameSmallPrefix = lang.getString("FontDisplayPrefix"); - } - if(lang.hasString("FontDisplayPostfix") == true) { - displayFontNameSmallPostfix = lang.getString("FontDisplayPostfix"); - } - if(lang.hasString("FontDisplaySmallBaseSize") == true) { - displayFontNameSmallSize = computeFontSize(strToInt(lang.getString("FontDisplaySmallBaseSize"))); - } - string displayFontNameSmall = displayFontNameSmallPrefix + intToStr(displayFontNameSmallSize) + displayFontNameSmallPostfix; - - displayFontSmall = loadFont(displayFontSmall, displayFontNameSmall, displayFontNameSmallSize, "FontSmallDisplay", "FontSmallDisplayFamily", "displayFontSmall"); - displayFontSmall3D = loadFont(displayFontSmall3D, displayFontNameSmall, displayFontNameSmallSize, "FontSmallDisplay", "FontSmallDisplayFamily", "displayFontSmall3D"); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontSmallName = [%s] displayFontSmallNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontNameSmall.c_str(),displayFontNameSmallSize); - - string menuFontNameNormalPrefix = config.getString("FontMenuNormalPrefix"); - string menuFontNameNormalPostfix = config.getString("FontMenuNormalPostfix"); - int menuFontNameNormalSize = computeFontSize(config.getInt("FontMenuNormalBaseSize")); - if(lang.hasString("FontMenuNormalPrefix") == true) { - menuFontNameNormalPrefix = lang.getString("FontMenuNormalPrefix"); - } - if(lang.hasString("FontMenuNormalPostfix") == true) { - menuFontNameNormalPostfix = lang.getString("FontMenuNormalPostfix"); - } - if(lang.hasString("FontMenuNormalBaseSize") == true) { - menuFontNameNormalSize = computeFontSize(strToInt(lang.getString("FontMenuNormalBaseSize"))); - } - string menuFontNameNormal= menuFontNameNormalPrefix + intToStr(menuFontNameNormalSize) + menuFontNameNormalPostfix; - - menuFontNormal = loadFont(menuFontNormal, menuFontNameNormal, menuFontNameNormalSize, "FontMenuNormal", "FontMenuNormalFamily", "menuFontNormal"); - menuFontNormal3D = loadFont(menuFontNormal3D, menuFontNameNormal, menuFontNameNormalSize, "FontMenuNormal", "FontMenuNormalFamily", "menuFontNormal3D"); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNormalName = [%s] menuFontNormalNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameNormal.c_str(),menuFontNameNormalSize); - - string menuFontNameBigPrefix = config.getString("FontMenuBigPrefix"); - string menuFontNameBigPostfix = config.getString("FontMenuBigPostfix"); - int menuFontNameBigSize = computeFontSize(config.getInt("FontMenuBigBaseSize")); - - if(lang.hasString("FontMenuBigPrefix") == true) { - menuFontNameBigPrefix = lang.getString("FontMenuBigPrefix"); - } - if(lang.hasString("FontMenuBigPostfix") == true) { - menuFontNameBigPostfix = lang.getString("FontMenuBigPostfix"); - } - if(lang.hasString("FontMenuBigBaseSize") == true) { - menuFontNameBigSize = computeFontSize(strToInt(lang.getString("FontMenuBigBaseSize"))); - } - string menuFontNameBig= menuFontNameBigPrefix+intToStr(menuFontNameBigSize)+menuFontNameBigPostfix; - - menuFontBig = loadFont(menuFontBig, menuFontNameBig, menuFontNameBigSize, "FontMenuBig", "FontMenuBigFamily", "menuFontBig"); - menuFontBig3D = loadFont(menuFontBig3D, menuFontNameBig, menuFontNameBigSize, "FontMenuBig", "FontMenuBigFamily", "menuFontBig3D"); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameBig = [%s] menuFontNameBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameBig.c_str(),menuFontNameBigSize); - - string menuFontNameVeryBigPrefix = config.getString("FontMenuBigPrefix"); - string menuFontNameVeryBigPostfix = config.getString("FontMenuBigPostfix"); - int menuFontNameVeryBigSize = computeFontSize(config.getInt("FontMenuVeryBigBaseSize")); - - if(lang.hasString("FontMenuBigPrefix") == true) { - menuFontNameVeryBigPrefix = lang.getString("FontMenuBigPrefix"); - } - if(lang.hasString("FontMenuBigPostfix") == true) { - menuFontNameVeryBigPostfix = lang.getString("FontMenuBigPostfix"); - } - if(lang.hasString("FontMenuVeryBigBaseSize") == true) { - menuFontNameVeryBigSize = computeFontSize(strToInt(lang.getString("FontMenuVeryBigBaseSize"))); - } - string menuFontNameVeryBig= menuFontNameVeryBigPrefix + intToStr(menuFontNameVeryBigSize) + menuFontNameVeryBigPostfix; - - menuFontVeryBig = loadFont(menuFontVeryBig, menuFontNameVeryBig, menuFontNameVeryBigSize, "FontMenuVeryBig", "FontMenuVeryBigFamily", "menuFontVeryBig"); - menuFontVeryBig3D = loadFont(menuFontVeryBig3D, menuFontNameVeryBig, menuFontNameVeryBigSize, "FontMenuVeryBig", "FontMenuVeryBigFamily", "menuFontVeryBig3D"); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameVeryBig = [%s] menuFontNameVeryBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameVeryBig.c_str(),menuFontNameVeryBigSize); - - //console font - string consoleFontNamePrefix = config.getString("FontConsolePrefix"); - string consoleFontNamePostfix = config.getString("FontConsolePostfix"); - int consoleFontNameSize = computeFontSize(config.getInt("FontConsoleBaseSize")); - - if(lang.hasString("FontConsolePrefix") == true) { - consoleFontNamePrefix = lang.getString("FontConsolePrefix"); - } - if(lang.hasString("FontConsolePostfix") == true) { - consoleFontNamePostfix = lang.getString("FontConsolePostfix"); - } - if(lang.hasString("FontConsoleBaseSize") == true) { - consoleFontNameSize = computeFontSize(strToInt(lang.getString("FontConsoleBaseSize"))); - } - string consoleFontName= consoleFontNamePrefix + intToStr(consoleFontNameSize) + consoleFontNamePostfix; - - consoleFont = loadFont(consoleFont, consoleFontName, consoleFontNameSize, "FontConsole", "FontConsoleFamily", "consoleFont"); - consoleFont3D = loadFont(consoleFont3D, consoleFontName, consoleFontNameSize, "FontConsole", "FontConsoleFamily", "consoleFont3D"); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] consoleFontName = [%s] consoleFontNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,consoleFontName.c_str(),consoleFontNameSize); -} - - -template T * CoreData::loadFont(Font *menuFont, string menuFontName, - int menuFontNameSize, string fontType, string fontTypeFamily, string fontUniqueKey) { - Renderer &renderer= Renderer::getInstance(); - if(menuFont) { - string fontUniqueId = menuFont->getFontUniqueId(); - renderer.endFont(menuFont, rsGlobal); - menuFont = NULL; - triggerFontChangedCallbacks(fontUniqueId, menuFont); - } - if(Renderer::renderText3DEnabled == false) { - menuFont = renderer.newFont(rsGlobal); - } - else { - menuFont = renderer.newFont3D(rsGlobal); - } - if(menuFont) { - Config &config= Config::getInstance(); - menuFont->setType(menuFontName,config.getString(fontType,""),config.getString(fontTypeFamily,"")); - menuFont->setSize(menuFontNameSize); - menuFont->setWidth(Font::wBold); - menuFont->setFontUniqueId(fontUniqueKey); - triggerFontChangedCallbacks(menuFont->getFontUniqueId(), menuFont); - } - return (T *)menuFont; -} - -int CoreData::computeFontSize(int size) { - int rs = size; - Config &config= Config::getInstance(); - if(Font::forceLegacyFonts == true) { - int screenH = config.getInt("ScreenHeight"); - rs = size * screenH / 1024; - } - //FontSizeAdjustment - rs += config.getInt("FontSizeAdjustment"); - if(Font::forceLegacyFonts == false) { - rs += Font::baseSize; //basesize only for new font system - } - if(Font::forceLegacyFonts == true) { - if(rs < 10) { - rs= 10; - } - } - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fontsize original %d calculated:%d \n",__FILE__,__FUNCTION__,__LINE__,size,rs); - return rs; -} - -void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings, int advancedIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - Config &config = Config::getInstance(); - string userData = config.getString("UserData_Root",""); - if(userData != "") { - endPathWithSlash(userData); + void CoreData::registerFontChangedCallback (std::string entityName, + FontChangedCallbackInterface * + cb) + { + if (entityName == "") + { + printf ("Register Font Callback detected a blank entityName!\n"); + throw + megaglest_runtime_error + ("Register Font Callback detected a blank entityName!"); + } + if (entityName != "") + { + registeredFontChangedCallbacks[entityName].push_back (cb); + } } - fileName = userData + fileName; + void CoreData::unRegisterFontChangedCallback (std::string entityName) + { + if (entityName == "") + { + printf ("UnRegister Font Callback detected a blank entityName!\n"); + throw + megaglest_runtime_error + ("UnRegister Font Callback detected a blank entityName!"); + } + if (entityName != "") + { + registeredFontChangedCallbacks.erase (entityName); + } + } + void CoreData::triggerFontChangedCallbacks (std::string fontUniqueId, + Font * font) + { + for (std::map < std::string, + std::vector < + FontChangedCallbackInterface * > >::const_iterator iterMap = + registeredFontChangedCallbacks.begin (); + iterMap != registeredFontChangedCallbacks.end (); ++iterMap) + { + for (unsigned int index = 0; index < iterMap->second.size (); ++index) + { + //printf("Font Callback detected calling: Control [%s] for Font: [%s] value [%p]\n",iterMap->first.c_str(),fontUniqueId.c_str(),font); + FontChangedCallbackInterface *cb = iterMap->second[index]; + cb->FontChangedCallback (fontUniqueId, font); + } + } + } + void CoreData::loadFonts () + { + Lang & lang = Lang::getInstance (); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str()); + //display font + Config & config = Config::getInstance (); + + string displayFontNamePrefix = config.getString ("FontDisplayPrefix"); + string displayFontNamePostfix = config.getString ("FontDisplayPostfix"); + int displayFontSize = + computeFontSize (config.getInt ("FontDisplayBaseSize")); + + if (lang.hasString ("FontDisplayPrefix") == true) + { + displayFontNamePrefix = lang.getString ("FontDisplayPrefix"); + } + if (lang.hasString ("FontDisplayPostfix") == true) + { + displayFontNamePostfix = lang.getString ("FontDisplayPostfix"); + } + if (lang.hasString ("FontDisplayBaseSize") == true) + { + displayFontSize = + computeFontSize (strToInt (lang.getString ("FontDisplayBaseSize"))); + } + string displayFontName = + displayFontNamePrefix + intToStr (displayFontSize) + + displayFontNamePostfix; + + displayFont = + loadFont < Font2D > (displayFont, displayFontName, displayFontSize, + "FontDisplay", "FontDisplayFamily", + "displayFont"); + displayFont3D = + loadFont < Font3D > (displayFont3D, displayFontName, displayFontSize, + "FontDisplay", "FontDisplayFamily", + "displayFont3D"); + + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] displayFontName = [%s] displayFontSize = %d\n", + __FILE__, __FUNCTION__, __LINE__, + displayFontName.c_str (), displayFontSize); + + //menu fonts + string displayFontNameSmallPrefix = + config.getString ("FontDisplayPrefix"); + string displayFontNameSmallPostfix = + config.getString ("FontDisplayPostfix"); + int displayFontNameSmallSize = + computeFontSize (config.getInt ("FontDisplaySmallBaseSize")); + + if (lang.hasString ("FontDisplayPrefix") == true) + { + displayFontNameSmallPrefix = lang.getString ("FontDisplayPrefix"); + } + if (lang.hasString ("FontDisplayPostfix") == true) + { + displayFontNameSmallPostfix = lang.getString ("FontDisplayPostfix"); + } + if (lang.hasString ("FontDisplaySmallBaseSize") == true) + { + displayFontNameSmallSize = + computeFontSize (strToInt + (lang.getString ("FontDisplaySmallBaseSize"))); + } + string displayFontNameSmall = + displayFontNameSmallPrefix + intToStr (displayFontNameSmallSize) + + displayFontNameSmallPostfix; + + displayFontSmall = + loadFont < Font2D > (displayFontSmall, displayFontNameSmall, + displayFontNameSmallSize, "FontSmallDisplay", + "FontSmallDisplayFamily", "displayFontSmall"); + displayFontSmall3D = + loadFont < Font3D > (displayFontSmall3D, displayFontNameSmall, + displayFontNameSmallSize, "FontSmallDisplay", + "FontSmallDisplayFamily", "displayFontSmall3D"); + + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] displayFontSmallName = [%s] displayFontSmallNameSize = %d\n", + __FILE__, __FUNCTION__, __LINE__, + displayFontNameSmall.c_str (), + displayFontNameSmallSize); + + string menuFontNameNormalPrefix = + config.getString ("FontMenuNormalPrefix"); + string menuFontNameNormalPostfix = + config.getString ("FontMenuNormalPostfix"); + int menuFontNameNormalSize = + computeFontSize (config.getInt ("FontMenuNormalBaseSize")); + if (lang.hasString ("FontMenuNormalPrefix") == true) + { + menuFontNameNormalPrefix = lang.getString ("FontMenuNormalPrefix"); + } + if (lang.hasString ("FontMenuNormalPostfix") == true) + { + menuFontNameNormalPostfix = lang.getString ("FontMenuNormalPostfix"); + } + if (lang.hasString ("FontMenuNormalBaseSize") == true) + { + menuFontNameNormalSize = + computeFontSize (strToInt + (lang.getString ("FontMenuNormalBaseSize"))); + } + string menuFontNameNormal = + menuFontNameNormalPrefix + intToStr (menuFontNameNormalSize) + + menuFontNameNormalPostfix; + + menuFontNormal = + loadFont < Font2D > (menuFontNormal, menuFontNameNormal, + menuFontNameNormalSize, "FontMenuNormal", + "FontMenuNormalFamily", "menuFontNormal"); + menuFontNormal3D = + loadFont < Font3D > (menuFontNormal3D, menuFontNameNormal, + menuFontNameNormalSize, "FontMenuNormal", + "FontMenuNormalFamily", "menuFontNormal3D"); + + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] menuFontNormalName = [%s] menuFontNormalNameSize = %d\n", + __FILE__, __FUNCTION__, __LINE__, + menuFontNameNormal.c_str (), + menuFontNameNormalSize); + + string menuFontNameBigPrefix = config.getString ("FontMenuBigPrefix"); + string menuFontNameBigPostfix = config.getString ("FontMenuBigPostfix"); + int menuFontNameBigSize = + computeFontSize (config.getInt ("FontMenuBigBaseSize")); + + if (lang.hasString ("FontMenuBigPrefix") == true) + { + menuFontNameBigPrefix = lang.getString ("FontMenuBigPrefix"); + } + if (lang.hasString ("FontMenuBigPostfix") == true) + { + menuFontNameBigPostfix = lang.getString ("FontMenuBigPostfix"); + } + if (lang.hasString ("FontMenuBigBaseSize") == true) + { + menuFontNameBigSize = + computeFontSize (strToInt (lang.getString ("FontMenuBigBaseSize"))); + } + string menuFontNameBig = + menuFontNameBigPrefix + intToStr (menuFontNameBigSize) + + menuFontNameBigPostfix; + + menuFontBig = + loadFont < Font2D > (menuFontBig, menuFontNameBig, + menuFontNameBigSize, "FontMenuBig", + "FontMenuBigFamily", "menuFontBig"); + menuFontBig3D = + loadFont < Font3D > (menuFontBig3D, menuFontNameBig, + menuFontNameBigSize, "FontMenuBig", + "FontMenuBigFamily", "menuFontBig3D"); + + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] menuFontNameBig = [%s] menuFontNameBigSize = %d\n", + __FILE__, __FUNCTION__, __LINE__, + menuFontNameBig.c_str (), + menuFontNameBigSize); + + string menuFontNameVeryBigPrefix = + config.getString ("FontMenuBigPrefix"); + string menuFontNameVeryBigPostfix = + config.getString ("FontMenuBigPostfix"); + int menuFontNameVeryBigSize = + computeFontSize (config.getInt ("FontMenuVeryBigBaseSize")); + + if (lang.hasString ("FontMenuBigPrefix") == true) + { + menuFontNameVeryBigPrefix = lang.getString ("FontMenuBigPrefix"); + } + if (lang.hasString ("FontMenuBigPostfix") == true) + { + menuFontNameVeryBigPostfix = lang.getString ("FontMenuBigPostfix"); + } + if (lang.hasString ("FontMenuVeryBigBaseSize") == true) + { + menuFontNameVeryBigSize = + computeFontSize (strToInt + (lang.getString ("FontMenuVeryBigBaseSize"))); + } + string menuFontNameVeryBig = + menuFontNameVeryBigPrefix + intToStr (menuFontNameVeryBigSize) + + menuFontNameVeryBigPostfix; + + menuFontVeryBig = + loadFont < Font2D > (menuFontVeryBig, menuFontNameVeryBig, + menuFontNameVeryBigSize, "FontMenuVeryBig", + "FontMenuVeryBigFamily", "menuFontVeryBig"); + menuFontVeryBig3D = + loadFont < Font3D > (menuFontVeryBig3D, menuFontNameVeryBig, + menuFontNameVeryBigSize, "FontMenuVeryBig", + "FontMenuVeryBigFamily", "menuFontVeryBig3D"); + + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] menuFontNameVeryBig = [%s] menuFontNameVeryBigSize = %d\n", + __FILE__, __FUNCTION__, __LINE__, + menuFontNameVeryBig.c_str (), + menuFontNameVeryBigSize); + + //console font + string consoleFontNamePrefix = config.getString ("FontConsolePrefix"); + string consoleFontNamePostfix = config.getString ("FontConsolePostfix"); + int consoleFontNameSize = + computeFontSize (config.getInt ("FontConsoleBaseSize")); + + if (lang.hasString ("FontConsolePrefix") == true) + { + consoleFontNamePrefix = lang.getString ("FontConsolePrefix"); + } + if (lang.hasString ("FontConsolePostfix") == true) + { + consoleFontNamePostfix = lang.getString ("FontConsolePostfix"); + } + if (lang.hasString ("FontConsoleBaseSize") == true) + { + consoleFontNameSize = + computeFontSize (strToInt (lang.getString ("FontConsoleBaseSize"))); + } + string consoleFontName = + consoleFontNamePrefix + intToStr (consoleFontNameSize) + + consoleFontNamePostfix; + + consoleFont = + loadFont < Font2D > (consoleFont, consoleFontName, + consoleFontNameSize, "FontConsole", + "FontConsoleFamily", "consoleFont"); + consoleFont3D = + loadFont < Font3D > (consoleFont3D, consoleFontName, + consoleFontNameSize, "FontConsole", + "FontConsoleFamily", "consoleFont3D"); + + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] consoleFontName = [%s] consoleFontNameSize = %d\n", + __FILE__, __FUNCTION__, __LINE__, + consoleFontName.c_str (), + consoleFontNameSize); + } + + + template < typename T > T * CoreData::loadFont (Font * menuFont, + string menuFontName, + int menuFontNameSize, + string fontType, + string fontTypeFamily, + string fontUniqueKey) + { + Renderer & renderer = Renderer::getInstance (); + if (menuFont) + { + string fontUniqueId = menuFont->getFontUniqueId (); + renderer.endFont (menuFont, rsGlobal); + menuFont = NULL; + triggerFontChangedCallbacks (fontUniqueId, menuFont); + } + if (Renderer::renderText3DEnabled == false) + { + menuFont = renderer.newFont (rsGlobal); + } + else + { + menuFont = renderer.newFont3D (rsGlobal); + } + if (menuFont) + { + Config & config = Config::getInstance (); + menuFont->setType (menuFontName, config.getString (fontType, ""), + config.getString (fontTypeFamily, "")); + menuFont->setSize (menuFontNameSize); + menuFont->setWidth (Font::wBold); + menuFont->setFontUniqueId (fontUniqueKey); + triggerFontChangedCallbacks (menuFont->getFontUniqueId (), menuFont); + } + return (T *) menuFont; + } + + int CoreData::computeFontSize (int size) + { + int rs = size; + Config & config = Config::getInstance (); + if (Font::forceLegacyFonts == true) + { + int screenH = config.getInt ("ScreenHeight"); + rs = size * screenH / 1024; + } + //FontSizeAdjustment + rs += config.getInt ("FontSizeAdjustment"); + if (Font::forceLegacyFonts == false) + { + rs += Font::baseSize; //basesize only for new font system + } + if (Font::forceLegacyFonts == true) + { + if (rs < 10) + { + rs = 10; + } + } + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] fontsize original %d calculated:%d \n", + __FILE__, __FUNCTION__, __LINE__, size, rs); + return rs; + } + + void CoreData::saveGameSettingsToFile (std::string fileName, + GameSettings * gameSettings, + int advancedIndex) + { + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s] Line: %d\n", __FILE__, + __FUNCTION__, __LINE__); + + Config & config = Config::getInstance (); + string userData = config.getString ("UserData_Root", ""); + if (userData != "") + { + endPathWithSlash (userData); + } + fileName = userData + fileName; + + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] fileName = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + fileName.c_str ()); #if defined(WIN32) && !defined(__MINGW32__) - FILE *fp = _wfopen(utf8_decode(fileName).c_str(), L"w"); - std::ofstream saveGameFile(fp); + FILE *fp = _wfopen (utf8_decode (fileName).c_str (), L"w"); + std::ofstream saveGameFile (fp); #else - std::ofstream saveGameFile; - saveGameFile.open(fileName.c_str(), ios_base::out | ios_base::trunc); + std::ofstream saveGameFile; + saveGameFile.open (fileName.c_str (), ios_base::out | ios_base::trunc); #endif - saveGameFile << "Description=" << gameSettings->getDescription() << std::endl; - saveGameFile << "MapFilterIndex=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getMapFilter()) << std::endl; - saveGameFile << "Map=" << gameSettings->getMap() << std::endl; - saveGameFile << "Tileset=" << gameSettings->getTileset() << std::endl; - saveGameFile << "TechTree=" << gameSettings->getTech() << std::endl; - saveGameFile << "DefaultUnits=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getDefaultUnits()) << std::endl; - saveGameFile << "DefaultResources=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getDefaultResources()) << std::endl; - saveGameFile << "DefaultVictoryConditions=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getDefaultVictoryConditions()) << std::endl; - saveGameFile << "FogOfWar=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getFogOfWar()) << std::endl; - saveGameFile << "AdvancedIndex=" << Shared::PlatformByteOrder::toCommonEndian(advancedIndex) << std::endl; - saveGameFile << "AllowObservers=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getAllowObservers()) << std::endl; - saveGameFile << "FlagTypes1=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getFlagTypes1()) << std::endl; - saveGameFile << "EnableObserverModeAtEndGame=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getEnableObserverModeAtEndGame()) << std::endl; - saveGameFile << "AiAcceptSwitchTeamPercentChance=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getAiAcceptSwitchTeamPercentChance()) << std::endl; - saveGameFile << "FallbackCpuMultiplier=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getFallbackCpuMultiplier()) << std::endl; - saveGameFile << "PathFinderType=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getPathFinderType()) << std::endl; - saveGameFile << "EnableServerControlledAI=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getEnableServerControlledAI()) << std::endl; - saveGameFile << "NetworkFramePeriod=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getNetworkFramePeriod()) << std::endl; - saveGameFile << "NetworkPauseGameForLaggedClients=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getNetworkPauseGameForLaggedClients()) << std::endl; + saveGameFile << "Description=" << gameSettings-> + getDescription () << std::endl; + saveGameFile << "MapFilterIndex=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getMapFilter ()) << std::endl; + saveGameFile << "Map=" << gameSettings->getMap () << std::endl; + saveGameFile << "Tileset=" << gameSettings->getTileset () << std::endl; + saveGameFile << "TechTree=" << gameSettings->getTech () << std::endl; + saveGameFile << "DefaultUnits=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getDefaultUnits ()) << std::endl; + saveGameFile << "DefaultResources=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getDefaultResources ()) << std::endl; + saveGameFile << "DefaultVictoryConditions=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getDefaultVictoryConditions ()) << + std::endl; + saveGameFile << "FogOfWar=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getFogOfWar ()) << std::endl; + saveGameFile << "AdvancedIndex=" << Shared::PlatformByteOrder:: + toCommonEndian (advancedIndex) << std::endl; + saveGameFile << "AllowObservers=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getAllowObservers ()) << std::endl; + saveGameFile << "FlagTypes1=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getFlagTypes1 ()) << std::endl; + saveGameFile << "EnableObserverModeAtEndGame=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getEnableObserverModeAtEndGame ()) + << std::endl; + saveGameFile << "AiAcceptSwitchTeamPercentChance=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getAiAcceptSwitchTeamPercentChance + ()) << std::endl; + saveGameFile << "FallbackCpuMultiplier=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings-> + getFallbackCpuMultiplier ()) << std::endl; + saveGameFile << "PathFinderType=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getPathFinderType ()) << std::endl; + saveGameFile << "EnableServerControlledAI=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getEnableServerControlledAI ()) << + std::endl; + saveGameFile << "NetworkFramePeriod=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getNetworkFramePeriod ()) << std::endl; + saveGameFile << "NetworkPauseGameForLaggedClients=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getNetworkPauseGameForLaggedClients + ()) << std::endl; - saveGameFile << "FactionThisFactionIndex=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getThisFactionIndex()) << std::endl; - saveGameFile << "FactionCount=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getFactionCount()) << std::endl; + saveGameFile << "FactionThisFactionIndex=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getThisFactionIndex ()) << std:: + endl; + saveGameFile << "FactionCount=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getFactionCount ()) << std::endl; - saveGameFile << "NetworkAllowNativeLanguageTechtree=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getNetworkAllowNativeLanguageTechtree()) << std::endl; + saveGameFile << "NetworkAllowNativeLanguageTechtree=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getNetworkAllowNativeLanguageTechtree + ()) << std::endl; - for(int i = 0; i < GameConstants::maxPlayers; ++i) { - int slotIndex = gameSettings->getStartLocationIndex(i); + for (int i = 0; i < GameConstants::maxPlayers; ++i) + { + int slotIndex = gameSettings->getStartLocationIndex (i); - saveGameFile << "FactionControlForIndex" << Shared::PlatformByteOrder::toCommonEndian(slotIndex) << "=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getFactionControl(i)) << std::endl; - saveGameFile << "ResourceMultiplierIndex" << Shared::PlatformByteOrder::toCommonEndian(slotIndex) << "=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getResourceMultiplierIndex(i)) << std::endl; - saveGameFile << "FactionTeamForIndex" << Shared::PlatformByteOrder::toCommonEndian(slotIndex) << "=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getTeam(i)) << std::endl; - saveGameFile << "FactionStartLocationForIndex" << Shared::PlatformByteOrder::toCommonEndian(slotIndex) << "=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getStartLocationIndex(i)) << std::endl; - saveGameFile << "FactionTypeNameForIndex" << Shared::PlatformByteOrder::toCommonEndian(slotIndex) << "=" << gameSettings->getFactionTypeName(i) << std::endl; - saveGameFile << "FactionPlayerNameForIndex" << Shared::PlatformByteOrder::toCommonEndian(slotIndex) << "=" << gameSettings->getNetworkPlayerName(i) << std::endl; + saveGameFile << "FactionControlForIndex" << Shared:: + PlatformByteOrder::toCommonEndian (slotIndex) << "=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getFactionControl (i)) << std:: + endl; + saveGameFile << "ResourceMultiplierIndex" << Shared:: + PlatformByteOrder::toCommonEndian (slotIndex) << "=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getResourceMultiplierIndex (i)) + << std::endl; + saveGameFile << "FactionTeamForIndex" << Shared::PlatformByteOrder:: + toCommonEndian (slotIndex) << "=" << Shared::PlatformByteOrder:: + toCommonEndian (gameSettings->getTeam (i)) << std::endl; + saveGameFile << "FactionStartLocationForIndex" << Shared:: + PlatformByteOrder::toCommonEndian (slotIndex) << "=" << Shared:: + PlatformByteOrder::toCommonEndian (gameSettings-> + getStartLocationIndex (i)) << + std::endl; + saveGameFile << "FactionTypeNameForIndex" << Shared:: + PlatformByteOrder:: + toCommonEndian (slotIndex) << "=" << gameSettings-> + getFactionTypeName (i) << std::endl; + saveGameFile << "FactionPlayerNameForIndex" << Shared:: + PlatformByteOrder:: + toCommonEndian (slotIndex) << "=" << gameSettings-> + getNetworkPlayerName (i) << std::endl; - saveGameFile << "FactionPlayerUUIDForIndex" << Shared::PlatformByteOrder::toCommonEndian(slotIndex) << "=" << gameSettings->getNetworkPlayerUUID(i) << std::endl; - } + saveGameFile << "FactionPlayerUUIDForIndex" << Shared:: + PlatformByteOrder:: + toCommonEndian (slotIndex) << "=" << gameSettings-> + getNetworkPlayerUUID (i) << std::endl; + } #if defined(WIN32) && !defined(__MINGW32__) - if(fp) fclose(fp); + if (fp) + fclose (fp); #endif - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); -} - -bool CoreData::loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - bool fileWasFound = false; - Config &config = Config::getInstance(); - string userData = config.getString("UserData_Root",""); - if(userData != "") { - endPathWithSlash(userData); - } - if(fileExists(userData + fileName) == true) { - fileName = userData + fileName; - fileWasFound = true; + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s] Line: %d\n", __FILE__, + __FUNCTION__, __LINE__); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str()); + bool CoreData::loadGameSettingsFromFile (std::string fileName, + GameSettings * gameSettings) + { + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s] Line: %d\n", __FILE__, + __FUNCTION__, __LINE__); - if(fileExists(fileName) == false) { - return false; - } + bool fileWasFound = false; + Config & config = Config::getInstance (); + string userData = config.getString ("UserData_Root", ""); + if (userData != "") + { + endPathWithSlash (userData); + } + if (fileExists (userData + fileName) == true) + { + fileName = userData + fileName; + fileWasFound = true; + } - fileWasFound = true; - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str()); + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] fileName = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + fileName.c_str ()); - Properties properties; - properties.load(fileName); + if (fileExists (fileName) == false) + { + return false; + } - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str()); + fileWasFound = true; + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] fileName = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + fileName.c_str ()); - gameSettings->setMapFilter(properties.getInt("MapFilterIndex","0")); - gameSettings->setDescription(properties.getString("Description")); - gameSettings->setMap(properties.getString("Map")); - gameSettings->setTileset(properties.getString("Tileset")); - gameSettings->setTech(properties.getString("TechTree")); - gameSettings->setDefaultUnits(properties.getBool("DefaultUnits")); - gameSettings->setDefaultResources(properties.getBool("DefaultResources")); - gameSettings->setDefaultVictoryConditions(properties.getBool("DefaultVictoryConditions")); - gameSettings->setFogOfWar(properties.getBool("FogOfWar")); - //listBoxAdvanced.setSelectedItemIndex(properties.getInt("AdvancedIndex","0")); + Properties properties; + properties.load (fileName); - gameSettings->setAllowObservers(properties.getBool("AllowObservers","false")); - gameSettings->setFlagTypes1(properties.getInt("FlagTypes1","0")); + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] fileName = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + fileName.c_str ()); - uint32 valueFlags1 = gameSettings->getFlagTypes1(); - if(Config::getInstance().getBool("EnableNetworkGameSynchChecks","false") == true) { - //printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n"); + gameSettings->setMapFilter (properties.getInt ("MapFilterIndex", "0")); + gameSettings->setDescription (properties.getString ("Description")); + gameSettings->setMap (properties.getString ("Map")); + gameSettings->setTileset (properties.getString ("Tileset")); + gameSettings->setTech (properties.getString ("TechTree")); + gameSettings->setDefaultUnits (properties.getBool ("DefaultUnits")); + gameSettings->setDefaultResources (properties. + getBool ("DefaultResources")); + gameSettings->setDefaultVictoryConditions (properties. + getBool + ("DefaultVictoryConditions")); + gameSettings->setFogOfWar (properties.getBool ("FogOfWar")); + //listBoxAdvanced.setSelectedItemIndex(properties.getInt("AdvancedIndex","0")); + + gameSettings->setAllowObservers (properties. + getBool ("AllowObservers", "false")); + gameSettings->setFlagTypes1 (properties.getInt ("FlagTypes1", "0")); + + uint32 valueFlags1 = gameSettings->getFlagTypes1 (); + if (Config::getInstance (). + getBool ("EnableNetworkGameSynchChecks", "false") == true) + { + //printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n"); valueFlags1 |= ft1_network_synch_checks_verbose; - gameSettings->setFlagTypes1(valueFlags1); + gameSettings->setFlagTypes1 (valueFlags1); - } - else { + } + else + { valueFlags1 &= ~ft1_network_synch_checks_verbose; - gameSettings->setFlagTypes1(valueFlags1); + gameSettings->setFlagTypes1 (valueFlags1); - } - if(Config::getInstance().getBool("EnableNetworkGameSynchMonitor","false") == true) { - //printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n"); + } + if (Config::getInstance (). + getBool ("EnableNetworkGameSynchMonitor", "false") == true) + { + //printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n"); valueFlags1 |= ft1_network_synch_checks; - gameSettings->setFlagTypes1(valueFlags1); + gameSettings->setFlagTypes1 (valueFlags1); - } - else { + } + else + { valueFlags1 &= ~ft1_network_synch_checks; - gameSettings->setFlagTypes1(valueFlags1); + gameSettings->setFlagTypes1 (valueFlags1); - } + } - gameSettings->setEnableObserverModeAtEndGame(properties.getBool("EnableObserverModeAtEndGame")); - gameSettings->setAiAcceptSwitchTeamPercentChance(properties.getInt("AiAcceptSwitchTeamPercentChance","30")); - gameSettings->setFallbackCpuMultiplier(properties.getInt("FallbackCpuMultiplier","5")); + gameSettings->setEnableObserverModeAtEndGame (properties. + getBool + ("EnableObserverModeAtEndGame")); + gameSettings->setAiAcceptSwitchTeamPercentChance (properties. + getInt + ("AiAcceptSwitchTeamPercentChance", + "30")); + gameSettings->setFallbackCpuMultiplier (properties. + getInt ("FallbackCpuMultiplier", + "5")); - gameSettings->setPathFinderType(static_cast(properties.getInt("PathFinderType",intToStr(pfBasic).c_str()))); - gameSettings->setEnableServerControlledAI(properties.getBool("EnableServerControlledAI","true")); - gameSettings->setNetworkFramePeriod(properties.getInt("NetworkFramePeriod",intToStr(GameConstants::networkFramePeriod).c_str())); - gameSettings->setNetworkPauseGameForLaggedClients(properties.getBool("NetworkPauseGameForLaggedClients","false")); + gameSettings->setPathFinderType (static_cast < PathFinderType > + (properties. + getInt ("PathFinderType", + intToStr (pfBasic). + c_str ()))); + gameSettings->setEnableServerControlledAI (properties. + getBool + ("EnableServerControlledAI", + "true")); + gameSettings->setNetworkFramePeriod (properties. + getInt ("NetworkFramePeriod", + intToStr (GameConstants:: + networkFramePeriod). + c_str ())); + gameSettings->setNetworkPauseGameForLaggedClients (properties. + getBool + ("NetworkPauseGameForLaggedClients", + "false")); - gameSettings->setThisFactionIndex(properties.getInt("FactionThisFactionIndex")); - gameSettings->setFactionCount(properties.getInt("FactionCount")); + gameSettings->setThisFactionIndex (properties. + getInt ("FactionThisFactionIndex")); + gameSettings->setFactionCount (properties.getInt ("FactionCount")); - if(properties.hasString("NetworkAllowNativeLanguageTechtree") == true) { - gameSettings->setNetworkAllowNativeLanguageTechtree(properties.getBool("NetworkAllowNativeLanguageTechtree")); - } - else { - gameSettings->setNetworkAllowNativeLanguageTechtree(false); - } + if (properties.hasString ("NetworkAllowNativeLanguageTechtree") == true) + { + gameSettings->setNetworkAllowNativeLanguageTechtree (properties. + getBool + ("NetworkAllowNativeLanguageTechtree")); + } + else + { + gameSettings->setNetworkAllowNativeLanguageTechtree (false); + } - for(int i = 0; i < GameConstants::maxPlayers; ++i) { - gameSettings->setFactionControl(i,(ControlType)properties.getInt(string("FactionControlForIndex") + intToStr(i),intToStr(ctClosed).c_str()) ); + for (int i = 0; i < GameConstants::maxPlayers; ++i) + { + gameSettings->setFactionControl (i, + (ControlType) properties. + getInt (string + ("FactionControlForIndex") + + intToStr (i), + intToStr (ctClosed). + c_str ())); - if(gameSettings->getFactionControl(i) == ctNetworkUnassigned) { - gameSettings->setFactionControl(i,ctNetwork); - } + if (gameSettings->getFactionControl (i) == ctNetworkUnassigned) + { + gameSettings->setFactionControl (i, ctNetwork); + } - gameSettings->setResourceMultiplierIndex(i,properties.getInt(string("ResourceMultiplierIndex") + intToStr(i),"5")); - gameSettings->setTeam(i,properties.getInt(string("FactionTeamForIndex") + intToStr(i),"0") ); - gameSettings->setStartLocationIndex(i,properties.getInt(string("FactionStartLocationForIndex") + intToStr(i),intToStr(i).c_str()) ); - gameSettings->setFactionTypeName(i,properties.getString(string("FactionTypeNameForIndex") + intToStr(i),"?") ); + gameSettings->setResourceMultiplierIndex (i, + properties. + getInt (string + ("ResourceMultiplierIndex") + + intToStr (i), + "5")); + gameSettings->setTeam (i, + properties. + getInt (string ("FactionTeamForIndex") + + intToStr (i), "0")); + gameSettings->setStartLocationIndex (i, + properties. + getInt (string + ("FactionStartLocationForIndex") + + intToStr (i), + intToStr (i).c_str ())); + gameSettings->setFactionTypeName (i, + properties. + getString (string + ("FactionTypeNameForIndex") + + intToStr (i), "?")); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, factionTypeName [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,gameSettings->getFactionTypeName(i).c_str()); + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] i = %d, factionTypeName [%s]\n", + __FILE__, __FUNCTION__, __LINE__, i, + gameSettings->getFactionTypeName (i). + c_str ()); - if(gameSettings->getFactionControl(i) == ctHuman) { - gameSettings->setNetworkPlayerName(i,properties.getString(string("FactionPlayerNameForIndex") + intToStr(i),"") ); - } - else { - gameSettings->setNetworkPlayerName(i,""); - } + if (gameSettings->getFactionControl (i) == ctHuman) + { + gameSettings->setNetworkPlayerName (i, + properties. + getString (string + ("FactionPlayerNameForIndex") + + intToStr (i), "")); + } + else + { + gameSettings->setNetworkPlayerName (i, ""); + } - gameSettings->setNetworkPlayerUUID(i,properties.getString(string("FactionPlayerUUIDForIndex") + intToStr(i),"") ); - } + gameSettings->setNetworkPlayerUUID (i, + properties. + getString (string + ("FactionPlayerUUIDForIndex") + + intToStr (i), "")); + } - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s] Line: %d\n", __FILE__, + __FUNCTION__, __LINE__); - return fileWasFound; -} + return fileWasFound; + } // ================== PRIVATE ======================== -}}//end namespace + } +} //end namespace diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 8baf9d47c..3dbd804a5 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -19,263 +19,342 @@ // along with this program. If not, see . #ifndef _GLEST_GAME_COREDATA_H_ -#define _GLEST_GAME_COREDATA_H_ +# define _GLEST_GAME_COREDATA_H_ -#ifdef WIN32 - #include - #include -#endif +# ifdef WIN32 +# include +# include +# endif -#include -#include "sound.h" -#include "font.h" -#include "texture.h" -#include "sound_container.h" -#include "leak_dumper.h" +# include +# include "sound.h" +# include "font.h" +# include "texture.h" +# include "sound_container.h" +# include "leak_dumper.h" -namespace Glest{ namespace Game{ +namespace Glest +{ + namespace Game + { -using ::Shared::Graphics::Texture2D; -using ::Shared::Graphics::Texture3D; -using ::Shared::Graphics::Font; -using ::Shared::Graphics::Font2D; -using ::Shared::Graphics::Font3D; -using ::Shared::Graphics::FontChangedCallbackInterface; -using ::Shared::Sound::StrSound; -using ::Shared::Sound::StaticSound; + using::Shared::Graphics::Texture2D; + using::Shared::Graphics::Texture3D; + using::Shared::Graphics::Font; + using::Shared::Graphics::Font2D; + using::Shared::Graphics::Font3D; + using::Shared::Graphics::FontChangedCallbackInterface; + using::Shared::Sound::StrSound; + using::Shared::Sound::StaticSound; // ===================================================== -// class CoreData +// class CoreData // /// Data shared among all the ProgramStates // ===================================================== -class GameSettings; + class GameSettings; -class CoreData { -private: - std::map itemLoadAttempted; + class CoreData + { + private: + std::map < int, bool > itemLoadAttempted; - StrSound introMusic; - StrSound menuMusic; - StaticSound clickSoundA; - StaticSound clickSoundB; - StaticSound clickSoundC; - StaticSound attentionSound; - StaticSound highlightSound; - StaticSound markerSound; - SoundContainer waterSounds; + StrSound introMusic; + StrSound menuMusic; + StaticSound clickSoundA; + StaticSound clickSoundB; + StaticSound clickSoundC; + StaticSound attentionSound; + StaticSound highlightSound; + StaticSound markerSound; + SoundContainer waterSounds; - Texture2D *logoTexture; - std::vector logoTextureList; - Texture2D *backgroundTexture; - Texture2D *fireTexture; - Texture2D *teamColorTexture; - Texture2D *snowTexture; - Texture2D *waterSplashTexture; - Texture2D *customTexture; - Texture2D *buttonSmallTexture; - Texture2D *buttonBigTexture; - Texture2D *horizontalLineTexture; - Texture2D *verticalLineTexture; - Texture2D *checkBoxTexture; - Texture2D *checkedCheckBoxTexture; - Texture2D *gameWinnerTexture; - Texture2D *notOnServerTexture; - Texture2D *onServerDifferentTexture; - Texture2D *onServerTexture; - Texture2D *onServerInstalledTexture; - Texture2D *statusReadyTexture; - Texture2D *statusNotReadyTexture; - Texture2D *statusBRBTexture; + Texture2D *logoTexture; + std::vector < Texture2D * >logoTextureList; + Texture2D *backgroundTexture; + Texture2D *fireTexture; + Texture2D *teamColorTexture; + Texture2D *snowTexture; + Texture2D *waterSplashTexture; + Texture2D *customTexture; + Texture2D *buttonSmallTexture; + Texture2D *buttonBigTexture; + Texture2D *horizontalLineTexture; + Texture2D *verticalLineTexture; + Texture2D *checkBoxTexture; + Texture2D *checkedCheckBoxTexture; + Texture2D *gameWinnerTexture; + Texture2D *notOnServerTexture; + Texture2D *onServerDifferentTexture; + Texture2D *onServerTexture; + Texture2D *onServerInstalledTexture; + Texture2D *statusReadyTexture; + Texture2D *statusNotReadyTexture; + Texture2D *statusBRBTexture; - Texture2D *healthbarTexture; - Texture2D *healthbarBackgroundTexture; + Texture2D *healthbarTexture; + Texture2D *healthbarBackgroundTexture; - std::vector miscTextureList; + std::vector < Texture2D * >miscTextureList; - Font2D *displayFont; - Font2D *menuFontNormal; - Font2D *displayFontSmall; - Font2D *menuFontBig; - Font2D *menuFontVeryBig; - Font2D *consoleFont; + Font2D *displayFont; + Font2D *menuFontNormal; + Font2D *displayFontSmall; + Font2D *menuFontBig; + Font2D *menuFontVeryBig; + Font2D *consoleFont; - Font3D *displayFont3D; - Font3D *menuFontNormal3D; - Font3D *displayFontSmall3D; - Font3D *menuFontBig3D; - Font3D *menuFontVeryBig3D; - Font3D *consoleFont3D; + Font3D *displayFont3D; + Font3D *menuFontNormal3D; + Font3D *displayFontSmall3D; + Font3D *menuFontBig3D; + Font3D *menuFontVeryBig3D; + Font3D *consoleFont3D; - string introVideoFilename; - string introVideoFilenameFallback; + string introVideoFilename; + string introVideoFilenameFallback; - string mainMenuVideoFilename; - string mainMenuVideoFilenameFallback; + string mainMenuVideoFilename; + string mainMenuVideoFilenameFallback; - string battleEndWinVideoFilename; - string battleEndWinVideoFilenameFallback; - string battleEndWinMusicFilename; + string battleEndWinVideoFilename; + string battleEndWinVideoFilenameFallback; + string battleEndWinMusicFilename; - string battleEndLoseVideoFilename; - string battleEndLoseVideoFilenameFallback; - string battleEndLoseMusicFilename; + string battleEndLoseVideoFilename; + string battleEndLoseVideoFilenameFallback; + string battleEndLoseMusicFilename; - std::map > registeredFontChangedCallbacks; -public: + std::map < std::string, + std::vector < + FontChangedCallbackInterface * >>registeredFontChangedCallbacks; + public: - enum TextureSystemType { - tsyst_NONE, - tsyst_logoTexture, - tsyst_backgroundTexture, - tsyst_fireTexture, - tsyst_teamColorTexture, - tsyst_snowTexture, - tsyst_waterSplashTexture, - tsyst_customTexture, - tsyst_buttonSmallTexture, - tsyst_buttonBigTexture, - tsyst_horizontalLineTexture, - tsyst_verticalLineTexture, - tsyst_checkBoxTexture, - tsyst_checkedCheckBoxTexture, - tsyst_gameWinnerTexture, - tsyst_notOnServerTexture, - tsyst_onServerDifferentTexture, - tsyst_onServerTexture, - tsyst_onServerInstalledTexture, - tsyst_statusReadyTexture, - tsyst_statusNotReadyTexture, - tsyst_statusBRBTexture, - tsyst_healthbarTexture, - tsyst_healthbarBackgroundTexture, + enum TextureSystemType + { + tsyst_NONE, + tsyst_logoTexture, + tsyst_backgroundTexture, + tsyst_fireTexture, + tsyst_teamColorTexture, + tsyst_snowTexture, + tsyst_waterSplashTexture, + tsyst_customTexture, + tsyst_buttonSmallTexture, + tsyst_buttonBigTexture, + tsyst_horizontalLineTexture, + tsyst_verticalLineTexture, + tsyst_checkBoxTexture, + tsyst_checkedCheckBoxTexture, + tsyst_gameWinnerTexture, + tsyst_notOnServerTexture, + tsyst_onServerDifferentTexture, + tsyst_onServerTexture, + tsyst_onServerInstalledTexture, + tsyst_statusReadyTexture, + tsyst_statusNotReadyTexture, + tsyst_statusBRBTexture, + tsyst_healthbarTexture, + tsyst_healthbarBackgroundTexture, - tsyst_COUNT - }; + tsyst_COUNT + }; -public: + public: - ~CoreData(); - static CoreData &getInstance(); + ~CoreData (); + static CoreData & getInstance (); - void load(); - void cleanup(); - void loadFonts(); + void load (); + void cleanup (); + void loadFonts (); - // Textures - Texture2D *getTextureBySystemId(TextureSystemType type); + // Textures + Texture2D *getTextureBySystemId (TextureSystemType type); - Texture2D *getBackgroundTexture(); - Texture2D *getFireTexture(); - Texture2D *getTeamColorTexture(); - Texture2D *getSnowTexture(); - Texture2D *getLogoTexture(); - Texture2D *getWaterSplashTexture(); - Texture2D *getCustomTexture(); - Texture2D *getButtonSmallTexture(); - Texture2D *getButtonBigTexture(); - Texture2D *getHorizontalLineTexture(); - Texture2D *getVerticalLineTexture(); - Texture2D *getCheckBoxTexture(); - Texture2D *getCheckedCheckBoxTexture(); - Texture2D *getNotOnServerTexture(); - Texture2D *getOnServerDifferentTexture(); - Texture2D *getOnServerTexture(); - Texture2D *getOnServerInstalledTexture(); - Texture2D *getStatusReadyTexture(); - Texture2D *getStatusNotReadyTexture(); - Texture2D *getStatusBRBTexture(); - Texture2D *getGameWinnerTexture(); + Texture2D *getBackgroundTexture (); + Texture2D *getFireTexture (); + Texture2D *getTeamColorTexture (); + Texture2D *getSnowTexture (); + Texture2D *getLogoTexture (); + Texture2D *getWaterSplashTexture (); + Texture2D *getCustomTexture (); + Texture2D *getButtonSmallTexture (); + Texture2D *getButtonBigTexture (); + Texture2D *getHorizontalLineTexture (); + Texture2D *getVerticalLineTexture (); + Texture2D *getCheckBoxTexture (); + Texture2D *getCheckedCheckBoxTexture (); + Texture2D *getNotOnServerTexture (); + Texture2D *getOnServerDifferentTexture (); + Texture2D *getOnServerTexture (); + Texture2D *getOnServerInstalledTexture (); + Texture2D *getStatusReadyTexture (); + Texture2D *getStatusNotReadyTexture (); + Texture2D *getStatusBRBTexture (); + Texture2D *getGameWinnerTexture (); - Texture2D *getHealthbarTexture(); - Texture2D *getHealthbarBackgroundTexture(); + Texture2D *getHealthbarTexture (); + Texture2D *getHealthbarBackgroundTexture (); - size_t getLogoTextureExtraCount(); - Texture2D *getLogoTextureExtra(int idx); + size_t getLogoTextureExtraCount (); + Texture2D *getLogoTextureExtra (int idx); - std::vector & getMiscTextureList(); + std::vector < Texture2D * >&getMiscTextureList (); - // Sounds and Music - StrSound *getIntroMusic(); - StrSound *getMenuMusic(); + // Sounds and Music + StrSound *getIntroMusic (); + StrSound *getMenuMusic (); - StaticSound *getClickSoundA(); - StaticSound *getClickSoundB(); - StaticSound *getClickSoundC(); - StaticSound *getAttentionSound(); - StaticSound *getHighlightSound(); - StaticSound *getMarkerSound(); - StaticSound *getWaterSound(); + StaticSound *getClickSoundA (); + StaticSound *getClickSoundB (); + StaticSound *getClickSoundC (); + StaticSound *getAttentionSound (); + StaticSound *getHighlightSound (); + StaticSound *getMarkerSound (); + StaticSound *getWaterSound (); - // Fonts - Font2D *getDisplayFont() const {return displayFont;} - Font2D *getDisplayFontSmall() const {return displayFontSmall;} - Font2D *getMenuFontNormal() const {return menuFontNormal;} - Font2D *getMenuFontBig() const {return menuFontBig;} - Font2D *getMenuFontVeryBig() const {return menuFontVeryBig;} - Font2D *getConsoleFont() const {return consoleFont;} + // Fonts + Font2D *getDisplayFont () const + { + return displayFont; + } + Font2D *getDisplayFontSmall () const + { + return displayFontSmall; + } + Font2D *getMenuFontNormal () const + { + return menuFontNormal; + } + Font2D *getMenuFontBig () const + { + return menuFontBig; + } + Font2D *getMenuFontVeryBig () const + { + return menuFontVeryBig; + } + Font2D *getConsoleFont () const + { + return consoleFont; + } - Font3D *getDisplayFont3D() const {return displayFont3D;} - Font3D *getDisplayFontSmall3D() const {return displayFontSmall3D;} - Font3D *getMenuFontNormal3D() const {return menuFontNormal3D;} - Font3D *getMenuFontBig3D() const {return menuFontBig3D;} - Font3D *getMenuFontVeryBig3D() const {return menuFontVeryBig3D;} - Font3D *getConsoleFont3D() const {return consoleFont3D;} + Font3D *getDisplayFont3D () const + { + return displayFont3D; + } + Font3D *getDisplayFontSmall3D () const + { + return displayFontSmall3D; + } + Font3D *getMenuFontNormal3D () const + { + return menuFontNormal3D; + } + Font3D *getMenuFontBig3D () const + { + return menuFontBig3D; + } + Font3D *getMenuFontVeryBig3D () const + { + return menuFontVeryBig3D; + } + Font3D *getConsoleFont3D () const + { + return consoleFont3D; + } - // Helper functions - string getMainMenuVideoFilename() const { return mainMenuVideoFilename; } - bool hasMainMenuVideoFilename() const; - string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; } - bool hasMainMenuVideoFilenameFallback() const; + // Helper functions + string getMainMenuVideoFilename () const + { + return mainMenuVideoFilename; + } + bool hasMainMenuVideoFilename () const; + string getMainMenuVideoFilenameFallback () const + { + return mainMenuVideoFilenameFallback; + } + bool hasMainMenuVideoFilenameFallback () const; - string getIntroVideoFilename() const { return introVideoFilename; } - bool hasIntroVideoFilename() const; - string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; } - bool hasIntroVideoFilenameFallback() const; + string getIntroVideoFilename () const + { + return introVideoFilename; + } + bool hasIntroVideoFilename () const; + string getIntroVideoFilenameFallback () const + { + return introVideoFilenameFallback; + } + bool hasIntroVideoFilenameFallback () const; - string getBattleEndVideoFilename(bool won) const { return won == true ? battleEndWinVideoFilename : battleEndLoseVideoFilename; } - //bool hasBattleEndVideoFilename(bool won) const; - string getBattleEndVideoFilenameFallback(bool won) const { return won == true ? battleEndWinVideoFilenameFallback : battleEndLoseVideoFilenameFallback; } - bool hasBattleEndVideoFilenameFallback(bool won) const; + string getBattleEndVideoFilename (bool won) const + { + return won == + true ? battleEndWinVideoFilename : battleEndLoseVideoFilename; + } + //bool hasBattleEndVideoFilename(bool won) const; + string getBattleEndVideoFilenameFallback (bool won) const + { + return won == + true ? battleEndWinVideoFilenameFallback : + battleEndLoseVideoFilenameFallback; + } + bool hasBattleEndVideoFilenameFallback (bool won) const; - string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; } + string getBattleEndMusicFilename (bool won) const + { + return won == + true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; + } - void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0); - bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings); + void saveGameSettingsToFile (std::string fileName, + GameSettings * gameSettings, + int advancedIndex = 0); + bool loadGameSettingsFromFile (std::string fileName, + GameSettings * gameSettings); - void registerFontChangedCallback(std::string entityName, FontChangedCallbackInterface *cb); - void unRegisterFontChangedCallback(std::string entityName); -private: + void registerFontChangedCallback (std::string entityName, + FontChangedCallbackInterface * cb); + void unRegisterFontChangedCallback (std::string entityName); + private: - CoreData(); + CoreData (); - int computeFontSize(int size); - void cleanupTexture(Texture2D **texture); - void loadTextures(string data_path); - void loadSounds(string data_path); - void loadMusic(string data_path); - void loadIntroMedia(string data_path); - void loadMainMenuMedia(string data_path); - void loadBattleEndMedia(string data_path); + int computeFontSize (int size); + void cleanupTexture (Texture2D ** texture); + void loadTextures (string data_path); + void loadSounds (string data_path); + void loadMusic (string data_path); + void loadIntroMedia (string data_path); + void loadMainMenuMedia (string data_path); + void loadBattleEndMedia (string data_path); - string getDataPath(); - void loadTextureIfRequired(Texture2D **tex,string data_path, - string uniqueFilePath, int texSystemId, bool setMipMap, - bool setAlpha, bool loadUniqueFilePath, - bool compressionDisabled = false); + string getDataPath (); + void loadTextureIfRequired (Texture2D ** tex, string data_path, + string uniqueFilePath, int texSystemId, + bool setMipMap, bool setAlpha, + bool loadUniqueFilePath, + bool compressionDisabled = false); - void loadLogoTextureExtraIfRequired(); - void loadMiscTextureListIfRequired(); + void loadLogoTextureExtraIfRequired (); + void loadMiscTextureListIfRequired (); - void loadWaterSoundsIfRequired(); - void loadMusicIfRequired(); + void loadWaterSoundsIfRequired (); + void loadMusicIfRequired (); - void triggerFontChangedCallbacks(std::string fontUniqueId, Font *font); - template T * loadFont(Font *menuFontNormal, string menuFontNameNormal, int menuFontNameNormalSize, string fontType, string fontTypeFamily, string fontUniqueKey); -}; + void triggerFontChangedCallbacks (std::string fontUniqueId, + Font * font); + template < typename T > T * loadFont (Font * menuFontNormal, + string menuFontNameNormal, + int menuFontNameNormalSize, + string fontType, + string fontTypeFamily, + string fontUniqueKey); + }; -}} //end namespace +}} //end namespace #endif diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index 3ef82adcf..c90dc4dec 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -1,12 +1,12 @@ // ============================================================== -// This file is part of Glest (www.glest.org) +// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Martiño Figueroa // -// You can redistribute this code and/or modify it under -// the terms of the GNU General Public License as published -// by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version // ============================================================== #include "lang.h" @@ -32,719 +32,1048 @@ using namespace std; using namespace Shared::Util; using namespace Shared::Platform; -namespace Glest{ namespace Game{ +namespace Glest +{ + namespace Game + { -const char *DEFAULT_LANGUAGE = "english"; + const char *DEFAULT_LANGUAGE = "english"; // ===================================================== -// class Lang +// class Lang // ===================================================== -Lang::Lang() { - language = ""; - is_utf8_language = false; - allowNativeLanguageTechtree = true; - techNameLoaded = ""; -} - -Lang &Lang::getInstance() { - static Lang lang; - return lang; -} - -string Lang::getDefaultLanguage() const { - return DEFAULT_LANGUAGE; -} - -void Lang::loadGameStrings(string uselanguage, bool loadFonts, - bool fallbackToDefault) { - if(uselanguage.length() == 2 || (uselanguage.length() == 5 && uselanguage[2] == '-')) { - uselanguage = getLanguageFile(uselanguage); - } - bool languageChanged = (uselanguage != this->language); - this->language= uselanguage; - loadGameStringProperties(uselanguage, gameStringsAllLanguages[this->language], true, fallbackToDefault); - - if(languageChanged == true) { - Font::resetToDefaults(); - Lang &lang = Lang::getInstance(); - if( lang.hasString("FONT_BASE_SIZE")) { - Font::baseSize = strToInt(lang.getString("FONT_BASE_SIZE")); - } - - if( lang.hasString("FONT_SCALE_SIZE")) { - Font::scaleFontValue = strToFloat(lang.getString("FONT_SCALE_SIZE")); - } - if( lang.hasString("FONT_SCALE_CENTERH_FACTOR")) { - Font::scaleFontValueCenterHFactor = strToFloat(lang.getString("FONT_SCALE_CENTERH_FACTOR")); - } - - if( lang.hasString("FONT_CHARCOUNT")) { - // 256 for English - // 30000 for Chinese - Font::charCount = strToInt(lang.getString("FONT_CHARCOUNT")); - } - if( lang.hasString("FONT_TYPENAME")) { - Font::fontTypeName = lang.getString("FONT_TYPENAME"); - } - if( lang.hasString("FONT_CHARSET")) { - // Example values: - // DEFAULT_CHARSET (English) = 1 - // GB2312_CHARSET (Chinese) = 134 - Shared::Platform::PlatformContextGl::charSet = strToInt(lang.getString("FONT_CHARSET")); - } - if( lang.hasString("FONT_MULTIBYTE")) { - Font::fontIsMultibyte = strToBool(lang.getString("FONT_MULTIBYTE")); - } - - if( lang.hasString("FONT_RIGHTTOLEFT")) { - Font::fontIsRightToLeft = strToBool(lang.getString("FONT_RIGHTTOLEFT")); - } - - if( lang.hasString("FONT_RIGHTTOLEFT_MIXED_SUPPORT")) { - Font::fontSupportMixedRightToLeft = strToBool(lang.getString("FONT_RIGHTTOLEFT_MIXED_SUPPORT")); - } - - if( lang.hasString("MEGAGLEST_FONT")) { - //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese - #if defined(WIN32) - string newEnvValue = "MEGAGLEST_FONT=" + lang.getString("MEGAGLEST_FONT"); - _putenv(newEnvValue.c_str()); - #else - setenv("MEGAGLEST_FONT",lang.getString("MEGAGLEST_FONT").c_str(),0); - #endif - } - - if( lang.hasString("MEGAGLEST_FONT_FAMILY")) { - #if defined(WIN32) - string newEnvValue = "MEGAGLEST_FONT_FAMILY=" + lang.getString("MEGAGLEST_FONT_FAMILY"); - _putenv(newEnvValue.c_str()); - #else - setenv("MEGAGLEST_FONT_FAMILY",lang.getString("MEGAGLEST_FONT_FAMILY").c_str(),0); - #endif - } - - #if defined(WIN32) - // Win32 overrides for fonts (just in case they must be different) - - if( lang.hasString("FONT_BASE_SIZE_WINDOWS")) { - // 256 for English - // 30000 for Chinese - Font::baseSize = strToInt(lang.getString("FONT_BASE_SIZE_WINDOWS")); - } - - if( lang.hasString("FONT_SCALE_SIZE_WINDOWS")) { - Font::scaleFontValue = strToFloat(lang.getString("FONT_SCALE_SIZE_WINDOWS")); - } - if( lang.hasString("FONT_SCALE_CENTERH_FACTOR_WINDOWS")) { - Font::scaleFontValueCenterHFactor = strToFloat(lang.getString("FONT_SCALE_CENTERH_FACTOR_WINDOWS")); - } - - if( lang.hasString("FONT_HEIGHT_TEXT_WINDOWS")) { - Font::langHeightText = lang.getString("FONT_HEIGHT_TEXT_WINDOWS",Font::langHeightText.c_str()); - } - - if( lang.hasString("FONT_CHARCOUNT_WINDOWS")) { - // 256 for English - // 30000 for Chinese - Font::charCount = strToInt(lang.getString("FONT_CHARCOUNT_WINDOWS")); - } - if( lang.hasString("FONT_TYPENAME_WINDOWS")) { - Font::fontTypeName = lang.getString("FONT_TYPENAME_WINDOWS"); - } - if( lang.hasString("FONT_CHARSET_WINDOWS")) { - // Example values: - // DEFAULT_CHARSET (English) = 1 - // GB2312_CHARSET (Chinese) = 134 - Shared::Platform::PlatformContextGl::charSet = strToInt(lang.getString("FONT_CHARSET_WINDOWS")); - } - if( lang.hasString("FONT_MULTIBYTE_WINDOWS")) { - Font::fontIsMultibyte = strToBool(lang.getString("FONT_MULTIBYTE_WINDOWS")); - } - if( lang.hasString("FONT_RIGHTTOLEFT_WINDOWS")) { - Font::fontIsRightToLeft = strToBool(lang.getString("FONT_RIGHTTOLEFT_WINDOWS")); - } - - if( lang.hasString("MEGAGLEST_FONT_WINDOWS")) { - //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese - string newEnvValue = "MEGAGLEST_FONT=" + lang.getString("MEGAGLEST_FONT_WINDOWS"); - _putenv(newEnvValue.c_str()); - } - - // end win32 - #endif - - - if( lang.hasString("ALLOWED_SPECIAL_KEYS","",false)) { - string allowedKeys = lang.getString("ALLOWED_SPECIAL_KEYS"); - Window::addAllowedKeys(allowedKeys); - } - else { - Window::clearAllowedKeys(); - } - - if(loadFonts == true) { - CoreData &coreData= CoreData::getInstance(); - coreData.loadFonts(); - } + Lang::Lang () + { + language = ""; + is_utf8_language = false; + allowNativeLanguageTechtree = true; + techNameLoaded = ""; } -} -void Lang::loadGameStringProperties(string uselanguage, Properties &properties, bool fileMustExist, - bool fallbackToDefault) { - properties.clear(); - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - //string languageFile = data_path + "data/lang/" + uselanguage + ".lng"; - string languageFile = getGameCustomCoreDataPath(data_path, "data/lang/" + uselanguage + ".lng"); - if(fileMustExist == false && fileExists(languageFile) == false) { - return; - } - else if(fileExists(languageFile) == false && fallbackToDefault == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,languageFile.c_str()); - //throw megaglest_runtime_error("File NOT FOUND, can't open file: [" + languageFile + "]"); - printf("Language file NOT FOUND, can't open file: [%s] switching to default language: %s\n",languageFile.c_str(),DEFAULT_LANGUAGE); + Lang & Lang::getInstance () + { + static Lang lang; + return lang; + } - languageFile = getGameCustomCoreDataPath(data_path, "data/lang/" + string(DEFAULT_LANGUAGE) + ".lng"); - } - is_utf8_language = valid_utf8_file(languageFile.c_str()); - properties.load(languageFile); -} + string Lang::getDefaultLanguage () const + { + return DEFAULT_LANGUAGE; + } + + void Lang::loadGameStrings (string uselanguage, bool loadFonts, + bool fallbackToDefault) + { + if (uselanguage.length () == 2 + || (uselanguage.length () == 5 && uselanguage[2] == '-')) + { + uselanguage = getLanguageFile (uselanguage); + } + bool languageChanged = (uselanguage != this->language); + this->language = uselanguage; + loadGameStringProperties (uselanguage, + gameStringsAllLanguages[this->language], true, + fallbackToDefault); + + if (languageChanged == true) + { + Font::resetToDefaults (); + Lang & lang = Lang::getInstance (); + if (lang.hasString ("FONT_BASE_SIZE")) + { + Font::baseSize = strToInt (lang.getString ("FONT_BASE_SIZE")); + } + + if (lang.hasString ("FONT_SCALE_SIZE")) + { + Font::scaleFontValue = + strToFloat (lang.getString ("FONT_SCALE_SIZE")); + } + if (lang.hasString ("FONT_SCALE_CENTERH_FACTOR")) + { + Font::scaleFontValueCenterHFactor = + strToFloat (lang.getString ("FONT_SCALE_CENTERH_FACTOR")); + } + + if (lang.hasString ("FONT_CHARCOUNT")) + { + // 256 for English + // 30000 for Chinese + Font::charCount = strToInt (lang.getString ("FONT_CHARCOUNT")); + } + if (lang.hasString ("FONT_TYPENAME")) + { + Font::fontTypeName = lang.getString ("FONT_TYPENAME"); + } + if (lang.hasString ("FONT_CHARSET")) + { + // Example values: + // DEFAULT_CHARSET (English) = 1 + // GB2312_CHARSET (Chinese) = 134 + Shared::Platform::PlatformContextGl::charSet = + strToInt (lang.getString ("FONT_CHARSET")); + } + if (lang.hasString ("FONT_MULTIBYTE")) + { + Font::fontIsMultibyte = + strToBool (lang.getString ("FONT_MULTIBYTE")); + } + + if (lang.hasString ("FONT_RIGHTTOLEFT")) + { + Font::fontIsRightToLeft = + strToBool (lang.getString ("FONT_RIGHTTOLEFT")); + } + + if (lang.hasString ("FONT_RIGHTTOLEFT_MIXED_SUPPORT")) + { + Font::fontSupportMixedRightToLeft = + strToBool (lang.getString ("FONT_RIGHTTOLEFT_MIXED_SUPPORT")); + } + + if (lang.hasString ("MEGAGLEST_FONT")) + { + //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese +#if defined(WIN32) + string newEnvValue = + "MEGAGLEST_FONT=" + lang.getString ("MEGAGLEST_FONT"); + _putenv (newEnvValue.c_str ()); +#else + setenv ("MEGAGLEST_FONT", + lang.getString ("MEGAGLEST_FONT").c_str (), 0); +#endif + } + + if (lang.hasString ("MEGAGLEST_FONT_FAMILY")) + { +#if defined(WIN32) + string newEnvValue = + "MEGAGLEST_FONT_FAMILY=" + + lang.getString ("MEGAGLEST_FONT_FAMILY"); + _putenv (newEnvValue.c_str ()); +#else + setenv ("MEGAGLEST_FONT_FAMILY", + lang.getString ("MEGAGLEST_FONT_FAMILY").c_str (), 0); +#endif + } + +#if defined(WIN32) + // Win32 overrides for fonts (just in case they must be different) + + if (lang.hasString ("FONT_BASE_SIZE_WINDOWS")) + { + // 256 for English + // 30000 for Chinese + Font::baseSize = + strToInt (lang.getString ("FONT_BASE_SIZE_WINDOWS")); + } + + if (lang.hasString ("FONT_SCALE_SIZE_WINDOWS")) + { + Font::scaleFontValue = + strToFloat (lang.getString ("FONT_SCALE_SIZE_WINDOWS")); + } + if (lang.hasString ("FONT_SCALE_CENTERH_FACTOR_WINDOWS")) + { + Font::scaleFontValueCenterHFactor = + strToFloat (lang.getString ("FONT_SCALE_CENTERH_FACTOR_WINDOWS")); + } + + if (lang.hasString ("FONT_HEIGHT_TEXT_WINDOWS")) + { + Font::langHeightText = + lang.getString ("FONT_HEIGHT_TEXT_WINDOWS", + Font::langHeightText.c_str ()); + } + + if (lang.hasString ("FONT_CHARCOUNT_WINDOWS")) + { + // 256 for English + // 30000 for Chinese + Font::charCount = + strToInt (lang.getString ("FONT_CHARCOUNT_WINDOWS")); + } + if (lang.hasString ("FONT_TYPENAME_WINDOWS")) + { + Font::fontTypeName = lang.getString ("FONT_TYPENAME_WINDOWS"); + } + if (lang.hasString ("FONT_CHARSET_WINDOWS")) + { + // Example values: + // DEFAULT_CHARSET (English) = 1 + // GB2312_CHARSET (Chinese) = 134 + Shared::Platform::PlatformContextGl::charSet = + strToInt (lang.getString ("FONT_CHARSET_WINDOWS")); + } + if (lang.hasString ("FONT_MULTIBYTE_WINDOWS")) + { + Font::fontIsMultibyte = + strToBool (lang.getString ("FONT_MULTIBYTE_WINDOWS")); + } + if (lang.hasString ("FONT_RIGHTTOLEFT_WINDOWS")) + { + Font::fontIsRightToLeft = + strToBool (lang.getString ("FONT_RIGHTTOLEFT_WINDOWS")); + } + + if (lang.hasString ("MEGAGLEST_FONT_WINDOWS")) + { + //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese + string newEnvValue = + "MEGAGLEST_FONT=" + lang.getString ("MEGAGLEST_FONT_WINDOWS"); + _putenv (newEnvValue.c_str ()); + } + + // end win32 +#endif + + + if (lang.hasString ("ALLOWED_SPECIAL_KEYS", "", false)) + { + string allowedKeys = lang.getString ("ALLOWED_SPECIAL_KEYS"); + Window::addAllowedKeys (allowedKeys); + } + else + { + Window::clearAllowedKeys (); + } + + if (loadFonts == true) + { + CoreData & coreData = CoreData::getInstance (); + coreData.loadFonts (); + } + } + } + + void Lang::loadGameStringProperties (string uselanguage, + Properties & properties, + bool fileMustExist, + bool fallbackToDefault) + { + properties.clear (); + string data_path = + getGameReadWritePath (GameConstants::path_data_CacheLookupKey); + //string languageFile = data_path + "data/lang/" + uselanguage + ".lng"; + string languageFile = + getGameCustomCoreDataPath (data_path, + "data/lang/" + uselanguage + ".lng"); + if (fileMustExist == false && fileExists (languageFile) == false) + { + return; + } + else if (fileExists (languageFile) == false + && fallbackToDefault == true) + { + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] path = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + languageFile.c_str ()); + //throw megaglest_runtime_error("File NOT FOUND, can't open file: [" + languageFile + "]"); + printf + ("Language file NOT FOUND, can't open file: [%s] switching to default language: %s\n", + languageFile.c_str (), DEFAULT_LANGUAGE); + + languageFile = + getGameCustomCoreDataPath (data_path, + "data/lang/" + + string (DEFAULT_LANGUAGE) + ".lng"); + } + is_utf8_language = valid_utf8_file (languageFile.c_str ()); + properties.load (languageFile); + } //bool Lang::isUTF8Language() const { -// return is_utf8_language; +// return is_utf8_language; //} -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()); + 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()); + //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; - if(isTutorial == false) { - scenarioPaths = config.getPathListForType(ptScenarios); - } - else { - scenarioPaths = config.getPathListForType(ptTutorials); - } - if(scenarioPaths.size() > 1) { - string &scenarioPath = scenarioPaths[1]; - endPathWithSlash(scenarioPath); + // First try to find scenario lng file in userdata + Config & config = Config::getInstance (); + vector < string > scenarioPaths; + if (isTutorial == false) + { + scenarioPaths = config.getPathListForType (ptScenarios); + } + else + { + scenarioPaths = config.getPathListForType (ptTutorials); + } + if (scenarioPaths.size () > 1) + { + string & scenarioPath = scenarioPaths[1]; + endPathWithSlash (scenarioPath); - string currentPath = scenarioPath; - endPathWithSlash(currentPath); - string scenarioFolder = currentPath + scenarioName + "/"; - string path = scenarioFolder + scenarioName + "_" + language + ".lng"; + string currentPath = scenarioPath; + endPathWithSlash (currentPath); + string scenarioFolder = currentPath + scenarioName + "/"; + string path = scenarioFolder + scenarioName + "_" + language + ".lng"; - //try to load the current language first - if(fileExists(path)) { - scenarioDir = scenarioPath; - } + //try to load the current language first + if (fileExists (path)) + { + scenarioDir = scenarioPath; + } + } + + string currentPath = scenarioDir; + endPathWithSlash (currentPath); + string scenarioFolder = currentPath + scenarioName + "/"; + string path = scenarioFolder + scenarioName + "_" + language + ".lng"; + if (EndsWith (scenarioDir, ".xml") == true) + { + scenarioFolder = extractDirectoryPathFromFile (scenarioDir); + path = scenarioFolder + scenarioName + "_" + language + ".lng"; + + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] path = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + path.c_str ()); + } + + scenarioStrings.clear (); + + //try to load the current language first + if (fileExists (path)) + { + //printf("#2 Loading scenario path [%s]\n",path.c_str()); + + scenarioStrings.load (path); + } + else + { + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] path not found [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + path.c_str ()); + + //try english otherwise + path = scenarioFolder + scenarioName + "_english.lng"; + 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); + } + } } - string currentPath = scenarioDir; - endPathWithSlash(currentPath); - string scenarioFolder = currentPath + scenarioName + "/"; - string path = scenarioFolder + scenarioName + "_" + language + ".lng"; - if(EndsWith(scenarioDir, ".xml") == true) { - scenarioFolder = extractDirectoryPathFromFile(scenarioDir); - path = scenarioFolder + scenarioName + "_" + language + ".lng"; + bool Lang::loadTechTreeStrings (string techTree, bool forceLoad) + { + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] techTree = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + techTree.c_str ()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); - } + //printf("Line: %d techTree = %s forceLoad = %d\n",__LINE__,techTree.c_str(),forceLoad); - scenarioStrings.clear(); + if (forceLoad == false && techTree == techNameLoaded) + { + return true; + } - //try to load the current language first - if(fileExists(path)) { - //printf("#2 Loading scenario path [%s]\n",path.c_str()); + bool foundTranslation = false; - scenarioStrings.load(path); - } - else{ - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path not found [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); + string currentPath = ""; + Config & config = Config::getInstance (); + vector < string > techPaths = config.getPathListForType (ptTechs); + for (int idx = 0; idx < (int) techPaths.size (); idx++) + { + string & techPath = techPaths[idx]; + endPathWithSlash (techPath); - //try english otherwise - path = scenarioFolder + scenarioName + "_english.lng"; - 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 (folderExists (techPath + techTree) == true) + { + currentPath = techPath; + endPathWithSlash (currentPath); + break; + } + } - if(fileExists(path)){ - //printf("#3 Loading scenario path [%s]\n",path.c_str()); + string techTreeFolder = currentPath + techTree + "/"; + string path = + techTreeFolder + "lang/" + techTree + "_" + language + ".lng"; + string pathDefault = + techTreeFolder + "lang/" + techTree + "_default.lng"; + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] path = [%s] pathDefault = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + path.c_str (), pathDefault.c_str ()); - scenarioStrings.load(path); - } - } -} + //techTreeStrings.clear(); + //techTreeStringsDefault.clear(); -bool Lang::loadTechTreeStrings(string techTree,bool forceLoad) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] techTree = [%s]\n",__FILE__,__FUNCTION__,__LINE__,techTree.c_str()); + //printf("Line: %d techTree = %s this->language = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),this->language.c_str(),forceLoad,path.c_str()); - //printf("Line: %d techTree = %s forceLoad = %d\n",__LINE__,techTree.c_str(),forceLoad); + //try to load the current language first + if (fileExists (path)) + { + foundTranslation = true; + if (forceLoad == true || + path != + techTreeStringsAllLanguages[techTree][this->language].getpath ()) + { - if(forceLoad == false && techTree == techNameLoaded) { - return true; - } + //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); - bool foundTranslation = false; + techTreeStringsAllLanguages[techTree][this->language].load (path); + techNameLoaded = techTree; + } + else if (path == + techTreeStringsAllLanguages[techTree][this->language]. + getpath () && techTree != techNameLoaded) + { + techNameLoaded = techTree; + } + } + else + { + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] path not found [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + path.c_str ()); - string currentPath = ""; - Config &config = Config::getInstance(); - vector techPaths = config.getPathListForType(ptTechs); - for(int idx = 0; idx < (int)techPaths.size(); idx++) { - string &techPath = techPaths[idx]; - endPathWithSlash(techPath); + //try english otherwise + string default_language = "english"; + path = + techTreeFolder + "lang/" + techTree + "_" + default_language + + ".lng"; + 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(folderExists(techPath + techTree) == true) { - currentPath = techPath; - endPathWithSlash(currentPath); - break; - } + //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); + + if (fileExists (path)) + { + foundTranslation = true; + if (forceLoad == true || + path != + techTreeStringsAllLanguages[techTree][default_language]. + getpath ()) + { + //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); + + techTreeStringsAllLanguages[techTree][default_language]. + load (path); + techNameLoaded = techTree; + } + else if (path == + techTreeStringsAllLanguages[techTree][default_language]. + getpath () && techTree != techNameLoaded) + { + techNameLoaded = techTree; + } + } + } + + if (fileExists (pathDefault)) + { + foundTranslation = true; + string default_language = "default"; + + //printf("Line: %d techTree = %s forceLoad = %d default_language = %s\n",__LINE__,techTree.c_str(),forceLoad,default_language.c_str()); + + if (forceLoad == true || + pathDefault != + techTreeStringsAllLanguages[techTree][default_language]. + getpath ()) + { + //printf("Line: %d techTree = %s forceLoad = %d pathDefault = %s\n",__LINE__,techTree.c_str(),forceLoad,pathDefault.c_str()); + + techTreeStringsAllLanguages[techTree][default_language]. + load (pathDefault); + techNameLoaded = techTree; + } + else if (pathDefault == + techTreeStringsAllLanguages[techTree][default_language]. + getpath () && techTree != techNameLoaded) + { + techNameLoaded = techTree; + } + } + + return foundTranslation; } - string techTreeFolder = currentPath + techTree + "/"; - string path = techTreeFolder + "lang/" + techTree + "_" + language + ".lng"; - string pathDefault = techTreeFolder + "lang/" + techTree + "_default.lng"; - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] pathDefault = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),pathDefault.c_str()); + void Lang::loadTilesetStrings (string tileset) + { + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] tileset = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + tileset.c_str ()); - //techTreeStrings.clear(); - //techTreeStringsDefault.clear(); - - //printf("Line: %d techTree = %s this->language = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),this->language.c_str(),forceLoad,path.c_str()); - - //try to load the current language first - if(fileExists(path)) { - foundTranslation = true; - if(forceLoad == true || - path != techTreeStringsAllLanguages[techTree][this->language].getpath()) { - - //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); - - techTreeStringsAllLanguages[techTree][this->language].load(path); - techNameLoaded = techTree; - } - else if(path == techTreeStringsAllLanguages[techTree][this->language].getpath() && - techTree != techNameLoaded) { - techNameLoaded = techTree; - } - } - else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path not found [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); - - //try english otherwise - string default_language = "english"; - path = techTreeFolder + "lang/" + techTree + "_" + default_language + ".lng"; - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); - - //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); - - if(fileExists(path)) { - foundTranslation = true; - if(forceLoad == true || - path != techTreeStringsAllLanguages[techTree][default_language].getpath()) { - //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); - - techTreeStringsAllLanguages[techTree][default_language].load(path); - techNameLoaded = techTree; - } - else if(path == techTreeStringsAllLanguages[techTree][default_language].getpath() && - techTree != techNameLoaded) { - techNameLoaded = techTree; - } - } - } - - if(fileExists(pathDefault)) { - foundTranslation = true; - string default_language = "default"; - - //printf("Line: %d techTree = %s forceLoad = %d default_language = %s\n",__LINE__,techTree.c_str(),forceLoad,default_language.c_str()); - - if(forceLoad == true || - pathDefault != techTreeStringsAllLanguages[techTree][default_language].getpath()) { - //printf("Line: %d techTree = %s forceLoad = %d pathDefault = %s\n",__LINE__,techTree.c_str(),forceLoad,pathDefault.c_str()); - - techTreeStringsAllLanguages[techTree][default_language].load(pathDefault); - techNameLoaded = techTree; - } - else if(pathDefault == techTreeStringsAllLanguages[techTree][default_language].getpath() && - techTree != techNameLoaded) { - techNameLoaded = techTree; - } - } - - return foundTranslation; -} - -void Lang::loadTilesetStrings(string tileset) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tileset = [%s]\n",__FILE__,__FUNCTION__,__LINE__,tileset.c_str()); - - string currentPath = ""; - Config &config = Config::getInstance(); - vector tilesetPaths = config.getPathListForType(ptTilesets); - for(int idx = 0; idx < (int)tilesetPaths.size(); idx++) { - string &tilesetPath = tilesetPaths[idx]; - endPathWithSlash(tilesetPath); + string currentPath = ""; + Config & config = Config::getInstance (); + vector < string > tilesetPaths = config.getPathListForType (ptTilesets); + for (int idx = 0; idx < (int) tilesetPaths.size (); idx++) + { + string & tilesetPath = tilesetPaths[idx]; + endPathWithSlash (tilesetPath); //printf("tilesetPath [%s]\n",tilesetPath.c_str()); - if(folderExists(tilesetPath + tileset) == true) { - currentPath = tilesetPath; - endPathWithSlash(currentPath); - break; - } + if (folderExists (tilesetPath + tileset) == true) + { + currentPath = tilesetPath; + endPathWithSlash (currentPath); + break; + } + } + + string tilesetFolder = currentPath + tileset + "/"; + string path = + tilesetFolder + "lang/" + tileset + "_" + language + ".lng"; + string pathDefault = tilesetFolder + "lang/" + tileset + "_default.lng"; + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] path = [%s] pathDefault = [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + path.c_str (), pathDefault.c_str ()); + + tilesetStrings.clear (); + tilesetStringsDefault.clear (); + + //try to load the current language first + if (fileExists (path)) + { + tilesetStrings.load (path); + } + else + { + if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug (SystemFlags::debugSystem, + "In [%s::%s Line: %d] path not found [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + path.c_str ()); + + //try english otherwise + path = tilesetFolder + "lang/" + tileset + "_english.lng"; + 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)) + { + tilesetStrings.load (path); + } + } + + if (fileExists (pathDefault)) + { + tilesetStringsDefault.load (pathDefault); + } } - string tilesetFolder = currentPath + tileset + "/"; - string path = tilesetFolder + "lang/" + tileset + "_" + language + ".lng"; - string pathDefault = tilesetFolder + "lang/" + tileset + "_default.lng"; - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] pathDefault = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),pathDefault.c_str()); + bool Lang::hasString (const string & s, string uselanguage, + bool fallbackToDefault) + { + bool result = false; + try + { + if (uselanguage != "") + { + //printf("#a fallbackToDefault = %d [%s] uselanguage [%s] DEFAULT_LANGUAGE [%s] this->language [%s]\n",fallbackToDefault,s.c_str(),uselanguage.c_str(),DEFAULT_LANGUAGE,this->language.c_str()); + if (gameStringsAllLanguages.find (uselanguage) == + gameStringsAllLanguages.end ()) + { + loadGameStringProperties (uselanguage, + gameStringsAllLanguages[uselanguage], + false); + } + //string result2 = otherLanguageStrings[uselanguage].getString(s); + gameStringsAllLanguages[uselanguage].getString (s); + //printf("#b result2 [%s]\n",result2.c_str()); - tilesetStrings.clear(); - tilesetStringsDefault.clear(); + result = true; + } + else + { + //string result2 = strings.getString(s); + gameStringsAllLanguages[this->language].getString (s); + result = true; + } + } + catch (exception & ex) + { + if (gameStringsAllLanguages[this->language].getpath () != "") + { + if (SystemFlags::VERBOSE_MODE_ENABLED) + SystemFlags::OutputDebug (SystemFlags::debugError, + "In [%s::%s Line: %d] Error [%s] for uselanguage [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + ex.what (), uselanguage.c_str ()); + } - //try to load the current language first - if(fileExists(path)) { - tilesetStrings.load(path); - } - else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path not found [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); + //printf("#1 fallbackToDefault = %d [%s] uselanguage [%s] DEFAULT_LANGUAGE [%s] this->language [%s]\n",fallbackToDefault,s.c_str(),uselanguage.c_str(),DEFAULT_LANGUAGE,this->language.c_str()); + if (fallbackToDefault == true && uselanguage != DEFAULT_LANGUAGE + && this->language != DEFAULT_LANGUAGE) + { + result = hasString (s, DEFAULT_LANGUAGE, false); + } + else + { - //try english otherwise - path = tilesetFolder + "lang/" + tileset + "_english.lng"; - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); + } + } + return result; + } - if(fileExists(path)) { - tilesetStrings.load(path); - } - } + bool Lang::isLanguageLocal (string compareLanguage) const + { + return (compareLanguage == language); + } - if(fileExists(pathDefault)) { - tilesetStringsDefault.load(pathDefault); - } -} + string Lang::parseResult (const string & key, const string & value) + { + if (value != "$USE_DEFAULT_LANGUAGE_VALUE") + { + return value; + } + string result = Lang::getString (key, DEFAULT_LANGUAGE); + return result; + } + string Lang::getString (const string & s, string uselanguage, + bool fallbackToDefault) + { + try + { + string result = ""; -bool Lang::hasString(const string &s, string uselanguage, bool fallbackToDefault) { - bool result = false; - try { - if(uselanguage != "") { - //printf("#a fallbackToDefault = %d [%s] uselanguage [%s] DEFAULT_LANGUAGE [%s] this->language [%s]\n",fallbackToDefault,s.c_str(),uselanguage.c_str(),DEFAULT_LANGUAGE,this->language.c_str()); - if(gameStringsAllLanguages.find(uselanguage) == gameStringsAllLanguages.end()) { - loadGameStringProperties(uselanguage, gameStringsAllLanguages[uselanguage], false); - } - //string result2 = otherLanguageStrings[uselanguage].getString(s); - gameStringsAllLanguages[uselanguage].getString(s); - //printf("#b result2 [%s]\n",result2.c_str()); + if (uselanguage != "") + { + if (gameStringsAllLanguages.find (uselanguage) == + gameStringsAllLanguages.end ()) + { + loadGameStringProperties (uselanguage, + gameStringsAllLanguages[uselanguage], + false); + } + result = gameStringsAllLanguages[uselanguage].getString (s); + replaceAll (result, "\\n", "\n"); + } + else + { + result = gameStringsAllLanguages[this->language].getString (s); + replaceAll (result, "\\n", "\n"); + } - result = true; - } - else { - //string result2 = strings.getString(s); - gameStringsAllLanguages[this->language].getString(s); - result = true; - } - } - catch(exception &ex) { - if(gameStringsAllLanguages[this->language].getpath() != "") { - if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] for uselanguage [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what(),uselanguage.c_str()); - } + return parseResult (s, result);; + } + catch (exception & ex) + { + if (gameStringsAllLanguages[this->language].getpath () != "") + { + if (fallbackToDefault == false || SystemFlags::VERBOSE_MODE_ENABLED) + { + if (GlobalStaticFlags::getIsNonGraphicalModeEnabled () == false) + { + if (SystemFlags::VERBOSE_MODE_ENABLED) + SystemFlags::OutputDebug (SystemFlags::debugError, + "In [%s::%s Line: %d] Error [%s] uselanguage [%s] text [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + ex.what (), uselanguage.c_str (), + s.c_str ()); + } + } + } - //printf("#1 fallbackToDefault = %d [%s] uselanguage [%s] DEFAULT_LANGUAGE [%s] this->language [%s]\n",fallbackToDefault,s.c_str(),uselanguage.c_str(),DEFAULT_LANGUAGE,this->language.c_str()); - if(fallbackToDefault == true && uselanguage != DEFAULT_LANGUAGE && this->language != DEFAULT_LANGUAGE) { - result = hasString(s, DEFAULT_LANGUAGE, false); - } - else { + //printf("#2 fallbackToDefault = %d [%s] uselanguage [%s] DEFAULT_LANGUAGE [%s] this->language [%s]\n",fallbackToDefault,s.c_str(),uselanguage.c_str(),DEFAULT_LANGUAGE,this->language.c_str()); - } - } - return result; -} + //if(fallbackToDefault == true && uselanguage != DEFAULT_LANGUAGE && this->language != DEFAULT_LANGUAGE) { + if (uselanguage != DEFAULT_LANGUAGE + && this->language != DEFAULT_LANGUAGE) + { + return getString (s, DEFAULT_LANGUAGE, false); + } -bool Lang::isLanguageLocal(string compareLanguage) const { - return (compareLanguage == language); -} + //return "???" + s + "???"; + } + return "???" + s + "???"; + } -string Lang::parseResult(const string &key, const string &value) { - if(value != "$USE_DEFAULT_LANGUAGE_VALUE") { - return value; - } - string result = Lang::getString(key, DEFAULT_LANGUAGE); - return result; -} -string Lang::getString(const string &s, string uselanguage, bool fallbackToDefault) { - try { - string result = ""; + string Lang::getScenarioString (const string & s) + { + try + { + string result = scenarioStrings.getString (s); + replaceAll (result, "\\n", "\n"); + return result; + } + catch (exception & ex) + { + if (scenarioStrings.getpath () != "") + { + SystemFlags::OutputDebug (SystemFlags::debugError, + "In [%s::%s Line: %d] Error [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + ex.what ()); + } + return "???" + s + "???"; + } + } - if(uselanguage != "") { - if(gameStringsAllLanguages.find(uselanguage) == gameStringsAllLanguages.end()) { - loadGameStringProperties(uselanguage, gameStringsAllLanguages[uselanguage], false); - } - result = gameStringsAllLanguages[uselanguage].getString(s); - replaceAll(result, "\\n", "\n"); - } - else { - result = gameStringsAllLanguages[this->language].getString(s); - replaceAll(result, "\\n", "\n"); - } + bool Lang::hasScenarioString (const string & s) + { + bool result = false; + try + { + scenarioStrings.getString (s); + result = true; + } + catch (exception & ex) + { + if (scenarioStrings.getpath () != "") + { + if (SystemFlags::VERBOSE_MODE_ENABLED) + SystemFlags::OutputDebug (SystemFlags::debugError, + "In [%s::%s Line: %d] Error [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + ex.what ()); + } + } + return result; + } - return parseResult(s, result);; - } - catch(exception &ex) { - if(gameStringsAllLanguages[this->language].getpath() != "") { - if(fallbackToDefault == false || SystemFlags::VERBOSE_MODE_ENABLED) { - if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { - if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] uselanguage [%s] text [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what(),uselanguage.c_str(),s.c_str()); - } - } - } + string Lang::getTechTreeString (const string & s, + const char *defaultValue) + { + try + { + string result = ""; + string default_language = "default"; - //printf("#2 fallbackToDefault = %d [%s] uselanguage [%s] DEFAULT_LANGUAGE [%s] this->language [%s]\n",fallbackToDefault,s.c_str(),uselanguage.c_str(),DEFAULT_LANGUAGE,this->language.c_str()); + //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); - //if(fallbackToDefault == true && uselanguage != DEFAULT_LANGUAGE && this->language != DEFAULT_LANGUAGE) { - if( uselanguage != DEFAULT_LANGUAGE && this->language != DEFAULT_LANGUAGE) { - return getString(s, DEFAULT_LANGUAGE, false); - } + if (allowNativeLanguageTechtree == true && + (techTreeStringsAllLanguages[techNameLoaded][this->language]. + hasString (s) == true || defaultValue == NULL)) + { + if (techTreeStringsAllLanguages[techNameLoaded][this->language]. + hasString (s) == false + && + techTreeStringsAllLanguages[techNameLoaded][default_language]. + hasString (s) == true) + { - //return "???" + s + "???"; - } - return "???" + s + "???"; -} + //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); -string Lang::getScenarioString(const string &s) { - try{ - string result = scenarioStrings.getString(s); - replaceAll(result, "\\n", "\n"); - return result; - } - catch(exception &ex) { - if(scenarioStrings.getpath() != "") { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - } - return "???" + s + "???"; - } -} + result = + techTreeStringsAllLanguages[techNameLoaded][default_language]. + getString (s); + } + else + { -bool Lang::hasScenarioString(const string &s) { - bool result = false; - try { - scenarioStrings.getString(s); - result = true; - } - catch(exception &ex) { - if(scenarioStrings.getpath() != "") { - if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - } - } - return result; -} + //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); -string Lang::getTechTreeString(const string &s,const char *defaultValue) { - try{ - string result = ""; - string default_language = "default"; + result = + techTreeStringsAllLanguages[techNameLoaded][this->language]. + getString (s); + } + } + else if (allowNativeLanguageTechtree == true && + techTreeStringsAllLanguages[techNameLoaded] + [default_language].hasString (s) == true) + { - //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); + //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); - if(allowNativeLanguageTechtree == true && - (techTreeStringsAllLanguages[techNameLoaded][this->language].hasString(s) == true || - defaultValue == NULL)) { - if(techTreeStringsAllLanguages[techNameLoaded][this->language].hasString(s) == false && - techTreeStringsAllLanguages[techNameLoaded][default_language].hasString(s) == true) { + result = + techTreeStringsAllLanguages[techNameLoaded][default_language]. + getString (s); + } + else if (defaultValue != NULL) + { + result = defaultValue; + } + replaceAll (result, "\\n", "\n"); + return result; + } + catch (exception & ex) + { + if (techTreeStringsAllLanguages[techNameLoaded][this->language]. + getpath () != "") + { + SystemFlags::OutputDebug (SystemFlags::debugError, + "In [%s::%s Line: %d] Error [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + ex.what ()); + } + //return "???" + s + "???"; + } + return "???" + s + "???"; + } - //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); + string Lang::getTilesetString (const string & s, const char *defaultValue) + { + try + { + string result = ""; - result = techTreeStringsAllLanguages[techNameLoaded][default_language].getString(s); - } - else { + if (tilesetStrings.hasString (s) == true || defaultValue == NULL) + { + if (tilesetStrings.hasString (s) == false + && tilesetStringsDefault.hasString (s) == true) + { + result = tilesetStringsDefault.getString (s); + } + else + { + result = tilesetStrings.getString (s); + } + } + else if (tilesetStringsDefault.hasString (s) == true) + { + result = tilesetStringsDefault.getString (s); + } + else if (defaultValue != NULL) + { + result = defaultValue; + } + replaceAll (result, "\\n", "\n"); + return result; + } + catch (exception & ex) + { + if (tilesetStrings.getpath () != "") + { + SystemFlags::OutputDebug (SystemFlags::debugError, + "In [%s::%s Line: %d] Error [%s]\n", + __FILE__, __FUNCTION__, __LINE__, + ex.what ()); + } + //return "???" + s + "???"; + } + return "???" + s + "???"; + } - //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); + bool Lang::fileMatchesISO630Code (string uselanguage, + string testLanguageFile) + { + bool result = false; + Properties stringsTest; + stringsTest.load (testLanguageFile); - result = techTreeStringsAllLanguages[techNameLoaded][this->language].getString(s); - } - } - else if(allowNativeLanguageTechtree == true && - techTreeStringsAllLanguages[techNameLoaded][default_language].hasString(s) == true) { + try + { + string iso639 = stringsTest.getString ("ISO639-1"); + if (iso639 == uselanguage) + { + result = true; + } + } + //catch(const exception &ex) { + catch ( ...) + { + } - //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); + return result; + } - result = techTreeStringsAllLanguages[techNameLoaded][default_language].getString(s); - } - else if(defaultValue != NULL) { - result = defaultValue; - } - replaceAll(result, "\\n", "\n"); - return result; - } - catch(exception &ex) { - if(techTreeStringsAllLanguages[techNameLoaded][this->language].getpath() != "") { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - } - //return "???" + s + "???"; - } - return "???" + s + "???"; -} + string Lang::getLanguageFile (string uselanguage) + { + bool foundMatch = false; + string result = uselanguage; -string Lang::getTilesetString(const string &s,const char *defaultValue) { - try{ - string result = ""; + string data_path = + getGameReadWritePath (GameConstants::path_data_CacheLookupKey); - if(tilesetStrings.hasString(s) == true || defaultValue == NULL) { - if(tilesetStrings.hasString(s) == false && tilesetStringsDefault.hasString(s) == true) { - result = tilesetStringsDefault.getString(s); - } - else { - result = tilesetStrings.getString(s); - } - } - else if(tilesetStringsDefault.hasString(s) == true) { - result = tilesetStringsDefault.getString(s); - } - else if(defaultValue != NULL) { - result = defaultValue; - } - replaceAll(result, "\\n", "\n"); - return result; - } - catch(exception &ex) { - if(tilesetStrings.getpath() != "") { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - } - //return "???" + s + "???"; - } - return "???" + s + "???"; -} + vector < string > langResults; + string userDataPath = getGameCustomCoreDataPath (data_path, ""); + findAll (userDataPath + "data/lang/*.lng", langResults, true, false); + for (unsigned int i = 0; i < langResults.size () && foundMatch == false; + ++i) + { + string testLanguageFile = + userDataPath + "data/lang/" + langResults[i] + ".lng"; + foundMatch = fileMatchesISO630Code (uselanguage, testLanguageFile); + if (foundMatch == true) + { + result = langResults[i]; + } + } + if (foundMatch == false) + { + langResults.clear (); + findAll (data_path + "data/lang/*.lng", langResults, true); + for (unsigned int i = 0; + i < langResults.size () && foundMatch == false; ++i) + { + string testLanguageFile = + data_path + "data/lang/" + langResults[i] + ".lng"; + foundMatch = fileMatchesISO630Code (uselanguage, testLanguageFile); + if (foundMatch == true) + { + result = langResults[i]; + } + } + } + return result; + } -bool Lang::fileMatchesISO630Code(string uselanguage, string testLanguageFile) { - bool result = false; - Properties stringsTest; - stringsTest.load(testLanguageFile); + string Lang::getNativeLanguageName (string uselanguage, + string testLanguageFile) + { + string result = uselanguage; - try { - string iso639 = stringsTest.getString("ISO639-1"); - if(iso639 == uselanguage) { - result = true; - } - } - //catch(const exception &ex) { - catch(...) { - } + static map < string, string > cachedNativeLanguageNames; + if (cachedNativeLanguageNames.find (testLanguageFile) != + cachedNativeLanguageNames.end ()) + { + result = cachedNativeLanguageNames[testLanguageFile]; + } + else + { + Properties stringsTest; + stringsTest.load (testLanguageFile); - return result; -} + try + { + result = stringsTest.getString ("NativeLanguageName"); + cachedNativeLanguageNames[testLanguageFile] = result; -string Lang::getLanguageFile(string uselanguage) { - bool foundMatch = false; - string result = uselanguage; + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("Caching native language name for [%s] = [%s]\n", + testLanguageFile.c_str (), result.c_str ()); + } + catch (const exception & ex) + { + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf ("ERROR Caching native language name for [%s] msg: [%s]\n", + testLanguageFile.c_str (), ex.what ()); + } + catch ( ...) + { + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("ERROR Caching native language name for [%s] msg: [UNKNOWN]\n", + testLanguageFile.c_str ()); + } + } - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + return result; + } - vector langResults; - string userDataPath = getGameCustomCoreDataPath(data_path, ""); - findAll(userDataPath + "data/lang/*.lng", langResults, true, false); - for(unsigned int i = 0; i < langResults.size() && foundMatch == false ; ++i) { - string testLanguageFile = userDataPath + "data/lang/" + langResults[i] + ".lng"; - foundMatch = fileMatchesISO630Code(uselanguage, testLanguageFile); - if(foundMatch == true) { - result = langResults[i]; - } - } - if(foundMatch == false) { - langResults.clear(); - findAll(data_path + "data/lang/*.lng", langResults, true); - for(unsigned int i = 0; i < langResults.size() && foundMatch == false ; ++i) { - string testLanguageFile = data_path + "data/lang/" + langResults[i] + ".lng"; - foundMatch = fileMatchesISO630Code(uselanguage, testLanguageFile); - if(foundMatch == true) { - result = langResults[i]; - } - } - } - return result; -} + pair < string, + string > Lang::getNavtiveNameFromLanguageName (string langName) + { + pair < string, string > result; -string Lang::getNativeLanguageName(string uselanguage, string testLanguageFile) { - string result = uselanguage; + //printf("looking for language [%s]\n",langName.c_str()); - static map cachedNativeLanguageNames; - if(cachedNativeLanguageNames.find(testLanguageFile) != cachedNativeLanguageNames.end()) { - result = cachedNativeLanguageNames[testLanguageFile]; - } - else { - Properties stringsTest; - stringsTest.load(testLanguageFile); + map < string, string > nativeList = + Lang::getDiscoveredLanguageList (true); + map < string, string >::iterator iterMap = nativeList.find (langName); + if (iterMap != nativeList.end ()) + { + result = make_pair (iterMap->second, iterMap->first); + } + return result; + } - try { - result = stringsTest.getString("NativeLanguageName"); - cachedNativeLanguageNames[testLanguageFile] = result; + map < string, + string > Lang::getDiscoveredLanguageList (bool searchKeyIsLangName) + { + map < string, string > result; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Caching native language name for [%s] = [%s]\n",testLanguageFile.c_str(),result.c_str()); - } - catch(const exception &ex) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("ERROR Caching native language name for [%s] msg: [%s]\n",testLanguageFile.c_str(),ex.what()); - } - catch(...) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("ERROR Caching native language name for [%s] msg: [UNKNOWN]\n",testLanguageFile.c_str()); - } - } + string data_path = + getGameReadWritePath (GameConstants::path_data_CacheLookupKey); + string userDataPath = getGameCustomCoreDataPath (data_path, ""); - return result; -} + vector < string > langResults; + findAll (userDataPath + "data/lang/*.lng", langResults, true, false); + for (unsigned int i = 0; i < langResults.size (); ++i) + { + string testLanguage = langResults[i]; + string testLanguageFile = + userDataPath + "data/lang/" + testLanguage + ".lng"; + string nativeName = + getNativeLanguageName (testLanguage, testLanguageFile); + if (searchKeyIsLangName == false) + { + result[nativeName] = testLanguage; + } + else + { + result[testLanguage] = nativeName; + } + } -pair Lang::getNavtiveNameFromLanguageName(string langName) { - pair result; + vector < string > langResults2; + findAll (data_path + "data/lang/*.lng", langResults2, true); + if (langResults2.empty () && langResults.empty ()) + { + throw megaglest_runtime_error ("There are no lang files"); + } + for (unsigned int i = 0; i < langResults2.size (); ++i) + { + string testLanguage = langResults2[i]; + if (std:: + find (langResults.begin (), langResults.end (), + testLanguage) == langResults.end ()) + { + langResults.push_back (testLanguage); - //printf("looking for language [%s]\n",langName.c_str()); + string testLanguageFile = + data_path + "data/lang/" + testLanguage + ".lng"; + string nativeName = + getNativeLanguageName (testLanguage, testLanguageFile); + if (searchKeyIsLangName == false) + { + result[nativeName] = testLanguage; + } + else + { + result[testLanguage] = nativeName; + } + } + } - map nativeList = Lang::getDiscoveredLanguageList(true); - map::iterator iterMap = nativeList.find(langName); - if(iterMap != nativeList.end()) { - result = make_pair(iterMap->second,iterMap->first); - } - return result; -} + return result; + } -map Lang::getDiscoveredLanguageList(bool searchKeyIsLangName) { - map result; - - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - string userDataPath = getGameCustomCoreDataPath(data_path, ""); - - vector langResults; - findAll(userDataPath + "data/lang/*.lng", langResults, true, false); - for(unsigned int i = 0; i < langResults.size(); ++i) { - string testLanguage = langResults[i]; - string testLanguageFile = userDataPath + "data/lang/" + testLanguage + ".lng"; - string nativeName = getNativeLanguageName(testLanguage, testLanguageFile); - if(searchKeyIsLangName == false) { - result[nativeName] = testLanguage; - } - else { - result[testLanguage] = nativeName; - } - } - - vector langResults2; - findAll(data_path + "data/lang/*.lng", langResults2, true); - if(langResults2.empty() && langResults.empty()) { - throw megaglest_runtime_error("There are no lang files"); - } - for(unsigned int i = 0; i < langResults2.size(); ++i) { - string testLanguage = langResults2[i]; - if(std::find(langResults.begin(),langResults.end(),testLanguage) == langResults.end()) { - langResults.push_back(testLanguage); - - string testLanguageFile = data_path + "data/lang/" + testLanguage + ".lng"; - string nativeName = getNativeLanguageName(testLanguage, testLanguageFile); - if(searchKeyIsLangName == false) { - result[nativeName] = testLanguage; - } - else { - result[testLanguage] = nativeName; - } - } - } - - return result; -} - -}}//end namespace + } +} //end namespace diff --git a/source/glest_game/global/lang.h b/source/glest_game/global/lang.h index 3b153ea2a..d5f684fcc 100644 --- a/source/glest_game/global/lang.h +++ b/source/glest_game/global/lang.h @@ -1,91 +1,120 @@ // ============================================================== -// This file is part of Glest (www.glest.org) +// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Martiño Figueroa // -// You can redistribute this code and/or modify it under -// the terms of the GNU General Public License as published -// by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version // ============================================================== #ifndef _GLEST_GAME_LANG_H_ -#define _GLEST_GAME_LANG_H_ +# define _GLEST_GAME_LANG_H_ -#ifdef WIN32 - #include - #include -#endif +# ifdef WIN32 +# include +# include +# endif -#include "properties.h" -#include "leak_dumper.h" +# include "properties.h" +# include "leak_dumper.h" -namespace Glest{ namespace Game{ +namespace Glest +{ + namespace Game + { -using Shared::Util::Properties; + using Shared::Util::Properties; // ===================================================== -// class Lang +// class Lang // -// String table +// String table // ===================================================== -class Lang { -private: + class Lang + { + private: - bool is_utf8_language; - string language; - std::map gameStringsAllLanguages; + bool is_utf8_language; + string language; + std::map < string, Properties > gameStringsAllLanguages; - Properties scenarioStrings; + Properties scenarioStrings; - Properties tilesetStrings; - Properties tilesetStringsDefault; + Properties tilesetStrings; + Properties tilesetStringsDefault; - std::map > techTreeStringsAllLanguages; - string techNameLoaded; - bool allowNativeLanguageTechtree; + std::map < string, std::map < string, + Properties > >techTreeStringsAllLanguages; + string techNameLoaded; + bool allowNativeLanguageTechtree; -private: - Lang(); - void loadGameStringProperties(string language, Properties &properties, bool fileMustExist,bool fallbackToDefault=false); - bool fileMatchesISO630Code(string uselanguage, string testLanguageFile); - string getNativeLanguageName(string uselanguage, string testLanguageFile); + private: + Lang (); + void loadGameStringProperties (string language, Properties & properties, + bool fileMustExist, + bool fallbackToDefault = false); + bool fileMatchesISO630Code (string uselanguage, + string testLanguageFile); + string getNativeLanguageName (string uselanguage, + string testLanguageFile); - string parseResult(const string &key, const string &value); + string parseResult (const string & key, const string & value); -public: - static Lang &getInstance(); + public: + static Lang & getInstance (); - string getTechNameLoaded() const { return techNameLoaded; } - bool getAllowNativeLanguageTechtree() const { return allowNativeLanguageTechtree; } - void setAllowNativeLanguageTechtree(bool value) { allowNativeLanguageTechtree = value; } + string getTechNameLoaded () const + { + return techNameLoaded; + } + bool getAllowNativeLanguageTechtree () const + { + return allowNativeLanguageTechtree; + } + void setAllowNativeLanguageTechtree (bool value) + { + allowNativeLanguageTechtree = value; + } - void loadGameStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false); - void loadScenarioStrings(string scenarioDir, string scenarioName, bool isTutorial); - bool loadTechTreeStrings(string techTree, bool forceLoad=false); - void loadTilesetStrings(string tileset); + void loadGameStrings (string uselanguage, bool loadFonts = + true, bool fallbackToDefault = false); + void loadScenarioStrings (string scenarioDir, string scenarioName, + bool isTutorial); + bool loadTechTreeStrings (string techTree, bool forceLoad = false); + void loadTilesetStrings (string tileset); - string getString(const string &s,string uselanguage="", bool fallbackToDefault=false); - bool hasString(const string &s, string uselanguage="", bool fallbackToDefault=false); + string getString (const string & s, string uselanguage = + "", bool fallbackToDefault = false); + bool hasString (const string & s, string uselanguage = + "", bool fallbackToDefault = false); - string getScenarioString(const string &s); - bool hasScenarioString(const string &s); + string getScenarioString (const string & s); + bool hasScenarioString (const string & s); - string getTechTreeString(const string &s, const char *defaultValue=NULL); - string getTilesetString(const string &s, const char *defaultValue=NULL); + string getTechTreeString (const string & s, const char *defaultValue = + NULL); + string getTilesetString (const string & s, const char *defaultValue = + NULL); - string getLanguage() const { return language; } - bool isLanguageLocal(string compareLanguage) const; - //bool isUTF8Language() const; - string getDefaultLanguage() const; + string getLanguage () const + { + return language; + } + bool isLanguageLocal (string compareLanguage) const; + //bool isUTF8Language() const; + string getDefaultLanguage () const; - map getDiscoveredLanguageList(bool searchKeyIsLangName=false); - pair getNavtiveNameFromLanguageName(string langName); + map < string, + string > getDiscoveredLanguageList (bool searchKeyIsLangName = false); + pair < string, + string > getNavtiveNameFromLanguageName (string langName); - string getLanguageFile(string uselanguage); -}; + string getLanguageFile (string uselanguage); + }; -}}//end namespace +}} //end namespace #endif diff --git a/source/glest_game/global/metrics.cpp b/source/glest_game/global/metrics.cpp index 15bbae3e5..34bf853a8 100644 --- a/source/glest_game/global/metrics.cpp +++ b/source/glest_game/global/metrics.cpp @@ -1,115 +1,132 @@ // ============================================================== -// This file is part of Glest (www.glest.org) +// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Martiño Figueroa // -// You can redistribute this code and/or modify it under -// the terms of the GNU General Public License as published -// by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version // ============================================================== -#include "metrics.h" +#include "metrics.h" #include #include "platform_util.h" #include "leak_dumper.h" using namespace std; -namespace Glest{ namespace Game{ +namespace Glest +{ + namespace Game + { // ===================================================== -// class Metrics +// class Metrics // ===================================================== -Metrics::Metrics() { - reloadData(); -} + Metrics::Metrics () + { + reloadData (); + } -void Metrics::reload(int resWidth, int resHeight) { - Metrics *metrics = getInstancePtr(); - metrics->reloadData(resWidth, resHeight); -} + void Metrics::reload (int resWidth, int resHeight) + { + Metrics *metrics = getInstancePtr (); + metrics->reloadData (resWidth, resHeight); + } -void Metrics::reloadData(int resWidth, int resHeight) { - Config &config = Config::getInstance(); - - virtualW= 1000; - virtualH= 750; + void Metrics::reloadData (int resWidth, int resHeight) + { + Config & config = Config::getInstance (); - if(resWidth > 0) { - screenW= resWidth; - } - else { - screenW= config.getInt("ScreenWidth"); - } - if(resHeight > 0) { - screenH= resHeight; - } - else { - screenH= config.getInt("ScreenHeight"); - } - - minimapX= 10; - minimapY= 750-128-30+16; - minimapW= 128; - minimapH= 128; + virtualW = 1000; + virtualH = 750; - displayX= 800; - displayY= 250; - displayW= 128; - displayH= 480; -} + if (resWidth > 0) + { + screenW = resWidth; + } + else + { + screenW = config.getInt ("ScreenWidth"); + } + if (resHeight > 0) + { + screenH = resHeight; + } + else + { + screenH = config.getInt ("ScreenHeight"); + } -Metrics * Metrics::getInstancePtr() { - static Metrics metrics; - return &metrics; -} + minimapX = 10; + minimapY = 750 - 128 - 30 + 16; + minimapW = 128; + minimapH = 128; -const Metrics &Metrics::getInstance(){ - Metrics *metrics = getInstancePtr(); - return *metrics; -} + displayX = 800; + displayY = 250; + displayW = 128; + displayH = 480; + } -float Metrics::getAspectRatio() const{ - if(screenH == 0) { - throw megaglest_runtime_error("div by 0 screenH == 0"); - } - return static_cast(screenW)/screenH; -} + Metrics *Metrics::getInstancePtr () + { + static Metrics metrics; + return &metrics; + } -int Metrics::toVirtualX(int w) const{ - if(screenW == 0) { - throw megaglest_runtime_error("div by 0 screenW == 0"); - } - return w*virtualW/screenW; -} + const Metrics & Metrics::getInstance () + { + Metrics *metrics = getInstancePtr (); + return *metrics; + } -int Metrics::toVirtualY(int h) const{ - if(screenH == 0) { - throw megaglest_runtime_error("div by 0 screenH == 0"); - } + float Metrics::getAspectRatio () const + { + if (screenH == 0) + { + throw megaglest_runtime_error ("div by 0 screenH == 0"); + } + return static_cast < float >(screenW) / screenH; + } - //printf("h [%d] virtualH [%d] screenH [%d] result = %d\n",h,virtualH,screenH,(h*virtualH/screenH)); + int Metrics::toVirtualX (int w) const + { + if (screenW == 0) + { + throw megaglest_runtime_error ("div by 0 screenW == 0"); + } + return w * virtualW / screenW; + } - return h*virtualH/screenH; -} + int Metrics::toVirtualY (int h) const + { + if (screenH == 0) + { + throw megaglest_runtime_error ("div by 0 screenH == 0"); + } -bool Metrics::isInDisplay(int x, int y) const{ - return + //printf("h [%d] virtualH [%d] screenH [%d] result = %d\n",h,virtualH,screenH,(h*virtualH/screenH)); + + return h * virtualH / screenH; + } + + bool Metrics::isInDisplay (int x, int y) const + { + return x > displayX && - y > displayY && - x < displayX+displayW && - y < displayY+displayH; -} + y > displayY && x < displayX + displayW && y < displayY + displayH; + } -bool Metrics::isInMinimap(int x, int y) const{ - return + bool Metrics::isInMinimap (int x, int y) const + { + return x > minimapX && - y > minimapY && - x < minimapX+minimapW && - y < minimapY+minimapH; -} + y > minimapY && x < minimapX + minimapW && y < minimapY + minimapH; + } -}}// end namespace + } +} // end namespace diff --git a/source/glest_game/global/metrics.h b/source/glest_game/global/metrics.h index 08eba250d..8a938bc1b 100644 --- a/source/glest_game/global/metrics.h +++ b/source/glest_game/global/metrics.h @@ -1,77 +1,117 @@ // ============================================================== -// This file is part of Glest (www.glest.org) +// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Martiño Figueroa // -// You can redistribute this code and/or modify it under -// the terms of the GNU General Public License as published -// by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version // ============================================================== #ifndef _GLEST_GAME_METRICS_H_ -#define _GLEST_GAME_METRICS_H_ +# define _GLEST_GAME_METRICS_H_ -#ifdef WIN32 - #include - #include -#endif +# ifdef WIN32 +# include +# include +# endif -#include "config.h" -#include "leak_dumper.h" +# include "config.h" +# include "leak_dumper.h" -namespace Glest{ namespace Game{ +namespace Glest +{ + namespace Game + { // ===================================================== -// class Metrics +// class Metrics // ===================================================== -class Metrics{ -private: - int virtualW; - int virtualH; - int screenW; - int screenH; - int minimapX; - int minimapY; - int minimapW; - int minimapH; - int displayX; - int displayY; - int displayH; - int displayW; + class Metrics + { + private: + int virtualW; + int virtualH; + int screenW; + int screenH; + int minimapX; + int minimapY; + int minimapW; + int minimapH; + int displayX; + int displayY; + int displayH; + int displayW; -private: - Metrics(); - static Metrics *getInstancePtr(); - void reloadData(int resWidth=-1, int resHeight=-1); + private: + Metrics (); + static Metrics *getInstancePtr (); + void reloadData (int resWidth = -1, int resHeight = -1); -public: - static const Metrics &getInstance(); - - int getVirtualW() const {return virtualW;} - int getVirtualH() const {return virtualH;} - int getScreenW() const {return screenW;} - int getScreenH() const {return screenH;} - int getMinimapX() const {return minimapX;} - int getMinimapY() const {return minimapY;} - int getMinimapW() const {return minimapW;} - int getMinimapH() const {return minimapH;} - int getDisplayX() const {return displayX;} - int getDisplayY() const {return displayY;} - int getDisplayH() const {return displayH;} - int getDisplayW() const {return displayW;} - float getAspectRatio() const; - - int toVirtualX(int w) const; - int toVirtualY(int h) const; + public: + static const Metrics & getInstance (); - bool isInDisplay(int x, int y) const; - bool isInMinimap(int x, int y) const; + int getVirtualW () const + { + return virtualW; + } + int getVirtualH () const + { + return virtualH; + } + int getScreenW () const + { + return screenW; + } + int getScreenH () const + { + return screenH; + } + int getMinimapX () const + { + return minimapX; + } + int getMinimapY () const + { + return minimapY; + } + int getMinimapW () const + { + return minimapW; + } + int getMinimapH () const + { + return minimapH; + } + int getDisplayX () const + { + return displayX; + } + int getDisplayY () const + { + return displayY; + } + int getDisplayH () const + { + return displayH; + } + int getDisplayW () const + { + return displayW; + } + float getAspectRatio () const; - static void reload(int resWidth=-1, int resHeight=-1); -}; + int toVirtualX (int w) const; + int toVirtualY (int h) const; -}}//end namespace + bool isInDisplay (int x, int y) const; + bool isInMinimap (int x, int y) const; + + static void reload (int resWidth = -1, int resHeight = -1); + }; + +}} //end namespace #endif