CachedObjectPointer<Song> for StepsID
This commit is contained in:
@@ -319,8 +319,6 @@ bool Song::ReloadFromSongDir( RString sDir )
|
|||||||
{
|
{
|
||||||
// This stepchart didn't exist in the file we reverted from
|
// This stepchart didn't exist in the file we reverted from
|
||||||
delete *itOld;
|
delete *itOld;
|
||||||
// TODO: We should move the cache from StepsUtil to Song
|
|
||||||
StepsID::ClearCache();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1233,8 +1231,6 @@ void Song::DeleteSteps( const Steps* pSteps, bool bReAutoGen )
|
|||||||
{
|
{
|
||||||
delete m_vpSteps[j];
|
delete m_vpSteps[j];
|
||||||
m_vpSteps.erase( m_vpSteps.begin()+j );
|
m_vpSteps.erase( m_vpSteps.begin()+j );
|
||||||
// TODO: We should move the cache from StepsUtil to Song
|
|
||||||
StepsID::ClearCache();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1590,9 +1590,6 @@ void SongManager::FreeAllLoadedFromProfile( ProfileSlot slot )
|
|||||||
STATSMAN->GetStepsInUse( setInUse );
|
STATSMAN->GetStepsInUse( setInUse );
|
||||||
FOREACH( Song*, m_pSongs, s )
|
FOREACH( Song*, m_pSongs, s )
|
||||||
(*s)->FreeAllLoadedFromProfile( slot, &setInUse );
|
(*s)->FreeAllLoadedFromProfile( slot, &setInUse );
|
||||||
|
|
||||||
// After freeing some Steps pointers, the cache will be invalid.
|
|
||||||
StepsID::ClearCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int SongManager::GetNumStepsLoadedFromProfile()
|
int SongManager::GetNumStepsLoadedFromProfile()
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
CACHED_REGISTER_CLASS(Steps);
|
||||||
|
|
||||||
Steps::Steps()
|
Steps::Steps()
|
||||||
{
|
{
|
||||||
m_bSavedToDisk = false;
|
m_bSavedToDisk = false;
|
||||||
@@ -243,7 +245,12 @@ void Steps::Decompress() const
|
|||||||
StepsID ID;
|
StepsID ID;
|
||||||
ID.FromSteps( this );
|
ID.FromSteps( this );
|
||||||
|
|
||||||
Steps *pSteps = ID.ToSteps( &s, true, false ); // don't use cache
|
/* We're using a StepsID to search in a different copy of a Song than
|
||||||
|
* the one it was created with. Clear the cache before doing this,
|
||||||
|
* or search results will come from cache and point to the original
|
||||||
|
* copy. */
|
||||||
|
CachedObject<Steps>::ClearCacheAll();
|
||||||
|
Steps *pSteps = ID.ToSteps( &s, true );
|
||||||
if( pSteps == NULL )
|
if( pSteps == NULL )
|
||||||
{
|
{
|
||||||
LOG->Warn( "Couldn't find %s in \"%s\"", ID.ToString().c_str(), m_sFilename.c_str() );
|
LOG->Warn( "Couldn't find %s in \"%s\"", ID.ToString().c_str(), m_sFilename.c_str() );
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "RadarValues.h"
|
#include "RadarValues.h"
|
||||||
#include "Difficulty.h"
|
#include "Difficulty.h"
|
||||||
#include "RageUtil_AutoPtr.h"
|
#include "RageUtil_AutoPtr.h"
|
||||||
|
#include "RageUtil_CachedObject.h"
|
||||||
class Profile;
|
class Profile;
|
||||||
class NoteData;
|
class NoteData;
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
@@ -67,6 +68,9 @@ public:
|
|||||||
void PushSelf( lua_State *L );
|
void PushSelf( lua_State *L );
|
||||||
|
|
||||||
StepsType m_StepsType;
|
StepsType m_StepsType;
|
||||||
|
|
||||||
|
CachedObject<Steps> m_CachedObject;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline const Steps *Real() const { return parent ? parent : this; }
|
inline const Steps *Real() const { return parent ? parent : this; }
|
||||||
void DeAutogen( bool bCopyNoteData = true ); /* If this Steps is autogenerated, make it a real Steps. */
|
void DeAutogen( bool bCopyNoteData = true ); /* If this Steps is autogenerated, make it a real Steps. */
|
||||||
|
|||||||
@@ -237,6 +237,8 @@ void StepsID::FromSteps( const Steps *p )
|
|||||||
uHash = 0;
|
uHash = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_Cache.Unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: Don't allow duplicate edit descriptions, and don't allow edit descriptions
|
/* XXX: Don't allow duplicate edit descriptions, and don't allow edit descriptions
|
||||||
@@ -247,24 +249,14 @@ 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;
|
|
||||||
|
|
||||||
Steps *StepsID::ToSteps( const Song *p, bool bAllowNull, bool bUseCache ) const
|
Steps *StepsID::ToSteps( const Song *p, bool bAllowNull ) const
|
||||||
{
|
{
|
||||||
if( st == StepsType_Invalid || dc == Difficulty_Invalid )
|
if( st == StepsType_Invalid || dc == Difficulty_Invalid )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
SongID songID;
|
SongID songID;
|
||||||
songID.FromSong( p );
|
songID.FromSong( p );
|
||||||
SongIDAndStepsID sas = SongIDAndStepsID(songID,*this);
|
|
||||||
|
|
||||||
if( bUseCache )
|
|
||||||
{
|
|
||||||
map<SongIDAndStepsID,Steps *>::iterator it = g_Cache.find( sas );
|
|
||||||
if( it != g_Cache.end() )
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
Steps *pRet = NULL;
|
Steps *pRet = NULL;
|
||||||
if( dc == Difficulty_Edit )
|
if( dc == Difficulty_Edit )
|
||||||
@@ -279,8 +271,7 @@ Steps *StepsID::ToSteps( const Song *p, bool bAllowNull, bool bUseCache ) const
|
|||||||
if( !bAllowNull && pRet == NULL )
|
if( !bAllowNull && pRet == NULL )
|
||||||
FAIL_M( ssprintf("%i, %i, \"%s\"", st, dc, sDescription.c_str()) );
|
FAIL_M( ssprintf("%i, %i, \"%s\"", st, dc, sDescription.c_str()) );
|
||||||
|
|
||||||
if( bUseCache )
|
m_Cache.Set( pRet );
|
||||||
g_Cache[sas] = pRet;
|
|
||||||
|
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
@@ -300,12 +291,6 @@ XNode* StepsID::CreateNode() const
|
|||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void StepsID::ClearCache()
|
|
||||||
{
|
|
||||||
g_Cache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void StepsID::LoadFromNode( const XNode* pNode )
|
void StepsID::LoadFromNode( const XNode* pNode )
|
||||||
{
|
{
|
||||||
ASSERT( pNode->GetName() == "Steps" );
|
ASSERT( pNode->GetName() == "Steps" );
|
||||||
@@ -328,6 +313,8 @@ void StepsID::LoadFromNode( const XNode* pNode )
|
|||||||
sDescription = "";
|
sDescription = "";
|
||||||
uHash = 0;
|
uHash = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_Cache.Unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
RString StepsID::ToString() const
|
RString StepsID::ToString() const
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "GameConstantsAndTypes.h"
|
#include "GameConstantsAndTypes.h"
|
||||||
#include "Difficulty.h"
|
#include "Difficulty.h"
|
||||||
|
#include "RageUtil_CachedObject.h"
|
||||||
|
|
||||||
class Steps;
|
class Steps;
|
||||||
class Song;
|
class Song;
|
||||||
@@ -75,12 +76,13 @@ class StepsID
|
|||||||
Difficulty dc;
|
Difficulty dc;
|
||||||
RString sDescription;
|
RString sDescription;
|
||||||
unsigned uHash;
|
unsigned uHash;
|
||||||
|
mutable CachedObjectPointer<Steps> m_Cache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StepsID() { Unset(); }
|
StepsID() { Unset(); }
|
||||||
void Unset() { FromSteps(NULL); }
|
void Unset() { FromSteps(NULL); }
|
||||||
void FromSteps( const Steps *p );
|
void FromSteps( const Steps *p );
|
||||||
Steps *ToSteps( const Song *p, bool bAllowNull, bool bUseCache = true ) const;
|
Steps *ToSteps( const Song *p, bool bAllowNull ) const;
|
||||||
bool operator<( const StepsID &rhs ) const;
|
bool operator<( const StepsID &rhs ) const;
|
||||||
bool MatchesStepsType( StepsType s ) const { return st == s; }
|
bool MatchesStepsType( StepsType s ) const { return st == s; }
|
||||||
|
|
||||||
@@ -88,7 +90,6 @@ public:
|
|||||||
void LoadFromNode( const XNode* pNode );
|
void LoadFromNode( const XNode* pNode );
|
||||||
RString ToString() const;
|
RString ToString() const;
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
static void ClearCache();
|
|
||||||
|
|
||||||
StepsType GetStepsType() const { return st; }
|
StepsType GetStepsType() const { return st; }
|
||||||
Difficulty GetDifficulty() const { return dc; }
|
Difficulty GetDifficulty() const { return dc; }
|
||||||
|
|||||||
Reference in New Issue
Block a user