From e2cf64fe550840f08b98cc236667941dbbfb9aef Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 21 May 2004 05:21:03 +0000 Subject: [PATCH] cache GetCourseDifficultiesToShow results --- stepmania/src/GameState.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index bb6316c124..1bb0d45b5e 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1648,26 +1648,37 @@ bool GameState::ChangeDifficulty( PlayerNumber pn, int dir ) return ChangeDifficulty( pn, diff ); } -static set GetCourseDifficultiesToShow() +static void 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 ); - set ret; + cache.clear(); for( unsigned i = 0; i < asDiff.size(); ++i ) { CourseDifficulty cd = StringToCourseDifficulty(asDiff[i]); if( cd == NUM_COURSE_DIFFICULTIES ) RageException::Throw( "Unknown difficulty \"%s\" in CourseDifficultiesToShow", asDiff[i].c_str() ); - ret.insert( cd ); + cache.insert( cd ); } - return ret; + + fExpiration = RageTimer::GetTimeSinceStart()+1; + ret = cache; } bool GameState::ChangeCourseDifficulty( PlayerNumber pn, int dir ) { - const set asDiff = GetCourseDifficultiesToShow(); + set asDiff; + GetCourseDifficultiesToShow( asDiff ); CourseDifficulty cd = m_PreferredCourseDifficulty[pn]; do { @@ -1687,7 +1698,8 @@ bool GameState::ChangeCourseDifficulty( PlayerNumber pn, int dir ) bool GameState::IsCourseDifficultyShown( CourseDifficulty cd ) { - const set asDiff = GetCourseDifficultiesToShow(); + set asDiff; + GetCourseDifficultiesToShow( asDiff ); return asDiff.find(cd) != asDiff.end(); }