CachedObjectPointer<Song> for SongID

This commit is contained in:
Glenn Maynard
2007-08-12 22:03:59 +00:00
parent 17434831f9
commit 66b6b168bb
4 changed files with 21 additions and 6 deletions
+1
View File
@@ -49,6 +49,7 @@ static const char *InstrumentTrackNames[] = {
XToString( InstrumentTrack );
StringToX( InstrumentTrack );
CACHED_REGISTER_CLASS(Song);
Song::Song()
{
+15 -6
View File
@@ -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
+2
View File
@@ -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<Song> m_Cache;
public:
SongID() { Unset(); }
+3
View File
@@ -7,6 +7,7 @@
#include "Difficulty.h"
#include "EnumHelper.h"
#include "RageUtil_AutoPtr.h"
#include "RageUtil_CachedObject.h"
#include "RageTypes.h"
#include <set>
@@ -226,6 +227,8 @@ public:
// means "this note doens't have a keysound".
vector<RString> m_vsKeysoundFile;
CachedObject<Song> m_CachedObject;
// Lua
void PushSelf( lua_State *L );