From 4104edcad9eae7a135aec31b19ed5f56646f6759 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 25 Feb 2005 05:27:28 +0000 Subject: [PATCH] use BroadcastOnChange wrappers --- stepmania/src/GameCommand.cpp | 2 +- stepmania/src/GameState.cpp | 27 +++++++++++++++----- stepmania/src/GameState.h | 10 ++++---- stepmania/src/MusicWheel.cpp | 2 +- stepmania/src/ScreenEdit.cpp | 8 +++--- stepmania/src/ScreenEditMenu.cpp | 2 +- stepmania/src/ScreenEnding.cpp | 4 +-- stepmania/src/ScreenEvaluation.cpp | 4 +-- stepmania/src/ScreenEz2SelectMusic.cpp | 2 +- stepmania/src/ScreenGameplay.cpp | 4 +-- stepmania/src/ScreenGameplayMultiplayer.cpp | 4 +-- stepmania/src/ScreenJukebox.cpp | 2 +- stepmania/src/ScreenNameEntryTraditional.cpp | 2 +- stepmania/src/ScreenNetSelectMusic.cpp | 2 +- stepmania/src/ScreenSelectMusic.cpp | 4 +-- stepmania/src/SongManager.cpp | 12 +++++++-- 16 files changed, 57 insertions(+), 34 deletions(-) diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index 7bc59649d5..deafa3f7c2 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -641,7 +641,7 @@ void GameCommand::Apply( const vector &vpns ) const } if( m_pSteps ) FOREACH_CONST( PlayerNumber, vpns, pn ) - GAMESTATE->m_pCurSteps[*pn] = m_pSteps; + GAMESTATE->m_pCurSteps.Set( *pn, m_pSteps ); if( m_pCourse ) { GAMESTATE->m_pCurCourse = m_pCourse; diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index cd0ef660f6..efab81cc2f 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -41,7 +41,12 @@ GameState* GAMESTATE = NULL; // global and accessable from anywhere in our progr #define CHARACTERS_DIR "Characters/" #define NAMES_BLACKLIST_FILE "Data/NamesBlacklist.dat" -GameState::GameState() +GameState::GameState() : + m_pCurSong( MESSAGE_CURRENT_SONG_CHANGED ), + m_pCurSteps( MESSAGE_CURRENT_STEPS_P1_CHANGED ), + m_stEdit( MESSAGE_EDIT_STEPS_TYPE_CHANGED ), + m_pEditSourceSteps( MESSAGE_EDIT_SOURCE_STEPS_CHANGED ), + m_stEditSource( MESSAGE_EDIT_SOURCE_STEPS_TYPE_CHANGED ) { m_pCurStyle = NULL; @@ -154,7 +159,7 @@ void GameState::Reset() m_pCurSong.Set( NULL ); m_pPreferredSong = NULL; FOREACH_PlayerNumber( p ) - m_pCurSteps[p] = NULL; + m_pCurSteps.Set( p, NULL ); m_pCurCourse = NULL; m_pPreferredCourse = NULL; FOREACH_PlayerNumber( p ) @@ -208,9 +213,9 @@ void GameState::Reset() LIGHTSMAN->SetLightsMode( LIGHTSMODE_ATTRACT ); - m_stEdit = STEPS_TYPE_INVALID; - m_pStepsEditSource = NULL; - m_stEditSource = STEPS_TYPE_INVALID; + m_stEdit.Set( STEPS_TYPE_INVALID ); + m_pEditSourceSteps.Set( NULL ); + m_stEditSource.Set( STEPS_TYPE_INVALID ); ApplyCmdline(); } @@ -1841,8 +1846,8 @@ public: static int SetCurrentSteps( T* p, lua_State *L ) { PlayerNumber pn = (PlayerNumber)IArg(1); - if( lua_isnil(L,2) ) { p->m_pCurSteps[pn] = NULL; } - else { Steps *pS = Luna::check(L,2); p->m_pCurSteps[pn] = pS; } + if( lua_isnil(L,2) ) { p->m_pCurSteps.Set( pn, NULL ); } + else { Steps *pS = Luna::check(L,2); p->m_pCurSteps.Set( pn, pS ); } MESSAGEMAN->Broadcast( ssprintf("CurrentStepsP%dChanged",pn+1) ); return 0; } @@ -1864,6 +1869,13 @@ public: lua_pushnil(L); return 1; } + static int GetEditSourceSteps( T* p, lua_State *L ) + { + Steps *pSteps = p->m_pEditSourceSteps; + if( pSteps ) { pSteps->PushSelf(L); } + else { lua_pushnil(L); } + return 1; + } static void Register(lua_State *L) { @@ -1881,6 +1893,7 @@ public: ADD_METHOD( SetTemporaryEventMode ) ADD_METHOD( SetEnv ) ADD_METHOD( GetEnv ) + ADD_METHOD( GetEditSourceSteps ) Luna::Register( L ); // Add global singleton if constructed already. If it's not constructed yet, diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 5b08d87a27..5930e6afd7 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -129,10 +129,10 @@ public: // // NULL on ScreenSelectMusic if the currently selected wheel item isn't a Song. - BroadcastOnChangePtr m_pCurSong; + BroadcastOnChangePtr m_pCurSong; // The last Song that the user manually changed to. Song* m_pPreferredSong; - Steps* m_pCurSteps[NUM_PLAYERS]; + BroadcastOnChangePtr1D m_pCurSteps; // NULL on ScreenSelectMusic if the currently selected wheel item isn't a Course. Course* m_pCurCourse; @@ -285,9 +285,9 @@ public: // // Edit stuff // - StepsType m_stEdit; - Steps *m_pStepsEditSource; - StepsType m_stEditSource; + BroadcastOnChange m_stEdit; + BroadcastOnChangePtr m_pEditSourceSteps; + BroadcastOnChange m_stEditSource; // Lua void PushSelf( lua_State *L ); diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index a1c75962eb..e47e2b131c 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -175,7 +175,7 @@ void MusicWheel::Load() GAMESTATE->m_pPreferredSong = pSong; FOREACH_HumanPlayer( p ) { - GAMESTATE->m_pCurSteps[p] = pSteps; + GAMESTATE->m_pCurSteps.Set( p, pSteps ); GAMESTATE->m_pPlayerState[p]->m_PlayerOptions = po; GAMESTATE->m_PreferredDifficulty[p] = pSteps->GetDifficulty(); } diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index b088df47a2..fff87a1b5e 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -1148,7 +1148,8 @@ void ScreenEdit::InputEdit( const DeviceInput& DeviceI, const InputEventType typ } pSteps = *it; - GAMESTATE->m_pCurSteps[PLAYER_1] = m_pSteps = pSteps; + GAMESTATE->m_pCurSteps.Set( PLAYER_1, pSteps ); + m_pSteps = pSteps; pSteps->GetNoteData( m_NoteDataEdit ); SCREENMAN->SystemMessage( ssprintf( "Switched to %s %s '%s'", @@ -1592,7 +1593,7 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM ) StepsID id; id.FromSteps( m_pSteps ); - GAMESTATE->m_pCurSteps[PLAYER_1] = NULL; /* make RevertFromDisk not try to reset it */ + GAMESTATE->m_pCurSteps.Set( PLAYER_1, NULL ); /* make RevertFromDisk not try to reset it */ SONGMAN->RevertFromDisk( GAMESTATE->m_pCurSong ); CString sMessage = "Reloaded from disk."; @@ -1623,7 +1624,8 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM ) SCREENMAN->SystemMessage( sMessage ); - m_pSteps = GAMESTATE->m_pCurSteps[PLAYER_1] = pSteps; + m_pSteps = pSteps; + GAMESTATE->m_pCurSteps.Set( PLAYER_1, pSteps ); m_pSteps->GetNoteData( m_NoteDataEdit ); break; diff --git a/stepmania/src/ScreenEditMenu.cpp b/stepmania/src/ScreenEditMenu.cpp index f48761dd63..d47f52a700 100644 --- a/stepmania/src/ScreenEditMenu.cpp +++ b/stepmania/src/ScreenEditMenu.cpp @@ -112,7 +112,7 @@ void ScreenEditMenu::MenuStart( PlayerNumber pn ) GAMESTATE->m_pCurSong.Set( pSong ); GAMESTATE->m_pCurStyle = GAMEMAN->GetEditorStyleForStepsType( st ); - GAMESTATE->m_pCurSteps[PLAYER_1] = pSteps; + GAMESTATE->m_pCurSteps.Set( PLAYER_1, pSteps ); // // handle error cases diff --git a/stepmania/src/ScreenEnding.cpp b/stepmania/src/ScreenEnding.cpp index 233c72883a..001ef38ac8 100644 --- a/stepmania/src/ScreenEnding.cpp +++ b/stepmania/src/ScreenEnding.cpp @@ -150,8 +150,8 @@ ScreenEnding::ScreenEnding( CString sClassName ) : ScreenAttract( sClassName, fa GAMESTATE->m_MasterPlayerNumber = PLAYER_1; GAMESTATE->m_pCurSong.Set( SONGMAN->GetRandomSong() ); GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse(); - GAMESTATE->m_pCurSteps[PLAYER_1] = GAMESTATE->m_pCurSong->GetAllSteps()[0]; - GAMESTATE->m_pCurSteps[PLAYER_2] = GAMESTATE->m_pCurSong->GetAllSteps()[0]; + GAMESTATE->m_pCurSteps.Set( PLAYER_1, GAMESTATE->m_pCurSong->GetAllSteps()[0] ); + GAMESTATE->m_pCurSteps.Set( PLAYER_2, GAMESTATE->m_pCurSong->GetAllSteps()[0] ); STATSMAN->m_CurStageStats.m_player[PLAYER_1].vpSteps.push_back( GAMESTATE->m_pCurSteps[PLAYER_1] ); STATSMAN->m_CurStageStats.m_player[PLAYER_2].vpSteps.push_back( GAMESTATE->m_pCurSteps[PLAYER_2] ); GAMESTATE->m_pPlayerState[PLAYER_1]->m_PlayerOptions.m_fScrollSpeed = 2; diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 5f4ffdd082..f4730f743b 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -111,8 +111,8 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName ) : ScreenWithMenuElement GAMESTATE->m_pCurSong.Set( SONGMAN->GetRandomSong() ); STATSMAN->m_CurStageStats.vpSongs.push_back( GAMESTATE->m_pCurSong ); GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse(); - GAMESTATE->m_pCurSteps[PLAYER_1] = GAMESTATE->m_pCurSong->GetAllSteps()[0]; - GAMESTATE->m_pCurSteps[PLAYER_2] = GAMESTATE->m_pCurSong->GetAllSteps()[0]; + GAMESTATE->m_pCurSteps.Set( PLAYER_1, GAMESTATE->m_pCurSong->GetAllSteps()[0] ); + GAMESTATE->m_pCurSteps.Set( PLAYER_2, GAMESTATE->m_pCurSong->GetAllSteps()[0] ); STATSMAN->m_CurStageStats.m_player[PLAYER_1].vpSteps.push_back( GAMESTATE->m_pCurSteps[PLAYER_1] ); STATSMAN->m_CurStageStats.m_player[PLAYER_2].vpSteps.push_back( GAMESTATE->m_pCurSteps[PLAYER_2] ); GAMESTATE->m_pPlayerState[PLAYER_1]->m_PlayerOptions.m_fScrollSpeed = 2; diff --git a/stepmania/src/ScreenEz2SelectMusic.cpp b/stepmania/src/ScreenEz2SelectMusic.cpp index bf71917b8a..eff34d9640 100644 --- a/stepmania/src/ScreenEz2SelectMusic.cpp +++ b/stepmania/src/ScreenEz2SelectMusic.cpp @@ -681,7 +681,7 @@ void ScreenEz2SelectMusic::AfterNotesChange( PlayerNumber pn ) Steps* pSteps = m_arrayNotes[pn].empty()? NULL: m_arrayNotes[pn][m_iSelection[pn]]; - GAMESTATE->m_pCurSteps[pn] = pSteps; + GAMESTATE->m_pCurSteps.Set( pn, pSteps ); if( pSteps != NULL && pn == GAMESTATE->m_MasterPlayerNumber ) diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index c853f11dda..e2a07aff62 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -154,7 +154,7 @@ void ScreenGameplay::Init() // fill in difficulty of CPU players with that of the first human player FOREACH_PotentialCpuPlayer(p) - GAMESTATE->m_pCurSteps[p] = GAMESTATE->m_pCurSteps[ GAMESTATE->GetFirstHumanPlayer() ]; + GAMESTATE->m_pCurSteps.Set( p, GAMESTATE->m_pCurSteps[ GAMESTATE->GetFirstHumanPlayer() ] ); switch( GAMESTATE->m_PlayMode ) { @@ -804,7 +804,7 @@ void ScreenGameplay::SetupSong( PlayerNumber p, int iSongIndex ) /* This is the first beat that can be changed without it being visible. Until * we draw for the first time, any beat can be changed. */ GAMESTATE->m_pPlayerState[p]->m_fLastDrawnBeat = -100; - GAMESTATE->m_pCurSteps[p] = m_vpStepsQueue[p][iSongIndex]; + GAMESTATE->m_pCurSteps.Set( p, m_vpStepsQueue[p][iSongIndex] ); /* Load new NoteData into Player. Do this before * RebuildPlayerOptionsFromActiveAttacks or else transform mods will get diff --git a/stepmania/src/ScreenGameplayMultiplayer.cpp b/stepmania/src/ScreenGameplayMultiplayer.cpp index 6e4ce8d028..fee621810e 100644 --- a/stepmania/src/ScreenGameplayMultiplayer.cpp +++ b/stepmania/src/ScreenGameplayMultiplayer.cpp @@ -90,7 +90,7 @@ void ScreenGameplayMultiplayer::Init() // fill in difficulty of CPU players with that of the first human player FOREACH_PotentialCpuPlayer(p) - GAMESTATE->m_pCurSteps[p] = GAMESTATE->m_pCurSteps[ GAMESTATE->GetFirstHumanPlayer() ]; + GAMESTATE->m_pCurSteps.Set( p, GAMESTATE->m_pCurSteps[ GAMESTATE->GetFirstHumanPlayer() ] ); @@ -289,7 +289,7 @@ void ScreenGameplayMultiplayer::SetupSong( MultiPlayer p, int iSongIndex ) /* This is the first beat that can be changed without it being visible. Until * we draw for the first time, any beat can be changed. */ GAMESTATE->m_pPlayerState[GAMESTATE->m_MasterPlayerNumber]->m_fLastDrawnBeat = -100; - GAMESTATE->m_pCurSteps[GAMESTATE->m_MasterPlayerNumber] = m_vpStepsQueue[iSongIndex]; + GAMESTATE->m_pCurSteps.Set( GAMESTATE->m_MasterPlayerNumber, m_vpStepsQueue[iSongIndex] ); /* Load new NoteData into Player. Do this before * RebuildPlayerOptionsFromActiveAttacks or else transform mods will get diff --git a/stepmania/src/ScreenJukebox.cpp b/stepmania/src/ScreenJukebox.cpp index 3d70e3e451..7523a5c561 100644 --- a/stepmania/src/ScreenJukebox.cpp +++ b/stepmania/src/ScreenJukebox.cpp @@ -101,7 +101,7 @@ bool ScreenJukebox::SetSong( bool bDemonstration ) // Found something we can use! GAMESTATE->m_pCurSong.Set( pSong ); FOREACH_PlayerNumber( p ) - GAMESTATE->m_pCurSteps[p] = pSteps; + GAMESTATE->m_pCurSteps.Set( p, pSteps ); return true; // done looking } diff --git a/stepmania/src/ScreenNameEntryTraditional.cpp b/stepmania/src/ScreenNameEntryTraditional.cpp index ec208d2132..64a9ad5eb8 100644 --- a/stepmania/src/ScreenNameEntryTraditional.cpp +++ b/stepmania/src/ScreenNameEntryTraditional.cpp @@ -144,7 +144,7 @@ ScreenNameEntryTraditional::ScreenNameEntryTraditional( CString sClassName ) : S FOREACH_PlayerNumber( p ) { ss.m_player[p].vpSteps.push_back( ss.vpSongs[0]->GetAllSteps()[0] ); - GAMESTATE->m_pCurSteps[p] = ss.m_player[p].vpSteps[0]; + GAMESTATE->m_pCurSteps.Set( p, ss.m_player[p].vpSteps[0] ); ss.m_player[p].iPossibleDancePoints = 1000; ss.m_player[p].iActualDancePoints = 985; diff --git a/stepmania/src/ScreenNetSelectMusic.cpp b/stepmania/src/ScreenNetSelectMusic.cpp index 1f5614722b..0234818d90 100644 --- a/stepmania/src/ScreenNetSelectMusic.cpp +++ b/stepmania/src/ScreenNetSelectMusic.cpp @@ -445,7 +445,7 @@ void ScreenNetSelectMusic::StartSelectedSong() { GAMESTATE->m_PreferredDifficulty[pn] = m_DC[pn]; Steps * pSteps = pSong->GetStepsByDifficulty(st,m_DC[pn]); - GAMESTATE->m_pCurSteps[pn] = pSteps; + GAMESTATE->m_pCurSteps.Set( pn, pSteps ); } TweenOffScreen(); diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 14c2dd957d..f269aa3e07 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -1225,7 +1225,7 @@ void ScreenSelectMusic::AfterStepsChange( PlayerNumber pn ) Song* pSong = GAMESTATE->m_pCurSong; Steps* pSteps = m_vpSteps.empty()? NULL: m_vpSteps[m_iSelection[pn]]; - GAMESTATE->m_pCurSteps[pn] = pSteps; + GAMESTATE->m_pCurSteps.Set( pn, pSteps ); int iScore = 0; if( pSteps ) @@ -1397,7 +1397,7 @@ void ScreenSelectMusic::AfterMusicChange() FOREACH_PlayerNumber( p ) { - GAMESTATE->m_pCurSteps[p] = NULL; + GAMESTATE->m_pCurSteps.Set( p, NULL ); GAMESTATE->m_pCurTrail[p] = NULL; m_vpSteps.clear(); m_vpTrails.clear(); diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index be15f5fba8..52153b5def 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -795,14 +795,22 @@ void SongManager::RevertFromDisk( Song *pSong, bool bAllowNotesLoss ) if( pSteps != NULL ) { \ map::iterator it = mapOldStepsToStepsID.find(pSteps); \ if( it != mapOldStepsToStepsID.end() ) \ - pSteps = it->second.ToSteps( pSong, bAllowNotesLoss ); \ + pSteps = it->second.ToSteps(pSong, bAllowNotesLoss); \ + } \ +} while(false) + +#define CONVERT_STEPS_POINTER2( pStepsRead, pStepsWrite, p ) do { \ + if( pStepsRead != NULL ) { \ + map::iterator it = mapOldStepsToStepsID.find(pStepsRead); \ + if( it != mapOldStepsToStepsID.end() ) \ + pStepsWrite.Set( p, it->second.ToSteps(pSong, bAllowNotesLoss) ); \ } \ } while(false) FOREACH_PlayerNumber( p ) { - CONVERT_STEPS_POINTER( GAMESTATE->m_pCurSteps[p] ); + CONVERT_STEPS_POINTER2( GAMESTATE->m_pCurSteps[p], GAMESTATE->m_pCurSteps, p ); FOREACH( Steps*, STATSMAN->m_CurStageStats.m_player[p].vpSteps, pSteps ) CONVERT_STEPS_POINTER( *pSteps );