From 5fd8b121a960f02413d1eb5c1128f630b739818d Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 11 Feb 2013 23:43:30 +0000 Subject: [PATCH] - allow for multiple preview / loading / hud textures for different resolutions --- source/glest_game/game/game.cpp | 56 +++++++++++++++++-- source/glest_game/game/game.h | 10 ++-- source/glest_game/game/game_constants.h | 7 +++ source/glest_game/global/config.cpp | 7 +++ source/glest_game/main/main.cpp | 6 +- .../menu/menu_state_connected_game.cpp | 2 +- .../menu/menu_state_custom_game.cpp | 2 +- 7 files changed, 75 insertions(+), 15 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index d999aec5..03b5868a 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -528,9 +528,55 @@ string Game::extractFactionLogoFile(bool &loadingImageUsed, string factionName, endPathWithSlash(path); vector loadScreenList; - findAll(path + factionLogoFilter, loadScreenList, false, false); + string logoFullPathFilter = path + factionLogoFilter; + findAll(logoFullPathFilter, loadScreenList, false, false); if(loadScreenList.empty() == false) { - string factionLogo = path + loadScreenList[0]; + int bestLogoIndex = 0; + + if(loadScreenList.size() > 1 && EndsWith(factionLogoFilter, ".xml") == false) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nLooking for best logo from a list of: " MG_SIZE_T_SPECIFIER " using filter: [%s]\n",loadScreenList.size(),logoFullPathFilter.c_str()); + + + int bestMinWidthDiff = INT_MAX; + int bestMinHeightDiff = INT_MAX; + // Now find the best texture for our screen + // Texture2D *result = preloadTexture(logoFilename); + for(unsigned int logoIndex = 0; logoIndex < loadScreenList.size(); ++logoIndex) { + string factionLogo = path + loadScreenList[logoIndex]; + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for loading screen '%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,factionLogo.c_str()); + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Looking for best logo: %u [%s]\n",logoIndex,factionLogo.c_str()); + + if(fileExists(factionLogo) == true) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found loading screen '%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,factionLogo.c_str()); + + Texture2D *checkLogo = Renderer::preloadTexture(factionLogo); + if(checkLogo != NULL) { + const Metrics &metrics= Metrics::getInstance(); + int minWidthDifference = abs(metrics.getScreenW() - checkLogo->getPixmapConst()->getW()); + int minHeightDifference = abs(metrics.getScreenH() - checkLogo->getPixmapConst()->getH()); + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Logo info: %d x %d (%d,%d)\n",checkLogo->getPixmapConst()->getW(),checkLogo->getPixmapConst()->getH(),minWidthDifference,minHeightDifference); + + if(minWidthDifference < bestMinWidthDiff) { + bestMinWidthDiff = minWidthDifference; + + bestLogoIndex = logoIndex; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 New best logo is [%s]\n",factionLogo.c_str()); + } + else if(minWidthDifference == bestMinWidthDiff && + minHeightDifference < bestMinHeightDiff) { + bestMinHeightDiff = minHeightDifference; + + bestLogoIndex = logoIndex; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 New best logo is [%s]\n",factionLogo.c_str()); + } + } + } + } + } + + string factionLogo = path + loadScreenList[bestLogoIndex]; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for loading screen '%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,factionLogo.c_str()); if(fileExists(factionLogo) == true) { @@ -698,7 +744,7 @@ void Game::loadHudTexture(const GameSettings *settings) vector hudList; string path= currentPath + techName + "/" + "factions" + "/" + factionName; endPathWithSlash(path); - findAll(path + "hud.*", hudList, false, false); + findAll(path + GameConstants::HUD_SCREEN_FILE_FILTER, hudList, false, false); if(hudList.empty() == false){ for(unsigned int hudIdx = 0; hudFound == false && hudIdx < hudList.size(); ++hudIdx) { string hudImageFileName= path + hudList[hudIdx]; @@ -800,7 +846,7 @@ vector Game::processTech(string techName) { "", techName, NULL, - "preview_screen.*"); + GameConstants::PREVIEW_SCREEN_FILE_FILTER); if(factionLogo == "") { factionLogo = Game::extractFactionLogoFile( @@ -809,7 +855,7 @@ vector Game::processTech(string techName) { "", techName, NULL, - "loading_screen.*"); + GameConstants::LOADING_SCREEN_FILE_FILTER); } if(factionLogo != "") { Texture2D *texture = Renderer::preloadTexture(factionLogo); diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index ecaa4624..8f624f8f 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -277,11 +277,11 @@ public: void endPerformanceTimer(); Vec2i getPerformanceTimerResults(); - static Texture2D * findFactionLogoTexture(const GameSettings *settings, Logger *logger=NULL,string factionLogoFilter="loading_screen.*", bool useTechDefaultIfFilterNotFound=true); - static string findFactionLogoFile(const GameSettings *settings, Logger *logger=NULL, string factionLogoFilter="loading_screen.*"); - static string extractScenarioLogoFile(const GameSettings *settings, string &result, bool &loadingImageUsed, Logger *logger=NULL, string factionLogoFilter="loading_screen.*"); - static string extractFactionLogoFile(bool &loadingImageUsed, string factionName, string scenarioDir, string techName, Logger *logger=NULL, string factionLogoFilter="loading_screen.*"); - static string extractTechLogoFile(string scenarioDir, string techName, bool &loadingImageUsed, Logger *logger=NULL,string factionLogoFilter="loading_screen.*"); + static Texture2D * findFactionLogoTexture(const GameSettings *settings, Logger *logger=NULL,string factionLogoFilter=GameConstants::LOADING_SCREEN_FILE_FILTER, bool useTechDefaultIfFilterNotFound=true); + static string findFactionLogoFile(const GameSettings *settings, Logger *logger=NULL, string factionLogoFilter=GameConstants::LOADING_SCREEN_FILE_FILTER); + static string extractScenarioLogoFile(const GameSettings *settings, string &result, bool &loadingImageUsed, Logger *logger=NULL, string factionLogoFilter=GameConstants::LOADING_SCREEN_FILE_FILTER); + static string extractFactionLogoFile(bool &loadingImageUsed, string factionName, string scenarioDir, string techName, Logger *logger=NULL, string factionLogoFilter=GameConstants::LOADING_SCREEN_FILE_FILTER); + static string extractTechLogoFile(string scenarioDir, string techName, bool &loadingImageUsed, Logger *logger=NULL,string factionLogoFilter=GameConstants::LOADING_SCREEN_FILE_FILTER); void loadHudTexture(const GameSettings *settings); diff --git a/source/glest_game/game/game_constants.h b/source/glest_game/game/game_constants.h index e4a88879..5d23cef9 100644 --- a/source/glest_game/game/game_constants.h +++ b/source/glest_game/game/game_constants.h @@ -174,6 +174,13 @@ public: static const float megaMultiplier; // + static const char * LOADING_SCREEN_FILE; + static const char * LOADING_SCREEN_FILE_FILTER; + static const char * PREVIEW_SCREEN_FILE; + static const char * PREVIEW_SCREEN_FILE_FILTER; + static const char * HUD_SCREEN_FILE; + static const char * HUD_SCREEN_FILE_FILTER; + }; enum PathType { diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index 8d9b4d63..e743d7bb 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -56,6 +56,13 @@ const char *GameConstants::factionPreviewTextureCacheLookupKey = "factionPrevie const char *GameConstants::characterMenuScreenPositionListCacheLookupKey = "characterMenuScreenPositionListCache"; const char *GameConstants::application_name = "MegaGlest"; +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"; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 63c7f32f..d3c1ea37 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2058,9 +2058,9 @@ void runTechValidationForPath(string techPath, string techName, replaceAll(file, "//", "/"); replaceAll(file, "\\\\", "\\"); - if( file.find("loading_screen") != string::npos || - file.find("preview_screen") != string::npos || - file.find("hud") != string::npos) { + if( file.find(GameConstants::LOADING_SCREEN_FILE) != string::npos || + file.find(GameConstants::PREVIEW_SCREEN_FILE) != string::npos || + file.find(GameConstants::HUD_SCREEN_FILE) != string::npos) { continue; } if(file.find("/factions/") != string::npos) { diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 31835264..3231b972 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -4514,7 +4514,7 @@ void MenuStateConnectedGame::initFactionPreview(const GameSettings *gameSettings } if(factionVideo == NULL) { - string factionLogo = Game::findFactionLogoFile(gameSettings, NULL,"preview_screen.*"); + string factionLogo = Game::findFactionLogoFile(gameSettings, NULL,GameConstants::PREVIEW_SCREEN_FILE_FILTER); if(factionLogo == "") { factionLogo = Game::findFactionLogoFile(gameSettings, NULL); } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 3854f5d6..f2f14bae 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2798,7 +2798,7 @@ void MenuStateCustomGame::initFactionPreview(const GameSettings *gameSettings) { } if(factionVideo == NULL) { - string factionLogo = Game::findFactionLogoFile(gameSettings, NULL,"preview_screen.*"); + string factionLogo = Game::findFactionLogoFile(gameSettings, NULL,GameConstants::PREVIEW_SCREEN_FILE_FILTER); if(factionLogo == "") { factionLogo = Game::findFactionLogoFile(gameSettings, NULL); }