diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 912481fe2f..18bb333a85 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -60,6 +60,7 @@ const int MAX_BOTTOM_RANGE = 10; RString CourseEntry::GetTextDescription() const { vector vsEntryDescription; + Song *pSong = songID.ToSong(); if( pSong ) vsEntryDescription.push_back( pSong->GetTranslitFullTitle() ); else @@ -105,8 +106,8 @@ class LunaCourseEntry: public Luna public: static int GetSong( T* p, lua_State *L ) { - if( p->pSong ) - p->pSong->PushSelf(L); + if( p->songID.ToSong() ) + p->songID.ToSong()->PushSelf(L); else lua_pushnil(L); return 1; @@ -232,10 +233,11 @@ bool Course::IsPlayableIn( StepsType st ) const { SongCriteria soc = e->songCriteria; - if( e->pSong ) + Song *pSong = e->songID.ToSong(); + if( pSong ) { soc.m_bUseSongAllowedList = true; - soc.m_vpSongAllowedList.push_back( e->pSong ); + soc.m_vpSongAllowedList.push_back( pSong ); } soc.m_Tutorial = SongCriteria::Tutorial_No; soc.m_Locked = SongCriteria::Locked_Unlocked; @@ -249,14 +251,14 @@ bool Course::IsPlayableIn( StepsType st ) const const bool bSameSongCriteria = e != m_vEntries.begin() && (e-1)->songCriteria == soc; const bool bSameStepsCriteria = e != m_vEntries.begin() && (e-1)->stepsCriteria == stc; - if( e->pSong ) + if( pSong ) { - if ( StepsUtil::HasMatching(e->pSong, stc) ) + if( StepsUtil::HasMatching(pSong, stc) ) return true; } else if( !(bSameSongCriteria && bSameStepsCriteria) ) { - if ( StepsUtil::HasMatching(soc, stc) ) + if( StepsUtil::HasMatching(soc, stc) ) return true; } @@ -495,10 +497,11 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) SongAndSteps resolved; // fill this in SongCriteria soc = e->songCriteria; - if( e->pSong ) + Song *pSong = e->songID.ToSong(); + if( pSong ) { soc.m_bUseSongAllowedList = true; - soc.m_vpSongAllowedList.push_back( e->pSong ); + soc.m_vpSongAllowedList.push_back( pSong ); } soc.m_Tutorial = SongCriteria::Tutorial_No; soc.m_Locked = SongCriteria::Locked_Unlocked; @@ -512,9 +515,9 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) const bool bSameSongCriteria = e != entries.begin() && (e-1)->songCriteria == soc; const bool bSameStepsCriteria = e != entries.begin() && (e-1)->stepsCriteria == stc; - if( e->pSong ) + if( pSong ) { - StepsUtil::GetAllMatching( e->pSong, stc, vSongAndSteps ); + StepsUtil::GetAllMatching( pSong, stc, vSongAndSteps ); } else if( vSongAndSteps.empty() || !(bSameSongCriteria && bSameStepsCriteria) ) { @@ -749,7 +752,8 @@ void Course::Invalidate( const Song *pStaleSong ) { FOREACH_CONST( CourseEntry, m_vEntries, e ) { - if( e->pSong == pStaleSong ) // a fixed entry that references the stale Song + Song *pSong = e->songID.ToSong(); + if( pSong == pStaleSong ) // a fixed entry that references the stale Song { RevertFromDisk(); return; @@ -876,7 +880,8 @@ void Course::UpdateCourseStats( StepsType st ) // courses with random/players best-worst songs should go at the end for(unsigned i = 0; i < m_vEntries.size(); i++) { - if ( m_vEntries[i].pSong != NULL ) + Song *pSong = m_vEntries[i].songID.ToSong(); + if( pSong != NULL ) continue; if ( m_SortOrder_Ranking == 2 ) @@ -916,7 +921,8 @@ const CourseEntry *Course::FindFixedSong( const Song *pSong ) const FOREACH_CONST( CourseEntry, m_vEntries, e ) { const CourseEntry &entry = *e; - if( entry.pSong == pSong ) + Song *pSong = entry.songID.ToSong(); + if( pSong == pSong ) return &entry; } diff --git a/stepmania/src/Course.h b/stepmania/src/Course.h index 8874523ba6..f8c66ca7d9 100644 --- a/stepmania/src/Course.h +++ b/stepmania/src/Course.h @@ -57,8 +57,7 @@ public: bool bSecret; // show "??????" instead of an exact song // filter criteria, applied from top to bottom - // TODO: change this to be a SongID - Song* pSong; // don't filter if NULL + SongID songID; // don't filter if unset SongCriteria songCriteria; StepsCriteria stepsCriteria; bool bNoDifficult; // if true, CourseDifficulty doesn't affect this entry @@ -74,8 +73,6 @@ public: CourseEntry() { bSecret = false; - - pSong = NULL; bNoDifficult = false; songSort = SongSort_Randomize; @@ -86,7 +83,7 @@ public: iGainLives = -1; } - bool IsFixedSong() const { return pSong != NULL; } + bool IsFixedSong() const { return songID.IsValid(); } RString GetTextDescription() const; int GetNumModChanges() const; diff --git a/stepmania/src/CourseLoaderCRS.cpp b/stepmania/src/CourseLoaderCRS.cpp index f19a8331b1..e288674a7d 100644 --- a/stepmania/src/CourseLoaderCRS.cpp +++ b/stepmania/src/CourseLoaderCRS.cpp @@ -196,17 +196,19 @@ bool CourseLoaderCRS::LoadFromMsd( const RString &sPath, const MsdFile &msd, Cou vector bits; split( sSong, "/", bits ); + Song *pSong = NULL; if( bits.size() == 2 ) { new_entry.songCriteria.m_sGroupName = bits[0]; - new_entry.pSong = SONGMAN->FindSong( bits[0], bits[1] ); + pSong = SONGMAN->FindSong( bits[0], bits[1] ); } else if( bits.size() == 1 ) { - new_entry.pSong = SONGMAN->FindSong( "", sSong ); + pSong = SONGMAN->FindSong( "", sSong ); } + new_entry.songID.FromSong( pSong ); - if( new_entry.pSong == NULL ) + if( pSong == NULL ) { LOG->UserLog( "Course file", sPath, "contains a fixed song entry \"%s\" that does not exist. " "This entry will be ignored.", sSong.c_str()); diff --git a/stepmania/src/CourseUtil.cpp b/stepmania/src/CourseUtil.cpp index 1359c85858..d1aea7fdd9 100644 --- a/stepmania/src/CourseUtil.cpp +++ b/stepmania/src/CourseUtil.cpp @@ -192,7 +192,7 @@ void CourseUtil::SortByMostRecentlyPlayedForMachine( vector &vpCoursesI void CourseUtil::MakeDefaultEditCourseEntry( CourseEntry& out ) { - out.pSong = GAMESTATE->GetDefaultSong(); + out.songID.FromSong( GAMESTATE->GetDefaultSong() ); out.stepsCriteria.m_difficulty = Difficulty_Medium; } @@ -286,7 +286,7 @@ void CourseUtil::AutogenOniFromArtist( const RString &sArtistName, RString sArti for( unsigned i = 0; i < aSongs.size(); ++i ) { - e.pSong = aSongs[i]; + e.songID.FromSong( aSongs[i] ); out.m_vEntries.push_back( e ); } } diff --git a/stepmania/src/CourseWriterCRS.cpp b/stepmania/src/CourseWriterCRS.cpp index 34159d7190..c712d80315 100644 --- a/stepmania/src/CourseWriterCRS.cpp +++ b/stepmania/src/CourseWriterCRS.cpp @@ -115,9 +115,10 @@ bool CourseWriterCRS::Write( const Course &course, RageFileBasic &f, bool bSavin { f.Write( ssprintf( "#SONG:WORST%d", entry.iChooseIndex+1 ) ); } - else if( entry.pSong ) + else if( entry.songID.ToSong() ) { - const RString &sSong = Basename( entry.pSong->GetSongDir() ); + Song *pSong = entry.songID.ToSong(); + const RString &sSong = Basename( pSong->GetSongDir() ); f.Write( "#SONG:" ); if( !entry.songCriteria.m_sGroupName.empty() ) diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index b22f2f0eef..b95514cef9 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -1736,7 +1736,7 @@ void ScreenEdit::InputEdit( const InputEventPlus &input, EditButton EditB ) bool bUsesThisSong = false; for( unsigned e = 0; e < crs->m_vEntries.size(); ++e ) { - if( crs->m_vEntries[e].pSong != m_pSong ) + if( crs->m_vEntries[e].songID.ToSong() != m_pSong ) continue; bUsesThisSong = true; } @@ -2502,7 +2502,7 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM ) int iCourseEntryIndex = -1; FOREACH_CONST( CourseEntry, pCourse->m_vEntries, i ) { - if( i->pSong == GAMESTATE->m_pCurSong.Get() ) + if( i->songID.ToSong() == GAMESTATE->m_pCurSong.Get() ) iCourseEntryIndex = i - pCourse->m_vEntries.begin(); } @@ -3487,7 +3487,7 @@ void ScreenEdit::SetupCourseAttacks() for( unsigned e = 0; e < GAMESTATE->m_pCurCourse->m_vEntries.size(); ++e ) { - if( GAMESTATE->m_pCurCourse->m_vEntries[e].pSong != m_pSong ) + if( GAMESTATE->m_pCurCourse->m_vEntries[e].songID.ToSong() != m_pSong ) continue; Attacks = GAMESTATE->m_pCurCourse->m_vEntries[e].attacks; diff --git a/stepmania/src/ScreenJukebox.cpp b/stepmania/src/ScreenJukebox.cpp index 4821328d7b..ffe7c9be89 100644 --- a/stepmania/src/ScreenJukebox.cpp +++ b/stepmania/src/ScreenJukebox.cpp @@ -39,7 +39,7 @@ void ScreenJukebox::SetSong() if( pCourse != NULL ) for ( unsigned i = 0; i < pCourse->m_vEntries.size(); i++ ) if( pCourse->m_vEntries[i].IsFixedSong() ) - vSongs.push_back( pCourse->m_vEntries[i].pSong ); + vSongs.push_back( pCourse->m_vEntries[i].songID.ToSong() ); if ( vSongs.size() == 0 ) vSongs = SONGMAN->GetSongs( GAMESTATE->m_sPreferredSongGroup ); diff --git a/stepmania/src/ScreenOptionsEditCourse.cpp b/stepmania/src/ScreenOptionsEditCourse.cpp index dd7b6e4c38..c912c36e5a 100644 --- a/stepmania/src/ScreenOptionsEditCourse.cpp +++ b/stepmania/src/ScreenOptionsEditCourse.cpp @@ -246,7 +246,8 @@ void ScreenOptionsEditCourse::ImportOptions( int iRow, const vector::const_iterator iter = find( m_vpDisplayedSongs.begin(), m_vpDisplayedSongs.end(), ce.pSong ); + Song *pSong = ce.songID.ToSong(); + vector::const_iterator iter = find( m_vpDisplayedSongs.begin(), m_vpDisplayedSongs.end(), pSong ); if( iter == m_vpDisplayedSongs.end() ) // This song isn't being displayed, set to "RANDOM" row.SetOneSharedSelection( 0 ); @@ -288,9 +289,9 @@ void ScreenOptionsEditCourse::ExportOptions( int iRow, const vectorm_vEntries[iRow - NUM_EditCourseRow]; if( iSel == 0 ) - ce.pSong = NULL; + ce.songID.FromSong( NULL ); else - ce.pSong = m_vpDisplayedSongs[iSel - 1]; + ce.songID.FromSong( m_vpDisplayedSongs[iSel - 1] ); } void ScreenOptionsEditCourse::ProcessMenuStart( const InputEventPlus &input ) diff --git a/stepmania/src/ScreenOptionsEditCourseEntry.cpp b/stepmania/src/ScreenOptionsEditCourseEntry.cpp index 3da000415b..440df125ba 100644 --- a/stepmania/src/ScreenOptionsEditCourseEntry.cpp +++ b/stepmania/src/ScreenOptionsEditCourseEntry.cpp @@ -237,7 +237,7 @@ void ScreenOptionsEditCourseEntry::HandleScreenMessage( const ScreenMessage SM ) /* We can't rely on the trail here since it depends on what steps are available. * Use the course entry directly instead. */ CourseEntry& ce = pCourse->m_vEntries[GAMESTATE->m_iEditCourseEntryIndex]; - Song *pSong = ce.pSong; + Song *pSong = ce.songID.ToSong(); Steps *pSteps; StepsType st = GAMESTATE->m_stEdit; CourseDifficulty cd = ( ce.stepsCriteria.m_difficulty == Difficulty_Invalid ? @@ -378,7 +378,7 @@ void ScreenOptionsEditCourseEntry::ImportOptions( int iRow, const vectorm_pCurSong.Set( ce.pSong ); + GAMESTATE->m_pCurSong.Set( ce.songID.ToSong() ); // XXX: copy and pasted from ScreenOptionsMaster FOREACH_CONST( PlayerNumber, vpns, pn ) @@ -466,7 +466,7 @@ void ScreenOptionsEditCourseEntry::ExportOptions( int iRow, const vectorm_pCurSong; + ce.songID.FromSong( GAMESTATE->m_pCurSong ); break; } case ROW_BASE_DIFFICULTY: