From 7729701678bdf0c9fc1dc00821229c8cb02fde47 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 15 Aug 2007 20:56:44 +0000 Subject: [PATCH] use SongID --- stepmania/src/ScreenUnlockCelebrate.cpp | 2 +- stepmania/src/ScreenUnlockStatus.cpp | 8 ++--- stepmania/src/SongManager.cpp | 4 +-- stepmania/src/SongUtil.cpp | 2 +- stepmania/src/UnlockManager.cpp | 44 ++++++++++++++----------- stepmania/src/UnlockManager.h | 4 +-- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/stepmania/src/ScreenUnlockCelebrate.cpp b/stepmania/src/ScreenUnlockCelebrate.cpp index 6598299ee7..fd14390384 100644 --- a/stepmania/src/ScreenUnlockCelebrate.cpp +++ b/stepmania/src/ScreenUnlockCelebrate.cpp @@ -18,7 +18,7 @@ void ScreenUnlockCelebrate::Init() g_iUnlockEntryIndexToCelebrate = UNLOCKMAN->GetUnlockEntryIndexToCelebrate(); UNLOCKMAN->UnlockEntryIndex( g_iUnlockEntryIndexToCelebrate ); - Song* pSong = UNLOCKMAN->m_UnlockEntries[ g_iUnlockEntryIndexToCelebrate ].m_pSong; + Song* pSong = UNLOCKMAN->m_UnlockEntries[ g_iUnlockEntryIndexToCelebrate ].m_Song.ToSong(); if( pSong ) GAMESTATE->m_pCurSong.Set( pSong ); diff --git a/stepmania/src/ScreenUnlockStatus.cpp b/stepmania/src/ScreenUnlockStatus.cpp index f1d10aca3b..ec1de4bbae 100644 --- a/stepmania/src/ScreenUnlockStatus.cpp +++ b/stepmania/src/ScreenUnlockStatus.cpp @@ -48,7 +48,7 @@ void ScreenUnlockStatus::Init() { // get pertaining UnlockEntry const UnlockEntry &entry = UNLOCKMAN->m_UnlockEntries[i-1]; - const Song *pSong = entry.m_pSong; + const Song *pSong = entry.m_Song.ToSong(); if( pSong == NULL) continue; @@ -104,7 +104,7 @@ void ScreenUnlockStatus::Init() { case UnlockRewardType_Song: { - const Song *pSong = entry.m_pSong; + const Song *pSong = entry.m_Song.ToSong(); ASSERT( pSong ); RString title = pSong->GetDisplayMainTitle(); @@ -139,7 +139,7 @@ void ScreenUnlockStatus::Init() else { // unlocked. change color - const Song *pSong = entry.m_pSong; + const Song *pSong = entry.m_Song.ToSong(); RageColor color = RageColor(1,1,1,1); if( pSong ) color = SONGMAN->GetSongGroupColor(pSong->m_sGroupName); @@ -228,7 +228,7 @@ void ScreenUnlockStatus::Init() unsigned NextIcon = LastUnlocks[LastUnlocks.size() - i]; const UnlockEntry &entry = UNLOCKMAN->m_UnlockEntries[NextIcon-1]; - const Song *pSong = entry.m_pSong; + const Song *pSong = entry.m_Song.ToSong(); if( pSong == NULL ) continue; diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 1270ea8ebe..e547382694 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1378,8 +1378,8 @@ void SongManager::UpdatePreferredSort() FOREACH( UnlockEntry, UNLOCKMAN->m_UnlockEntries, ue ) { if( ue->m_Type == UnlockRewardType_Song ) - if( ue->m_pSong ) - vpUnlockSongs.push_back( ue->m_pSong ); + if( ue->m_Song.ToSong() ) + vpUnlockSongs.push_back( ue->m_Song.ToSong() ); } FOREACH( SongPointerVector, m_vPreferredSongSort, v ) diff --git a/stepmania/src/SongUtil.cpp b/stepmania/src/SongUtil.cpp index c6b8c007af..c414123438 100644 --- a/stepmania/src/SongUtil.cpp +++ b/stepmania/src/SongUtil.cpp @@ -927,7 +927,7 @@ RString SongID::ToString() const bool SongID::IsValid() const { - return !sDir.empty(); + return ToSong() != NULL; } // lua start diff --git a/stepmania/src/UnlockManager.cpp b/stepmania/src/UnlockManager.cpp index 4bbf0fd795..5174606062 100644 --- a/stepmania/src/UnlockManager.cpp +++ b/stepmania/src/UnlockManager.cpp @@ -193,7 +193,7 @@ bool UnlockManager::ModifierIsLocked( const RString &sOneMod ) const const UnlockEntry *UnlockManager::FindSong( const Song *pSong ) const { FOREACH_CONST( UnlockEntry, m_UnlockEntries, e ) - if( e->m_pSong == pSong && e->m_dc == Difficulty_Invalid ) + if( e->m_Song.ToSong() == pSong && e->m_dc == Difficulty_Invalid ) return &(*e); return NULL; } @@ -202,7 +202,7 @@ const UnlockEntry *UnlockManager::FindSteps( const Song *pSong, const Steps *pSt { ASSERT( pSong && pSteps ); FOREACH_CONST( UnlockEntry, m_UnlockEntries, e ) - if( e->m_pSong == pSong && e->m_dc == pSteps->GetDifficulty() ) + if( e->m_Song.ToSong() == pSong && e->m_dc == pSteps->GetDifficulty() ) return &(*e); return NULL; } @@ -310,10 +310,10 @@ bool UnlockEntry::IsValid() const switch( m_Type ) { case UnlockRewardType_Song: - return m_pSong != NULL; + return m_Song.IsValid(); case UnlockRewardType_Steps: - return m_pSong != NULL && m_dc != Difficulty_Invalid; + return m_Song.IsValid() && m_dc != Difficulty_Invalid; case UnlockRewardType_Course: return m_pCourse != NULL; @@ -339,17 +339,18 @@ UnlockEntryStatus UnlockEntry::GetUnlockEntryStatus() const if( m_fRequirement[i] && fScores[i] >= m_fRequirement[i] ) return UnlockEntryStatus_RequirementsMet; - if( m_bRequirePassHardSteps && m_pSong ) + if( m_bRequirePassHardSteps && m_Song.IsValid() ) { + Song *pSong = m_Song.ToSong(); vector vp; SongUtil::GetSteps( - m_pSong, + pSong, vp, StepsType_Invalid, Difficulty_Hard ); FOREACH_CONST( Steps*, vp, s ) - if( PROFILEMAN->GetMachineProfile()->HasPassedSteps( m_pSong, *s ) ) + if( PROFILEMAN->GetMachineProfile()->HasPassedSteps(pSong, *s) ) return UnlockEntryStatus_RequirementsMet; } @@ -359,15 +360,16 @@ UnlockEntryStatus UnlockEntry::GetUnlockEntryStatus() const RString UnlockEntry::GetDescription() const { + Song *pSong = m_Song.ToSong(); switch( m_Type ) { default: ASSERT(0); return ""; case UnlockRewardType_Song: - return m_pSong ? m_pSong->GetDisplayFullTitle() : ""; + return pSong ? pSong->GetDisplayFullTitle() : ""; case UnlockRewardType_Steps: - return (m_pSong ? m_pSong->GetDisplayFullTitle() : "") + ", " + DifficultyToLocalizedString( m_dc ); + return (pSong ? pSong->GetDisplayFullTitle() : "") + ", " + DifficultyToLocalizedString( m_dc ); case UnlockRewardType_Course: return m_pCourse ? m_pCourse->GetDisplayFullTitle() : ""; case UnlockRewardType_Modifier: @@ -377,6 +379,7 @@ RString UnlockEntry::GetDescription() const RString UnlockEntry::GetBannerFile() const { + Song *pSong = m_Song.ToSong(); switch( m_Type ) { default: @@ -384,7 +387,7 @@ RString UnlockEntry::GetBannerFile() const return ""; case UnlockRewardType_Song: case UnlockRewardType_Steps: - return m_pSong ? m_pSong->GetBannerPath() : ""; + return pSong ? pSong->GetBannerPath() : ""; case UnlockRewardType_Course: return m_pCourse ? m_pCourse->GetBannerPath() : ""; case UnlockRewardType_Modifier: @@ -394,6 +397,7 @@ RString UnlockEntry::GetBannerFile() const RString UnlockEntry::GetBackgroundFile() const { + Song *pSong = m_Song.ToSong(); switch( m_Type ) { default: @@ -401,7 +405,7 @@ RString UnlockEntry::GetBackgroundFile() const return ""; case UnlockRewardType_Song: case UnlockRewardType_Steps: - return m_pSong ? m_pSong->GetBackgroundPath() : ""; + return pSong ? pSong->GetBackgroundPath() : ""; case UnlockRewardType_Course: return ""; case UnlockRewardType_Modifier: @@ -493,7 +497,7 @@ void UnlockManager::Load() str += ssprintf( "entryID = %s ", e->m_sEntryID.c_str() ); str += e->IsLocked()? "locked":"unlocked"; - if( e->m_pSong ) + if( e->m_Song.IsValid() ) str += ( " (found song)" ); if( e->m_pCourse ) str += ( " (found course)" ); @@ -538,13 +542,13 @@ void UnlockManager::UpdateCachedPointers() switch( e->m_Type ) { case UnlockRewardType_Song: - e->m_pSong = SONGMAN->FindSong( e->m_cmd.GetArg(0).s ); - if( e->m_pSong == NULL ) + e->m_Song.FromSong( SONGMAN->FindSong( e->m_cmd.GetArg(0).s ) ); + if( !e->m_Song.IsValid() ) LOG->Warn( "Unlock: Cannot find song matching \"%s\"", e->m_cmd.GetArg(0).s.c_str() ); break; case UnlockRewardType_Steps: - e->m_pSong = SONGMAN->FindSong( e->m_cmd.GetArg(0).s ); - if( e->m_pSong == NULL ) + e->m_Song.FromSong( SONGMAN->FindSong( e->m_cmd.GetArg(0).s ) ); + if( !e->m_Song.IsValid() ) { LOG->Warn( "Unlock: Cannot find song matching \"%s\"", e->m_cmd.GetArg(0).s.c_str() ); break; @@ -594,8 +598,8 @@ void UnlockManager::PreferUnlockEntryID( RString sUnlockEntryID ) if( pEntry.m_sEntryID != sUnlockEntryID ) continue; - if( pEntry.m_pSong != NULL ) - GAMESTATE->m_pPreferredSong = pEntry.m_pSong; + if( pEntry.m_Song.ToSong() != NULL ) + GAMESTATE->m_pPreferredSong = pEntry.m_Song.ToSong(); if( pEntry.m_pCourse != NULL ) GAMESTATE->m_pPreferredCourse = pEntry.m_pCourse; } @@ -646,7 +650,7 @@ void UnlockManager::GetSongsUnlockedByEntryID( vector &apSongsOut, RStri for( unsigned i = 0; i < apEntries.size(); ++i ) if( apEntries[i]->m_sEntryID == sUnlockEntryID ) - apSongsOut.push_back( apEntries[i]->m_pSong ); + apSongsOut.push_back( apEntries[i]->m_Song.ToSong() ); } void UnlockManager::GetStepsUnlockedByEntryID( vector &apSongsOut, vector &apDifficultyOut, RString sUnlockEntryID ) @@ -658,7 +662,7 @@ void UnlockManager::GetStepsUnlockedByEntryID( vector &apSongsOut, vecto { if( apEntries[i]->m_sEntryID == sUnlockEntryID ) { - apSongsOut.push_back( apEntries[i]->m_pSong ); + apSongsOut.push_back( apEntries[i]->m_Song.ToSong() ); apDifficultyOut.push_back( apEntries[i]->m_dc ); } } diff --git a/stepmania/src/UnlockManager.h b/stepmania/src/UnlockManager.h index dfbca85d87..0604a5516c 100644 --- a/stepmania/src/UnlockManager.h +++ b/stepmania/src/UnlockManager.h @@ -7,6 +7,7 @@ #include "Command.h" #include #include "Difficulty.h" +#include "SongUtil.h" class Song; class Course; @@ -54,7 +55,6 @@ public: { m_Type = UnlockRewardType_Invalid; - m_pSong = NULL; m_dc = Difficulty_Invalid; m_pCourse = NULL; @@ -69,7 +69,7 @@ public: /* A cached pointer to the song or course this entry refers to. Only one of * these will be non-NULL. */ - Song *m_pSong; + SongID m_Song; Difficulty m_dc; Course *m_pCourse;