StepsID cache needs both Song and Steps

This commit is contained in:
Chris Danford
2004-11-24 16:42:05 +00:00
parent 8e476b97c0
commit 243d63094f
+10 -5
View File
@@ -140,17 +140,22 @@ void StepsID::FromSteps( const Steps *p )
* them back out (which we don't do except in the editor), it won't be permanent. * them back out (which we don't do except in the editor), it won't be permanent.
* We could do this during the actual Steps::GetID() call, instead, but then it'd have * We could do this during the actual Steps::GetID() call, instead, but then it'd have
* to have access to Song::m_LoadedFromProfile. */ * to have access to Song::m_LoadedFromProfile. */
typedef pair<SongID,StepsID> SongIDAndStepsID;
static map<SongIDAndStepsID,Steps *> g_Cache;
static map<StepsID,Steps *> g_StepsIDCache;
Steps *StepsID::ToSteps( const Song *p, bool bAllowNull, bool bUseCache ) const Steps *StepsID::ToSteps( const Song *p, bool bAllowNull, bool bUseCache ) const
{ {
if( st == STEPS_TYPE_INVALID || dc == DIFFICULTY_INVALID ) if( st == STEPS_TYPE_INVALID || dc == DIFFICULTY_INVALID )
return NULL; return NULL;
SongID songID;
songID.FromSong( p );
SongIDAndStepsID sas = SongIDAndStepsID(songID,*this);
if( bUseCache ) if( bUseCache )
{ {
map<StepsID,Steps *>::iterator it = g_StepsIDCache.find( *this ); map<SongIDAndStepsID,Steps *>::iterator it = g_Cache.find( sas );
if( it != g_StepsIDCache.end() ) if( it != g_Cache.end() )
return it->second; return it->second;
} }
@@ -168,7 +173,7 @@ Steps *StepsID::ToSteps( const Song *p, bool bAllowNull, bool bUseCache ) const
RageException::Throw( "%i, %i, \"%s\"", st, dc, sDescription.c_str() ); RageException::Throw( "%i, %i, \"%s\"", st, dc, sDescription.c_str() );
if( bUseCache ) if( bUseCache )
g_StepsIDCache[*this] = ret; g_Cache[sas] = ret;
return ret; return ret;
} }
@@ -193,7 +198,7 @@ XNode* StepsID::CreateNode() const
void StepsID::Invalidate( Song *pStaleSong ) void StepsID::Invalidate( Song *pStaleSong )
{ {
// FIXME: Only flush entries with the stale song // FIXME: Only flush entries with the stale song
g_StepsIDCache.clear(); g_Cache.clear();
} }
void StepsID::LoadFromNode( const XNode* pNode ) void StepsID::LoadFromNode( const XNode* pNode )