From 8b323839698851933046779c16f7dba4f8db082c Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Thu, 10 Mar 2005 19:57:43 +0000 Subject: [PATCH] move DifficultiesToShow into CommonMetrics re-cache on theme reload, not on timer expired --- stepmania/src/CatalogXml.cpp | 17 ++++---- stepmania/src/CommonMetrics.cpp | 62 ++++++++++++++++++++++++++++- stepmania/src/CommonMetrics.h | 8 +++- stepmania/src/Course.cpp | 2 + stepmania/src/DifficultyList.cpp | 23 +++++------ stepmania/src/GameState.cpp | 64 ++---------------------------- stepmania/src/GameState.h | 6 --- stepmania/src/OptionRowHandler.cpp | 4 +- stepmania/src/ScreenEnding.cpp | 13 +++--- 9 files changed, 98 insertions(+), 101 deletions(-) diff --git a/stepmania/src/CatalogXml.cpp b/stepmania/src/CatalogXml.cpp index dc5c45df3b..faf2e90de5 100644 --- a/stepmania/src/CatalogXml.cpp +++ b/stepmania/src/CatalogXml.cpp @@ -18,6 +18,7 @@ #include "ThemeManager.h" #include "PrefsManager.h" #include "Style.h" +#include "CommonMetrics.h" #define SHOW_PLAY_MODE(pm) THEME->GetMetricB("CatalogXml",ssprintf("ShowPlayMode%s",PlayModeToString(pm).c_str())) #define SHOW_STYLE(ps) THEME->GetMetricB("CatalogXml",ssprintf("ShowStyle%s",Capitalize((ps)->m_szName).c_str())) @@ -63,8 +64,7 @@ void SaveCatalogXml() pSongNode->AppendChild( "MainTitle", pSong->GetDisplayMainTitle() ); pSongNode->AppendChild( "SubTitle", pSong->GetDisplaySubTitle() ); - set vDiffs; - GAMESTATE->GetDifficultiesToShow( vDiffs ); + const set &vDiffs = CommonMetrics::GetDifficultiesToShow(); FOREACH_StepsType( st ) { @@ -111,8 +111,7 @@ void SaveCatalogXml() pCourseNode->AppendChild( "SubTitle", pCourse->GetDisplaySubTitle() ); pCourseNode->AppendChild( "HasMods", pCourse->HasMods() ); - set vDiffs; - GAMESTATE->GetCourseDifficultiesToShow( vDiffs ); + const set &vDiffs = CommonMetrics::GetCourseDifficultiesToShow(); FOREACH_StepsType( st ) { @@ -144,9 +143,8 @@ void SaveCatalogXml() XNode* pNode = xml.AppendChild( "Types" ); { - set vDiffs; - GAMESTATE->GetDifficultiesToShow( vDiffs ); - for( set::const_iterator iter = vDiffs.begin(); iter != vDiffs.end(); iter++ ) + const set &vDiffs = CommonMetrics::GetDifficultiesToShow(); + FOREACHS_CONST( Difficulty, vDiffs, iter ) { XNode* pNode2 = pNode->AppendChild( "Difficulty", DifficultyToString(*iter) ); pNode2->AppendAttr( "DisplayAs", DifficultyToThemedString(*iter) ); @@ -154,9 +152,8 @@ void SaveCatalogXml() } { - set vDiffs; - GAMESTATE->GetCourseDifficultiesToShow( vDiffs ); - for( set::const_iterator iter = vDiffs.begin(); iter != vDiffs.end(); iter++ ) + const set &vDiffs = CommonMetrics::GetCourseDifficultiesToShow(); + FOREACHS_CONST( CourseDifficulty, vDiffs, iter ) { XNode* pNode2 = pNode->AppendChild( "CourseDifficulty", CourseDifficultyToString(*iter) ); pNode2->AppendAttr( "DisplayAs", CourseDifficultyToThemedString(*iter) ); diff --git a/stepmania/src/CommonMetrics.cpp b/stepmania/src/CommonMetrics.cpp index 72735e6e94..1b9ca492c5 100644 --- a/stepmania/src/CommonMetrics.cpp +++ b/stepmania/src/CommonMetrics.cpp @@ -1,16 +1,15 @@ #include "global.h" #include "CommonMetrics.h" #include "RageUtil.h" +#include "Foreach.h" CString PLAYER_COLOR_NAME( size_t p ) { return ssprintf("ColorP%d",p+1); } -ThemeMetric DIFFICULTIES_TO_SHOW ("Common","DifficultiesToShow"); ThemeMetric INITIAL_SCREEN ("Common","InitialScreen"); ThemeMetric FIRST_RUN_INITIAL_SCREEN ("Common","FirstRunInitialScreen"); ThemeMetric DEFAULT_MODIFIERS ("Common","DefaultModifiers" ); ThemeMetric DEFAULT_CPU_MODIFIERS ("Common","DefaultCpuModifiers" ); -ThemeMetric COURSE_DIFFICULTIES_TO_SHOW ("Common","CourseDifficultiesToShow"); ThemeMetric1D PLAYER_COLOR ("Common",PLAYER_COLOR_NAME,NUM_PLAYERS); ThemeMetric JOIN_PAUSE_SECONDS ("Common","JoinPauseSeconds"); ThemeMetric WINDOW_TITLE ("Common","WindowTitle"); @@ -18,6 +17,65 @@ ThemeMetric HOME_EDIT_MODE ("Common","HomeEditMode"); ThemeMetric MAX_STEPS_LOADED_FROM_PROFILE ("Common","MaxStepsLoadedFromProfile"); +class ThemeMetricDifficultiesToShow : ThemeMetric +{ +public: + set m_v; + + ThemeMetricDifficultiesToShow() : ThemeMetric("Common","DifficultiesToShow") {} + void Read() + { + ThemeMetric::Read(); + + m_v.clear(); + + CStringArray v; + split( GetValue(), ",", v ); + ASSERT( v.size() > 0 ); + + FOREACH_CONST( CString, v, i ) + { + Difficulty d = StringToDifficulty( *i ); + if( d == DIFFICULTY_INVALID ) + RageException::Throw( "Unknown difficulty \"%s\" in CourseDifficultiesToShow", i->c_str() ); + m_v.insert( d ); + } + } +}; +ThemeMetricDifficultiesToShow DIFFICULTIES_TO_SHOW; +const set& CommonMetrics::GetDifficultiesToShow() { return DIFFICULTIES_TO_SHOW.m_v; } + + +class ThemeMetricCourseDifficultiesToShow : ThemeMetric +{ +public: + set m_v; + + ThemeMetricCourseDifficultiesToShow() : ThemeMetric("Common","CourseDifficultiesToShow") {} + void Read() + { + ThemeMetric::Read(); + + m_v.clear(); + + CStringArray v; + split( GetValue(), ",", v ); + ASSERT( v.size() > 0 ); + + FOREACH_CONST( CString, v, i ) + { + CourseDifficulty d = StringToCourseDifficulty( *i ); + if( d == DIFFICULTY_INVALID ) + RageException::Throw( "Unknown CourseDifficulty \"%s\" in CourseDifficultiesToShow", i->c_str() ); + m_v.insert( d ); + } + } +}; +ThemeMetricCourseDifficultiesToShow COURSE_DIFFICULTIES_TO_SHOW; +const set& CommonMetrics::GetCourseDifficultiesToShow() { return COURSE_DIFFICULTIES_TO_SHOW.m_v; } + + + /* * (c) 2001-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/CommonMetrics.h b/stepmania/src/CommonMetrics.h index d72ad75175..4b7d28223d 100644 --- a/stepmania/src/CommonMetrics.h +++ b/stepmania/src/CommonMetrics.h @@ -5,19 +5,23 @@ #include "ThemeMetric.h" #include "PlayerNumber.h" +#include "Difficulty.h" -extern ThemeMetric DIFFICULTIES_TO_SHOW; extern ThemeMetric INITIAL_SCREEN; extern ThemeMetric FIRST_RUN_INITIAL_SCREEN; extern ThemeMetric DEFAULT_MODIFIERS; extern ThemeMetric DEFAULT_CPU_MODIFIERS; -extern ThemeMetric COURSE_DIFFICULTIES_TO_SHOW; extern ThemeMetric1D PLAYER_COLOR; extern ThemeMetric JOIN_PAUSE_SECONDS; extern ThemeMetric WINDOW_TITLE; extern ThemeMetric HOME_EDIT_MODE; extern ThemeMetric MAX_STEPS_LOADED_FROM_PROFILE; +namespace CommonMetrics +{ + const set& GetDifficultiesToShow(); + const set& GetCourseDifficultiesToShow(); +} #endif diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 83d7254954..e5e7bdc3f0 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -275,7 +275,9 @@ void Course::LoadFromCRSFile( CString sPath ) m_RadarCache[CacheEntry(st, cd)] = rv; } else + { LOG->Trace( "Unexpected value named '%s'", sValueName.c_str() ); + } } static TitleSubst tsub("courses"); diff --git a/stepmania/src/DifficultyList.cpp b/stepmania/src/DifficultyList.cpp index d76d5773e6..59f18b3773 100644 --- a/stepmania/src/DifficultyList.cpp +++ b/stepmania/src/DifficultyList.cpp @@ -12,6 +12,7 @@ #include "StepsUtil.h" #include "CommonMetrics.h" #include "Command.h" +#include "Foreach.h" #define MAX_METERS NUM_DIFFICULTIES + MAX_EDITS_PER_SONG @@ -283,27 +284,25 @@ void DifficultyList::SetFromGameState() // FIXME: This clamps to between the min and the max difficulty, but // it really should round to the nearest difficulty that's in // DIFFICULTIES_TO_SHOW. - CStringArray asDiff; - split( DIFFICULTIES_TO_SHOW.GetValue(), ",", asDiff ); - for( unsigned i=0; i &diffs = CommonMetrics::GetDifficultiesToShow(); + unsigned i=0; + FOREACHS_CONST( Difficulty, diffs, d ) { - Difficulty d = StringToDifficulty( asDiff[i] ); - if( d == DIFFICULTY_INVALID ) - continue; - m_Rows.resize( m_Rows.size()+1 ); Row &row = m_Rows.back(); - row.m_dc = d; + row.m_dc = *d; - m_Lines[i].m_Meter.SetFromMeterAndDifficulty( 3*(d), d ); + m_Lines[i].m_Meter.SetFromMeterAndDifficulty( 3*(*d), *d ); - m_Lines[i].m_Description.SetText( GetDifficultyString(d) ); - m_Lines[i].m_Description.SetDiffuseColor( SONGMAN->GetDifficultyColor(d) ); + m_Lines[i].m_Description.SetText( GetDifficultyString(*d) ); + m_Lines[i].m_Description.SetDiffuseColor( SONGMAN->GetDifficultyColor(*d) ); - m_Lines[i].m_Number.SetDiffuseColor( SONGMAN->GetDifficultyColor(d) ); + m_Lines[i].m_Number.SetDiffuseColor( SONGMAN->GetDifficultyColor(*d) ); m_Lines[i].m_Number.SetText( "?" ); + + i++; } } else diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index b767f936e1..7993e72dbc 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -31,6 +31,7 @@ #include "PlayerState.h" #include "Style.h" #include "MessageManager.h" +#include "CommonMetrics.h" #include #include @@ -1658,37 +1659,9 @@ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc ) return true; } -void GameState::GetDifficultiesToShow( set &ret ) -{ - static float fExpiration = -999; - static set cache; - if( RageTimer::GetTimeSinceStart() < fExpiration ) - { - ret = cache; - return; - } - - CStringArray asDiff; - split( DIFFICULTIES_TO_SHOW, ",", asDiff ); - ASSERT( asDiff.size() > 0 ); - - cache.clear(); - for( unsigned i = 0; i < asDiff.size(); ++i ) - { - Difficulty d = StringToDifficulty(asDiff[i]); - if( d == DIFFICULTY_INVALID ) - RageException::Throw( "Unknown difficulty \"%s\" in CourseDifficultiesToShow", asDiff[i].c_str() ); - cache.insert( d ); - } - - fExpiration = RageTimer::GetTimeSinceStart()+1; - ret = cache; -} - bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir ) { - set asDiff; - GetDifficultiesToShow( asDiff ); + const set &asDiff = CommonMetrics::GetDifficultiesToShow(); Difficulty d = m_PreferredDifficulty[pn]; while( 1 ) @@ -1703,33 +1676,6 @@ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir ) return ChangePreferredDifficulty( pn, d ); } -void GameState::GetCourseDifficultiesToShow( set &ret ) -{ - static float fExpiration = -999; - static set cache; - if( RageTimer::GetTimeSinceStart() < fExpiration ) - { - ret = cache; - return; - } - - CStringArray asDiff; - split( COURSE_DIFFICULTIES_TO_SHOW, ",", asDiff ); - ASSERT( asDiff.size() > 0 ); - - cache.clear(); - for( unsigned i = 0; i < asDiff.size(); ++i ) - { - CourseDifficulty cd = StringToCourseDifficulty(asDiff[i]); - if( cd == DIFFICULTY_INVALID ) - RageException::Throw( "Unknown difficulty \"%s\" in CourseDifficultiesToShow", asDiff[i].c_str() ); - cache.insert( cd ); - } - - fExpiration = RageTimer::GetTimeSinceStart()+1; - ret = cache; -} - bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, CourseDifficulty cd ) { m_PreferredCourseDifficulty[pn].Set( cd ); @@ -1747,8 +1693,7 @@ bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, int dir ) /* If we have a course selected, only choose among difficulties available in the course. */ const Course *pCourse = this->m_pCurCourse; - set asDiff; - GetCourseDifficultiesToShow( asDiff ); + const set &asDiff = CommonMetrics::GetCourseDifficultiesToShow(); CourseDifficulty cd = m_PreferredCourseDifficulty[pn]; while( 1 ) @@ -1767,8 +1712,7 @@ bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, int dir ) bool GameState::IsCourseDifficultyShown( CourseDifficulty cd ) { - set asDiff; - GetCourseDifficultiesToShow( asDiff ); + const set &asDiff = CommonMetrics::GetCourseDifficultiesToShow(); return asDiff.find(cd) != asDiff.end(); } diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 29e97ffc72..ccf46c9454 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -261,12 +261,6 @@ public: int m_iNumTimesThroughAttract; // negative means play regardless of m_iAttractSoundFrequency setting bool IsTimeToPlayAttractSounds(); - // - // DifficultiesToShow stuff - // - void GetDifficultiesToShow( set &AddTo ); - void GetCourseDifficultiesToShow( set &AddTo ); - // // PlayerState // diff --git a/stepmania/src/OptionRowHandler.cpp b/stepmania/src/OptionRowHandler.cpp index 1ffdd49342..45dcee064d 100644 --- a/stepmania/src/OptionRowHandler.cpp +++ b/stepmania/src/OptionRowHandler.cpp @@ -18,6 +18,7 @@ #include "Foreach.h" #include "ScreenManager.h" #include "GameSoundManager.h" +#include "CommonMetrics.h" #define ENTRY(s) THEME->GetMetric ("ScreenOptionsMaster",s) #define ENTRY_MODE(s,i) THEME->GetMetric ("ScreenOptionsMaster",ssprintf("%s,%i",(s).c_str(),(i+1))) @@ -451,8 +452,7 @@ public: ASSERT( sParam.size() ); m_sName = sParam; - set vDifficulties; - GAMESTATE->GetDifficultiesToShow( vDifficulties ); + const set &vDifficulties = CommonMetrics::GetDifficultiesToShow(); defOut.bOneChoiceForAllPlayers = true; defOut.name = "Difficulty"; diff --git a/stepmania/src/ScreenEnding.cpp b/stepmania/src/ScreenEnding.cpp index 91d3f64deb..d49a699ce0 100644 --- a/stepmania/src/ScreenEnding.cpp +++ b/stepmania/src/ScreenEnding.cpp @@ -18,6 +18,8 @@ #include "StatsManager.h" #include "PlayerState.h" #include "BGAnimation.h" +#include "CommonMetrics.h" +#include "Foreach.h" #define SCROLL_DELAY THEME->GetMetricF("ScreenEnding","ScrollDelay") @@ -25,7 +27,6 @@ #define TEXT_ZOOM THEME->GetMetricF("ScreenEnding","TextZoom") - CString GetStatsLineTitle( PlayerNumber pn, EndingStatsLine line ) { switch( line ) @@ -83,9 +84,8 @@ CString GetStatsLineValue( PlayerNumber pn, EndingStatsLine line ) if( GAMESTATE->IsCourseMode() ) { - set vDiffs; - GAMESTATE->GetCourseDifficultiesToShow( vDiffs ); - for( set::iterator iter = vDiffs.begin(); iter != vDiffs.end(); iter++ ) + const set &vDiffs = CommonMetrics::GetCourseDifficultiesToShow(); + FOREACHS_CONST( CourseDifficulty, vDiffs, iter ) { fActual += pProfile->GetCoursesActual(st,*iter); fPossible += pProfile->GetCoursesPossible(st,*iter); @@ -93,9 +93,8 @@ CString GetStatsLineValue( PlayerNumber pn, EndingStatsLine line ) } else { - set vDiffs; - GAMESTATE->GetDifficultiesToShow( vDiffs ); - for( set::iterator iter = vDiffs.begin(); iter != vDiffs.end(); iter++ ) + const set &vDiffs = CommonMetrics::GetDifficultiesToShow(); + FOREACHS_CONST( Difficulty, vDiffs, iter ) { fActual += pProfile->GetSongsActual(st,*iter); fPossible += pProfile->GetSongsPossible(st,*iter);