From 6ca3046d2e9b932b8f3417c72b27fb873d1dc33e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 21 May 2004 05:39:35 +0000 Subject: [PATCH] optimize: reduce theme calls --- stepmania/src/ProfileHtml.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/stepmania/src/ProfileHtml.cpp b/stepmania/src/ProfileHtml.cpp index 2ce32e7f6e..b2a3e24b39 100644 --- a/stepmania/src/ProfileHtml.cpp +++ b/stepmania/src/ProfileHtml.cpp @@ -954,6 +954,24 @@ bool PrintRecentScores( RageFile &f, const Profile *pProfile, CString sTitle, ve return true; } +/* (experimental) Short-term internal cache timer. */ +struct CacheTimer +{ + float fExpiration, fDuration; + CacheTimer( float duration = 1 ) { fExpiration = -999; fDuration = duration; } + + /* Return true if the timer has expired (fDuration has elapsed since the last + * true IsExpired call) or if this is the first call. */ + bool IsExpired() + { + float fNow = RageTimer::GetTimeSinceStart(); + if( fNow < fExpiration ) + return false; + fExpiration = fNow + fDuration; + return true; + } +}; + bool PrintCatalogForSong( RageFile &f, const Profile *pProfile, Song* pSong ) { if( pSong->NeverDisplayed() || UNLOCKMAN->SongIsLocked(pSong) ) @@ -961,12 +979,17 @@ bool PrintCatalogForSong( RageFile &f, const Profile *pProfile, Song* pSong ) vector vpSteps = pSong->GetAllSteps(); - bool bShowRadarCategory[NUM_RADAR_CATEGORIES]; - CString sThemedRadarCategory[NUM_RADAR_CATEGORIES]; - FOREACH_RadarCategory(rc) + static bool bShowRadarCategory[NUM_RADAR_CATEGORIES]; + static CString sThemedRadarCategory[NUM_RADAR_CATEGORIES]; + + static CacheTimer timer; + if( timer.IsExpired() ) { - bShowRadarCategory[rc] = SHOW_RADAR_CATEGORY(rc); - sThemedRadarCategory[rc] = RadarCategoryToThemedString(rc); + FOREACH_RadarCategory(rc) + { + bShowRadarCategory[rc] = SHOW_RADAR_CATEGORY(rc); + sThemedRadarCategory[rc] = RadarCategoryToThemedString(rc); + } } PRINT_OPEN(f, pSong->GetFullDisplayTitle() );