From a0a61d4519444a4991a231693d2571ab56b8600d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 7 Sep 2005 00:52:31 +0000 Subject: [PATCH] implement without (deep) recursion --- stepmania/src/ThemeManager.cpp | 29 +++++++++++++++++------------ stepmania/src/ThemeManager.h | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 6f834f35d8..f35aa2c2eb 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -581,25 +581,30 @@ void ThemeManager::ReloadMetrics() } -bool ThemeManager::GetMetricRawRecursive( const CString &sClassName, const CString &sValueName, CString &ret, int level ) +bool ThemeManager::GetMetricRawRecursive( const CString &sClassName_, const CString &sValueName, CString &sOut ) { - if( level > 100 ) - RageException::Throw("Infinite recursion looking up theme metric \"%s::%s\"", sClassName.c_str(), sValueName.c_str() ); + CString sClassName( sClassName_ ); - FOREACHD_CONST( Theme, g_vThemes, iter ) + int n = 100; + while( n-- ) { - if( iter->iniMetrics->GetValue(sClassName,sValueName,ret) ) - return true; - } + FOREACHD_CONST( Theme, g_vThemes, iter ) + { + if( iter->iniMetrics->GetValue(sClassName,sValueName,sOut) ) + return true; + } + + if( !sValueName.compare("Fallback") ) + return false; - FOREACHD_CONST( Theme, g_vThemes, iter ) - { CString sFallback; - if( iter->iniMetrics->GetValue(sClassName,"Fallback",sFallback) ) - return GetMetricRawRecursive(sFallback,sValueName,ret,level+1); + if( !GetMetricRawRecursive(sClassName,"Fallback",sFallback) ) + return false; + + sClassName = sFallback; } - return false; + RageException::Throw( "Infinite recursion looking up theme metric \"%s::%s\"", sClassName.c_str(), sValueName.c_str() ); } CString ThemeManager::GetMetricRaw( const CString &sClassName_, const CString &sValueName_ ) diff --git a/stepmania/src/ThemeManager.h b/stepmania/src/ThemeManager.h index 8cbe25299d..a2447fc965 100644 --- a/stepmania/src/ThemeManager.h +++ b/stepmania/src/ThemeManager.h @@ -98,7 +98,7 @@ public: protected: void RunLuaScripts( const CString &sMask ); void LoadThemeRecursive( deque &theme, const CString &sThemeName ); - bool GetMetricRawRecursive( const CString &sClassName, const CString &sValueName, CString &ret, int level=0 ); + bool GetMetricRawRecursive( const CString &sClassName, const CString &sValueName, CString &sRet ); CString GetPathToAndFallback( const CString &sThemeName, 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 );