diff --git a/stepmania/src/ScreenManager.cpp b/stepmania/src/ScreenManager.cpp index be2727d6b7..6440372318 100644 --- a/stepmania/src/ScreenManager.cpp +++ b/stepmania/src/ScreenManager.cpp @@ -28,6 +28,7 @@ #include "Quad.h" #include "RageTextureManager.h" #include "ProfileManager.h" +#include "ThemeManager.h" ScreenManager* SCREENMAN = NULL; // global and accessable from anywhere in our program @@ -467,6 +468,7 @@ void ScreenManager::DeletePreppedScreen() void ScreenManager::SetNewScreen( Screen *pNewScreen ) { RefreshCreditsMessages(); + THEME->ReloadMetricsIfNecessary(); // move current screen(s) to ScreenToDelete m_ScreensToDelete.insert(m_ScreensToDelete.end(), m_ScreenStack.begin(), m_ScreenStack.end()); diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 4f3d0c6fd0..820808a053 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -25,6 +25,7 @@ #include "arch/ArchHooks/ArchHooks.h" #include "arch/arch.h" #include "RageFile.h" +#include "ScreenManager.h" ThemeManager* THEME = NULL; // global object accessable from anywhere in the program @@ -306,13 +307,6 @@ try_element_again: CString ThemeManager::GetPathTo( ElementCategory category, CString sFileName, bool bOptional ) { - if ( m_ThemePathCacheTimer.PeekDeltaTime() >= 5 ) - { - m_ThemePathCacheTimer.GetDeltaTime(); - for( int i = 0; i < NUM_ELEMENT_CATEGORIES; ++i ) - g_ThemePathCache[i].clear(); - } - map &Cache = g_ThemePathCache[category]; { map::const_iterator i; @@ -394,6 +388,29 @@ bool ThemeManager::HasMetric( CString sClassName, CString sValueName ) return m_pIniMetrics->GetValue(sClassName,sValueName,sThrowAway); } +void ThemeManager::ReloadMetricsIfNecessary() +{ + // + // reload metrics if file has changed + // + CString sCurMetricPath = GetMetricsIniPath(m_sCurThemeName); + CString sDefaultMetricPath = GetMetricsIniPath(BASE_THEME_NAME); + + if( m_uHashForCurThemeMetrics != GetHashForFile(sCurMetricPath) || + m_uHashForBaseThemeMetrics != GetHashForFile(sDefaultMetricPath) ) + { + SCREENMAN->SystemMessage( "Reloading metrics" ); + SwitchThemeAndLanguage(m_sCurThemeName, m_sCurLanguage); // force a reload of the metrics cache + } + + // + // clear theme path cache + // + for( int i = 0; i < NUM_ELEMENT_CATEGORIES; ++i ) + g_ThemePathCache[i].clear(); +} + + CString ThemeManager::GetMetricRaw( CString sClassName, CString sValueName ) { #if defined(DEBUG) && defined(WIN32) @@ -402,22 +419,6 @@ try_metric_again: CString sCurMetricPath = GetMetricsIniPath(m_sCurThemeName); CString sDefaultMetricPath = GetMetricsIniPath(BASE_THEME_NAME); - // Is our metric cache out of date? - if ( !m_uHashForBaseThemeMetrics || m_ReloadTimer.PeekDeltaTime() >= 1 ) - { - m_ReloadTimer.GetDeltaTime(); - - if( m_uHashForCurThemeMetrics != GetHashForFile(sCurMetricPath) || - m_uHashForBaseThemeMetrics != GetHashForFile(sDefaultMetricPath) ) - { - if(m_uHashForBaseThemeMetrics) - { - LOG->Warn( "Metrics file is out of date. Reloading..." ); -// MessageBeep( MB_OK ); - } - SwitchThemeAndLanguage(m_sCurThemeName, m_sCurLanguage); // force a reload of the metrics cache - } - } CString sValue; if( m_pIniMetrics->GetValue(sClassName,sValueName,sValue) ) diff --git a/stepmania/src/ThemeManager.h b/stepmania/src/ThemeManager.h index 66ad1f82e1..fe1ebf6171 100644 --- a/stepmania/src/ThemeManager.h +++ b/stepmania/src/ThemeManager.h @@ -34,6 +34,7 @@ public: CString GetCurLanguage() { return m_sCurLanguage; }; CString GetCurThemeDir() { return GetThemeDirFromName(m_sCurThemeName); }; void NextTheme(); + void ReloadMetricsIfNecessary(); CString GetPathTo( ElementCategory category, CString sFileName, bool bOptional=false ); CString GetPathToB( CString sFileName, bool bOptional=false ) { return GetPathTo(BGAnimations,sFileName,bOptional); }; @@ -69,8 +70,6 @@ protected: unsigned m_uHashForBaseThemeCurLanguage; unsigned m_uHashForCurThemeBaseLanguage; unsigned m_uHashForBaseThemeBaseLanguage; - RageTimer m_ReloadTimer; - RageTimer m_ThemePathCacheTimer; }; extern ThemeManager* THEME; // global and accessable from anywhere in our program