From 438b712da2a2d30f15296b4eab07a30671f06fbd Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 7 Sep 2005 01:42:47 +0000 Subject: [PATCH] Previously, theme paths searched fallback classes before themes: each class fallback was checked with the main theme, then each class fallback was checked with the base theme, and so on. Reverse this: check the class name with each theme, then check the class fallback with each theme, and so on. This is faster, since we only look up each class Fallback at most once, not once per fallback theme, and groups together theme lookups (which may allow further optimizations). More importantly, this matches the metric lookup scheme. This also makes more sense--if "ScreenWithMenuElements header" is overridden by "ScreenMenu header" in the base theme, overriding "ScreenWithMenuElements header" in a derived theme should change the same in the base theme (changing the default) but not change the specialized "ScreenMenu header". --- stepmania/src/ThemeManager.cpp | 32 +++++++++++++++----------------- stepmania/src/ThemeManager.h | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index f35aa2c2eb..4883ba0365 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -443,17 +443,20 @@ try_element_again: } } -CString ThemeManager::GetPathToAndFallback( const CString &sThemeName, ElementCategory category, const CString &sClassName_, const CString &sElement ) +CString ThemeManager::GetPathToAndFallback( ElementCategory category, const CString &sClassName_, const CString &sElement ) { CString sClassName( sClassName_ ); int n = 100; while( n-- ) { - // search with requested name - CString sRet = GetPathToRaw( sThemeName, category, sClassName, sElement ); - if( !sRet.empty() ) - return sRet; + FOREACHD_CONST( Theme, g_vThemes, iter ) + { + // search with requested name + CString sRet = GetPathToRaw( iter->sThemeName, category, sClassName, sElement ); + if( !sRet.empty() ) + return sRet; + } if( sClassName.empty() ) return CString(); @@ -465,8 +468,8 @@ CString ThemeManager::GetPathToAndFallback( const CString &sThemeName, ElementCa sClassName = sFallback; } - RageException::Throw("Infinite recursion looking up theme element from theme \"%s\", class \"%s\"", - sThemeName.c_str(), sClassName.c_str() ); + RageException::Throw( "Infinite recursion looking up theme element \"%s\"", + ClassAndElementToFileName(sClassName, sElement).c_str() ); } CString ThemeManager::GetPath( ElementCategory category, const CString &sClassName_, const CString &sElement_, bool bOptional ) @@ -489,17 +492,12 @@ CString ThemeManager::GetPath( ElementCategory category, const CString &sClassNa try_element_again: - for( deque::const_iterator iter = g_vThemes.begin(); - iter != g_vThemes.end(); - iter++ ) + // search the current theme + CString ret = GetPathToAndFallback( category, sClassName, sElement ); + if( !ret.empty() ) // we found something { - // search the current theme - CString ret = GetPathToAndFallback( iter->sThemeName, category, sClassName, sElement ); - if( !ret.empty() ) // we found something - { - Cache[sFileName] = ret; - return ret; - } + Cache[sFileName] = ret; + return ret; } if( bOptional ) diff --git a/stepmania/src/ThemeManager.h b/stepmania/src/ThemeManager.h index a2447fc965..f5046d5895 100644 --- a/stepmania/src/ThemeManager.h +++ b/stepmania/src/ThemeManager.h @@ -99,7 +99,7 @@ protected: void RunLuaScripts( const CString &sMask ); void LoadThemeRecursive( deque &theme, const CString &sThemeName ); bool GetMetricRawRecursive( const CString &sClassName, const CString &sValueName, CString &sRet ); - CString GetPathToAndFallback( const CString &sThemeName, ElementCategory category, const CString &sClassName, const CString &sFile ); + CString GetPathToAndFallback( ElementCategory category, const CString &sClassName, const CString &sFile ); CString GetPathToRaw( const CString &sThemeName, ElementCategory category, const CString &sClassName, const CString &sFile ); static CString GetThemeDirFromName( const CString &sThemeName ); CString GetElementDir( const CString &sThemeName );