From 66b6b168bb3c49eb1655080047a55d2d2ee7e82a Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 12 Aug 2007 22:03:59 +0000 Subject: [PATCH] CachedObjectPointer for SongID --- stepmania/src/Song.cpp | 1 + stepmania/src/SongUtil.cpp | 21 +++++++++++++++------ stepmania/src/SongUtil.h | 2 ++ stepmania/src/song.h | 3 +++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index c58fe12f66..64b5ec940e 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -49,6 +49,7 @@ static const char *InstrumentTrackNames[] = { XToString( InstrumentTrack ); StringToX( InstrumentTrack ); +CACHED_REGISTER_CLASS(Song); Song::Song() { diff --git a/stepmania/src/SongUtil.cpp b/stepmania/src/SongUtil.cpp index 2ea29497de..0532880297 100644 --- a/stepmania/src/SongUtil.cpp +++ b/stepmania/src/SongUtil.cpp @@ -879,17 +879,25 @@ void SongID::FromSong( const Song *p ) // Strip off leading "/". 2005/05/21 file layer changes added a leading slash. if( sDir.Left(1) == "/" ) sDir.erase( sDir.begin() ); + + m_Cache.Unset(); } Song *SongID::ToSong() const { - // HACK for backwards compatibility: - // Re-add the leading "/". 2005/05/21 file layer changes added a leading slash. - RString sDir2 = sDir; - if( sDir2.Left(1) != "/" ) - sDir2 = "/" + sDir2; + Song *pRet; + if( !m_Cache.Get(&pRet) ) + { + // HACK for backwards compatibility: + // Re-add the leading "/". 2005/05/21 file layer changes added a leading slash. + RString sDir2 = sDir; + if( sDir2.Left(1) != "/" ) + sDir2 = "/" + sDir2; - return SONGMAN->GetSongFromDir( sDir2 ); + pRet = SONGMAN->GetSongFromDir( sDir2 ); + m_Cache.Set( pRet ); + } + return pRet; } XNode* SongID::CreateNode() const @@ -905,6 +913,7 @@ void SongID::LoadFromNode( const XNode* pNode ) { ASSERT( pNode->GetName() == "Song" ); pNode->GetAttrValue("Dir", sDir); + m_Cache.Unset(); } RString SongID::ToString() const diff --git a/stepmania/src/SongUtil.h b/stepmania/src/SongUtil.h index f109fff905..2d305d24d5 100644 --- a/stepmania/src/SongUtil.h +++ b/stepmania/src/SongUtil.h @@ -5,6 +5,7 @@ #include "GameConstantsAndTypes.h" #include "Difficulty.h" +#include "RageUtil_CachedObject.h" class Song; class Steps; @@ -118,6 +119,7 @@ namespace SongUtil class SongID { RString sDir; + mutable CachedObjectPointer m_Cache; public: SongID() { Unset(); } diff --git a/stepmania/src/song.h b/stepmania/src/song.h index b37b3c9c3b..d9a2f3dbde 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -7,6 +7,7 @@ #include "Difficulty.h" #include "EnumHelper.h" #include "RageUtil_AutoPtr.h" +#include "RageUtil_CachedObject.h" #include "RageTypes.h" #include @@ -226,6 +227,8 @@ public: // means "this note doens't have a keysound". vector m_vsKeysoundFile; + CachedObject m_CachedObject; + // Lua void PushSelf( lua_State *L );