diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index c6a8d49773..b347735df8 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -122,9 +122,9 @@ bool GameCommand::DescribesCurrentMode( PlayerNumber pn ) const return false; if( m_pCharacter && GAMESTATE->m_pCurCharacters[pn] != m_pCharacter ) return false; - if( m_pCourse && GAMESTATE->m_pCurCourse != m_pCourse ) + if( m_pCourse && GAMESTATE->m_pCurCourse.Get() != m_pCourse ) return false; - if( m_pTrail && GAMESTATE->m_pCurTrail[pn] != m_pTrail ) + if( m_pTrail && GAMESTATE->m_pCurTrail[pn].Get() != m_pTrail ) return false; if( !m_sSongGroup.empty() && GAMESTATE->m_sPreferredSongGroup != m_sSongGroup ) return false; @@ -744,12 +744,12 @@ void GameCommand::ApplySelf( const vector &vpns ) const GAMESTATE->m_pCurSteps[*pn].Set( m_pSteps ); if( m_pCourse ) { - GAMESTATE->m_pCurCourse = m_pCourse; + GAMESTATE->m_pCurCourse.Set( m_pCourse ); GAMESTATE->m_pPreferredCourse = m_pCourse; } if( m_pTrail ) FOREACH_CONST( PlayerNumber, vpns, pn ) - GAMESTATE->m_pCurTrail[*pn] = m_pTrail; + GAMESTATE->m_pCurTrail[*pn].Set( m_pTrail ); if( m_CourseDifficulty != DIFFICULTY_INVALID ) FOREACH_CONST( PlayerNumber, vpns, pn ) GAMESTATE->ChangePreferredCourseDifficulty( *pn, m_CourseDifficulty ); diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index ecd3de3555..d8c24eecf2 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -52,6 +52,8 @@ GameState::GameState() : m_PreferredDifficulty( MESSAGE_EDIT_PREFERRED_DIFFICULTY_P1_CHANGED ), m_pCurSong( MESSAGE_CURRENT_SONG_CHANGED ), m_pCurSteps( MESSAGE_CURRENT_STEPS_P1_CHANGED ), + m_pCurCourse( MESSAGE_CURRENT_COURSE_CHANGED ), + m_pCurTrail( MESSAGE_CURRENT_TRAIL_P1_CHANGED ), m_stEdit( MESSAGE_EDIT_STEPS_TYPE_CHANGED ), m_pEditSourceSteps( MESSAGE_EDIT_SOURCE_STEPS_CHANGED ), m_stEditSource( MESSAGE_EDIT_SOURCE_STEPS_TYPE_CHANGED ) @@ -172,10 +174,10 @@ void GameState::Reset() m_pPreferredSong = NULL; FOREACH_PlayerNumber( p ) m_pCurSteps[p].Set( NULL ); - m_pCurCourse = NULL; + m_pCurCourse.Set( NULL ); m_pPreferredCourse = NULL; FOREACH_PlayerNumber( p ) - m_pCurTrail[p] = NULL; + m_pCurTrail[p].Set( NULL ); FOREACH_PlayerNumber( p ) m_pPlayerState[p]->Reset(); @@ -1946,14 +1948,14 @@ public: PlayerNumber pn = (PlayerNumber)IArg(1); if( lua_isnil(L,2) ) { p->m_pCurSteps[pn].Set( NULL ); } else { Steps *pS = Luna::check(L,2); p->m_pCurSteps[pn].Set( pS ); } - MESSAGEMAN->Broadcast( ssprintf("CurrentStepsP%dChanged",pn+1) ); + MESSAGEMAN->Broadcast( (Message)(MESSAGE_CURRENT_STEPS_P1_CHANGED+pn) ); return 0; } static int GetCurrentCourse( T* p, lua_State *L ) { if(p->m_pCurCourse) p->m_pCurCourse->PushSelf(L); else lua_pushnil(L); return 1; } static int SetCurrentCourse( T* p, lua_State *L ) { - if( lua_isnil(L,1) ) { p->m_pCurCourse = NULL; } - else { Course *pC = Luna::check(L,1); p->m_pCurCourse = pC; } + if( lua_isnil(L,1) ) { p->m_pCurCourse.Set( NULL ); } + else { Course *pC = Luna::check(L,1); p->m_pCurCourse.Set( pC ); } return 0; } static int GetCurrentTrail( T* p, lua_State *L ) diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 3f3972ea02..3133265563 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -139,10 +139,10 @@ public: BroadcastOnChangePtr1D m_pCurSteps; // NULL on ScreenSelectMusic if the currently selected wheel item isn't a Course. - Course* m_pCurCourse; + BroadcastOnChangePtr m_pCurCourse; // The last Course that the user manually changed to. Course* m_pPreferredCourse; - Trail* m_pCurTrail[NUM_PLAYERS]; + BroadcastOnChangePtr1D m_pCurTrail; // diff --git a/stepmania/src/HelpDisplay.cpp b/stepmania/src/HelpDisplay.cpp index 577a7584a7..14f4fbe6b1 100644 --- a/stepmania/src/HelpDisplay.cpp +++ b/stepmania/src/HelpDisplay.cpp @@ -136,19 +136,17 @@ REGISTER_ACTOR_CLASS( GenreDisplay ) GenreDisplay::GenreDisplay() { - MESSAGEMAN->Subscribe( this, "OnSongChanged" ); - MESSAGEMAN->Subscribe( this, "OnCourseChanged" ); + this->SubscribeToMessage( MESSAGE_CURRENT_SONG_CHANGED ); + this->SubscribeToMessage( MESSAGE_CURRENT_COURSE_CHANGED ); } GenreDisplay::~GenreDisplay() { - MESSAGEMAN->Unsubscribe( this, "OnSongChanged" ); - MESSAGEMAN->Unsubscribe( this, "OnCourseChanged" ); } void GenreDisplay::PlayCommand( const CString &sCommandName ) { - if( sCommandName == "OnSongChanged" ) + if( sCommandName == MessageToString(MESSAGE_CURRENT_SONG_CHANGED) ) { vector m_Artists, m_AltArtists; @@ -160,7 +158,7 @@ void GenreDisplay::PlayCommand( const CString &sCommandName ) SetTips( m_Artists, m_AltArtists ); } - else if( sCommandName == "OnCourseChanged" ) + else if( sCommandName == MessageToString(MESSAGE_CURRENT_COURSE_CHANGED) ) { vector m_Artists, m_AltArtists; diff --git a/stepmania/src/MessageManager.cpp b/stepmania/src/MessageManager.cpp index f206da7396..5958116bf0 100644 --- a/stepmania/src/MessageManager.cpp +++ b/stepmania/src/MessageManager.cpp @@ -13,6 +13,9 @@ static const CString MessageNames[] = { "CurrentSongChanged", "CurrentStepsP1Changed", "CurrentStepsP2Changed", + "CurrentCourseChanged", + "CurrentTrailP1Changed", + "CurrentTrailP2Changed", "EditStepsTypeChanged", "EditSourceStepsChanged", "EditSourceStepsTypeChanged", diff --git a/stepmania/src/MessageManager.h b/stepmania/src/MessageManager.h index 9af3b3a475..e80d191648 100644 --- a/stepmania/src/MessageManager.h +++ b/stepmania/src/MessageManager.h @@ -20,6 +20,9 @@ enum Message MESSAGE_CURRENT_SONG_CHANGED, MESSAGE_CURRENT_STEPS_P1_CHANGED, MESSAGE_CURRENT_STEPS_P2_CHANGED, + MESSAGE_CURRENT_COURSE_CHANGED, + MESSAGE_CURRENT_TRAIL_P1_CHANGED, + MESSAGE_CURRENT_TRAIL_P2_CHANGED, MESSAGE_EDIT_STEPS_TYPE_CHANGED, MESSAGE_EDIT_SOURCE_STEPS_CHANGED, MESSAGE_EDIT_SOURCE_STEPS_TYPE_CHANGED, diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index 99c0b7e50f..d494a7b030 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -323,7 +323,7 @@ bool MusicWheel::SelectCourse( Course *p ) if(p == NULL) return false; - GAMESTATE->m_pCurCourse = p; + GAMESTATE->m_pCurCourse.Set( p ); unsigned i; vector &from = m_WheelItemDatas[GAMESTATE->m_SortOrder]; diff --git a/stepmania/src/ScreenEnding.cpp b/stepmania/src/ScreenEnding.cpp index 2e76d97007..b7d5a569d8 100644 --- a/stepmania/src/ScreenEnding.cpp +++ b/stepmania/src/ScreenEnding.cpp @@ -146,7 +146,7 @@ ScreenEnding::ScreenEnding( CString sClassName ) : ScreenAttract( sClassName, fa GAMESTATE->m_bSideIsJoined[PLAYER_2] = true; GAMESTATE->m_MasterPlayerNumber = PLAYER_1; GAMESTATE->m_pCurSong.Set( SONGMAN->GetRandomSong() ); - GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse(); + GAMESTATE->m_pCurCourse.Set( SONGMAN->GetRandomCourse() ); GAMESTATE->m_pCurSteps[PLAYER_1].Set( GAMESTATE->m_pCurSong->GetAllSteps()[0] ); GAMESTATE->m_pCurSteps[PLAYER_2].Set( GAMESTATE->m_pCurSong->GetAllSteps()[0] ); STATSMAN->m_CurStageStats.m_player[PLAYER_1].vpPlayedSteps.push_back( GAMESTATE->m_pCurSteps[PLAYER_1] ); diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index e2bcbf0ca6..f0812bbefa 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -110,7 +110,7 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName ) : ScreenWithMenuElement GAMESTATE->m_pCurSong.Set( SONGMAN->GetRandomSong() ); STATSMAN->m_CurStageStats.vpPlayedSongs.push_back( GAMESTATE->m_pCurSong ); STATSMAN->m_CurStageStats.vpPossibleSongs.push_back( GAMESTATE->m_pCurSong ); - GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse(); + GAMESTATE->m_pCurCourse.Set( SONGMAN->GetRandomCourse() ); GAMESTATE->m_iCurrentStageIndex = 0; FOREACH_PlayerNumber( p ) @@ -122,7 +122,7 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName ) : ScreenWithMenuElement GAMESTATE->m_pCurSteps[p].Set( GAMESTATE->m_pCurSong->GetAllSteps()[0] ); vector apTrails; GAMESTATE->m_pCurCourse->GetAllTrails( apTrails ); - GAMESTATE->m_pCurTrail[p] = apTrails[0]; + GAMESTATE->m_pCurTrail[p].Set( apTrails[0] ); STATSMAN->m_CurStageStats.m_player[p].vpPlayedSteps.push_back( GAMESTATE->m_pCurSteps[PLAYER_1] ); STATSMAN->m_CurStageStats.m_player[p].vpPossibleSteps.push_back( GAMESTATE->m_pCurSteps[PLAYER_1] ); GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.m_fScrollSpeed = 2; diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index b8a24822d2..f46fbfeff9 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -1371,7 +1371,7 @@ void ScreenSelectMusic::AfterTrailChange( const vector &vpns ) Course* pCourse = GAMESTATE->m_pCurCourse; Trail* pTrail = m_vpTrails.empty()? NULL: m_vpTrails[m_iSelection[pn]]; - GAMESTATE->m_pCurTrail[pn] = pTrail; + GAMESTATE->m_pCurTrail[pn].Set( pTrail ); int iScore = 0; if( pTrail ) @@ -1503,14 +1503,14 @@ void ScreenSelectMusic::AfterMusicChange() m_GrooveGraph.SetFromSong( pSong ); Course* pCourse = m_MusicWheel.GetSelectedCourse(); - GAMESTATE->m_pCurCourse = pCourse; + GAMESTATE->m_pCurCourse.Set( pCourse ); if( pCourse ) GAMESTATE->m_pPreferredCourse = pCourse; FOREACH_PlayerNumber( p ) { GAMESTATE->m_pCurSteps[p].Set( NULL ); - GAMESTATE->m_pCurTrail[p] = NULL; + GAMESTATE->m_pCurTrail[p].Set( NULL ); m_vpSteps.clear(); m_vpTrails.clear(); } @@ -1660,8 +1660,6 @@ void ScreenSelectMusic::AfterMusicChange() m_Artists.push_back( pSong->GetDisplayArtist() ); m_AltArtists.push_back( pSong->GetTranslitArtist() ); - - MESSAGEMAN->Broadcast( "OnSongChanged" ); } break; case TYPE_ROULETTE: @@ -1775,8 +1773,6 @@ void ScreenSelectMusic::AfterMusicChange() COMMAND( m_sprCourseHasMods, "Hide" ); } - MESSAGEMAN->Broadcast( "OnCourseChanged" ); - break; } default: diff --git a/stepmania/src/ScreenTitleMenu.cpp b/stepmania/src/ScreenTitleMenu.cpp index fa17d3e46a..c0b761b5bd 100644 --- a/stepmania/src/ScreenTitleMenu.cpp +++ b/stepmania/src/ScreenTitleMenu.cpp @@ -52,8 +52,6 @@ ScreenTitleMenu::ScreenTitleMenu( CString sScreenName ) : // TRICKY: Do this after GameState::Reset. LIGHTSMAN->SetLightsMode( LIGHTSMODE_JOINING ); - - this->SubscribeToMessage( "CoinModeChanged" ); } void ScreenTitleMenu::Init() @@ -170,7 +168,7 @@ void ScreenTitleMenu::Input( const DeviceInput& DeviceI, const InputEventType ty void ScreenTitleMenu::HandleMessage( const CString& sMessage ) { - if( sMessage == "CoinModeChanged" ) + if( sMessage == PREFSMAN->m_CoinMode.GetName()+"Changed" ) { /* If the CoinMode was changed, we need to reload this screen * so that the right m_aGameCommands will show */ diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index ab75c8c2b5..c1e6392696 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -709,7 +709,10 @@ void SongManager::Invalidate( Song *pStaleSong ) } } - CONVERT_COURSE_POINTER( GAMESTATE->m_pCurCourse ); + { + CourseID id = mapOldCourseToCourseID[GAMESTATE->m_pCurCourse]; /* this will always succeed */ + GAMESTATE->m_pCurCourse.Set( id.ToCourse() ); + } CONVERT_COURSE_POINTER( GAMESTATE->m_pPreferredCourse ); #define CONVERT_TRAIL_POINTER( pTrail ) do { \ @@ -720,7 +723,7 @@ void SongManager::Invalidate( Song *pStaleSong ) const TrailIDAndCourse &tidc = it->second; \ const TrailID &id = tidc.first; \ const Course *pCourse = tidc.second; \ - pTrail = id.ToTrail( pCourse, true ); \ + pTrail.Set( id.ToTrail( pCourse, true ) ); \ } \ } while(false)