diff --git a/stepmania/src/DifficultyList.cpp b/stepmania/src/DifficultyList.cpp index 2fcd0109b4..d76d5773e6 100644 --- a/stepmania/src/DifficultyList.cpp +++ b/stepmania/src/DifficultyList.cpp @@ -98,7 +98,7 @@ int DifficultyList::GetCurrentRowIndex( PlayerNumber pn ) const } else { - if( GAMESTATE->m_pCurSteps[pn] == row.m_Steps ) + if( GAMESTATE->m_pCurSteps[pn].Get() == row.m_Steps ) return i; } } diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index deafa3f7c2..2a3b668851 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -113,7 +113,7 @@ bool GameCommand::DescribesCurrentMode( PlayerNumber pn ) const if( m_pSong && GAMESTATE->m_pCurSong.Get() != m_pSong ) return false; - if( m_pSteps && GAMESTATE->m_pCurSteps[pn] != m_pSteps ) + if( m_pSteps && GAMESTATE->m_pCurSteps[pn].Get() != m_pSteps ) return false; if( m_pCharacter && GAMESTATE->m_pCurCharacters[pn] != m_pCharacter ) return false; @@ -641,7 +641,7 @@ void GameCommand::Apply( const vector &vpns ) const } if( m_pSteps ) FOREACH_CONST( PlayerNumber, vpns, pn ) - GAMESTATE->m_pCurSteps.Set( *pn, m_pSteps ); + GAMESTATE->m_pCurSteps[*pn].Set( m_pSteps ); if( m_pCourse ) { GAMESTATE->m_pCurCourse = m_pCourse; diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index efab81cc2f..719454bf0d 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -159,7 +159,7 @@ void GameState::Reset() m_pCurSong.Set( NULL ); m_pPreferredSong = NULL; FOREACH_PlayerNumber( p ) - m_pCurSteps.Set( p, NULL ); + m_pCurSteps[p].Set( NULL ); m_pCurCourse = NULL; m_pPreferredCourse = NULL; FOREACH_PlayerNumber( p ) @@ -1846,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.Set( pn, NULL ); } - else { Steps *pS = Luna::check(L,2); p->m_pCurSteps.Set( pn, pS ); } + 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) ); return 0; } @@ -1940,7 +1940,7 @@ LuaFunction_StrStr( SetEnv, GAMESTATE->m_mapEnv[str1] = str2 ) /* Return an integer into SONGMAN->m_pSongs. This lets us do input checking, which we * can't easily do if we return pointers. */ LuaFunction_NoArgs( CurSong, (void *) GAMESTATE->m_pCurSong ) -LuaFunction_PlayerNumber( CurSteps, GAMESTATE->m_pCurSteps[pn] ) +LuaFunction_PlayerNumber( CurSteps, (Steps*)GAMESTATE->m_pCurSteps[pn].Get() ) bool PlayerIsUsingModifier( PlayerNumber pn, const CString sModifier ) { diff --git a/stepmania/src/MessageManager.h b/stepmania/src/MessageManager.h index 2aa04814ea..dccafd929e 100644 --- a/stepmania/src/MessageManager.h +++ b/stepmania/src/MessageManager.h @@ -22,7 +22,8 @@ enum Message MESSAGE_EDIT_STEPS_TYPE_CHANGED, MESSAGE_EDIT_SOURCE_STEPS_CHANGED, MESSAGE_EDIT_SOURCE_STEPS_TYPE_CHANGED, - NUM_MESSAGES + NUM_MESSAGES, + MESSAGE_INVALID }; const CString& MessageToString( Message m ); @@ -32,6 +33,7 @@ class BroadcastOnChange private: Message mSendWhenChanged; T val; + public: BroadcastOnChange( Message m ) { mSendWhenChanged = m; } const T Get() const { return val; } @@ -58,12 +60,16 @@ class BroadcastOnChangePtr1D { private: Message mSendWhenChanged; - T *val[N]; + typedef BroadcastOnChangePtr MyType; + vector val; public: - BroadcastOnChangePtr1D( Message m ) { mSendWhenChanged = m; } - const T* Get( unsigned i ) const { return val[i]; } - void Set( unsigned i, T* t ) { val[i] = t; MESSAGEMAN->Broadcast( MessageToString((Message)(mSendWhenChanged+i)) ); } - T* operator[]( unsigned i ) const { return val[i]; } + BroadcastOnChangePtr1D( Message m ) + { + for( unsigned i=0; i((Message)(m+i)) ); + } + const BroadcastOnChangePtr& operator[]( unsigned i ) const { return val[i]; } + BroadcastOnChangePtr& operator[]( unsigned i ) { return val[i]; } }; class MessageManager diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index e47e2b131c..76c546a37f 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.Set( p, pSteps ); + GAMESTATE->m_pCurSteps[p].Set( 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 fff87a1b5e..f8f37888a9 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -1148,7 +1148,7 @@ void ScreenEdit::InputEdit( const DeviceInput& DeviceI, const InputEventType typ } pSteps = *it; - GAMESTATE->m_pCurSteps.Set( PLAYER_1, pSteps ); + GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps ); m_pSteps = pSteps; pSteps->GetNoteData( m_NoteDataEdit ); SCREENMAN->SystemMessage( ssprintf( @@ -1593,7 +1593,7 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM ) StepsID id; id.FromSteps( m_pSteps ); - GAMESTATE->m_pCurSteps.Set( PLAYER_1, NULL ); /* make RevertFromDisk not try to reset it */ + GAMESTATE->m_pCurSteps[PLAYER_1].Set( NULL ); /* make RevertFromDisk not try to reset it */ SONGMAN->RevertFromDisk( GAMESTATE->m_pCurSong ); CString sMessage = "Reloaded from disk."; @@ -1625,7 +1625,7 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM ) SCREENMAN->SystemMessage( sMessage ); m_pSteps = pSteps; - GAMESTATE->m_pCurSteps.Set( PLAYER_1, pSteps ); + GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps ); m_pSteps->GetNoteData( m_NoteDataEdit ); break; diff --git a/stepmania/src/ScreenEditMenu.cpp b/stepmania/src/ScreenEditMenu.cpp index d47f52a700..3e7b5778f7 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.Set( PLAYER_1, pSteps ); + GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps ); // // handle error cases diff --git a/stepmania/src/ScreenEnding.cpp b/stepmania/src/ScreenEnding.cpp index 001ef38ac8..91d3f64deb 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.Set( PLAYER_1, GAMESTATE->m_pCurSong->GetAllSteps()[0] ); - GAMESTATE->m_pCurSteps.Set( PLAYER_2, GAMESTATE->m_pCurSong->GetAllSteps()[0] ); + 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].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 f4730f743b..c37d99e4e3 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.Set( PLAYER_1, GAMESTATE->m_pCurSong->GetAllSteps()[0] ); - GAMESTATE->m_pCurSteps.Set( PLAYER_2, GAMESTATE->m_pCurSong->GetAllSteps()[0] ); + 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].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 eff34d9640..c809c546e5 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.Set( pn, pSteps ); + GAMESTATE->m_pCurSteps[pn].Set( pSteps ); if( pSteps != NULL && pn == GAMESTATE->m_MasterPlayerNumber ) diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index e2a07aff62..c8fb732506 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.Set( p, GAMESTATE->m_pCurSteps[ GAMESTATE->GetFirstHumanPlayer() ] ); + GAMESTATE->m_pCurSteps[p].Set( 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.Set( p, m_vpStepsQueue[p][iSongIndex] ); + GAMESTATE->m_pCurSteps[p].Set( 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 fee621810e..c00411abf2 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.Set( p, GAMESTATE->m_pCurSteps[ GAMESTATE->GetFirstHumanPlayer() ] ); + GAMESTATE->m_pCurSteps[p].Set( 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.Set( GAMESTATE->m_MasterPlayerNumber, m_vpStepsQueue[iSongIndex] ); + GAMESTATE->m_pCurSteps[GAMESTATE->m_MasterPlayerNumber].Set( 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 7523a5c561..5c30008d40 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.Set( p, pSteps ); + GAMESTATE->m_pCurSteps[p].Set( pSteps ); return true; // done looking } diff --git a/stepmania/src/ScreenNameEntryTraditional.cpp b/stepmania/src/ScreenNameEntryTraditional.cpp index 64a9ad5eb8..35ffb90571 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.Set( p, ss.m_player[p].vpSteps[0] ); + GAMESTATE->m_pCurSteps[p].Set( 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 0234818d90..9d0b96cc93 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.Set( pn, pSteps ); + GAMESTATE->m_pCurSteps[pn].Set( pSteps ); } TweenOffScreen(); diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index f269aa3e07..1a87ec889d 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.Set( pn, pSteps ); + GAMESTATE->m_pCurSteps[pn].Set( pSteps ); int iScore = 0; if( pSteps ) @@ -1397,7 +1397,7 @@ void ScreenSelectMusic::AfterMusicChange() FOREACH_PlayerNumber( p ) { - GAMESTATE->m_pCurSteps.Set( p, NULL ); + GAMESTATE->m_pCurSteps[p].Set( 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 52153b5def..b9022c5efd 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -799,18 +799,18 @@ void SongManager::RevertFromDisk( Song *pSong, bool bAllowNotesLoss ) } \ } while(false) -#define CONVERT_STEPS_POINTER2( pStepsRead, pStepsWrite, p ) do { \ - if( pStepsRead != NULL ) { \ - map::iterator it = mapOldStepsToStepsID.find(pStepsRead); \ +#define CONVERT_STEPS_POINTER2( pSteps ) do { \ + if( pSteps != NULL ) { \ + map::iterator it = mapOldStepsToStepsID.find(pSteps); \ if( it != mapOldStepsToStepsID.end() ) \ - pStepsWrite.Set( p, it->second.ToSteps(pSong, bAllowNotesLoss) ); \ + pSteps.Set( it->second.ToSteps(pSong, bAllowNotesLoss) ); \ } \ } while(false) FOREACH_PlayerNumber( p ) { - CONVERT_STEPS_POINTER2( GAMESTATE->m_pCurSteps[p], GAMESTATE->m_pCurSteps, p ); + CONVERT_STEPS_POINTER2( GAMESTATE->m_pCurSteps[p] ); FOREACH( Steps*, STATSMAN->m_CurStageStats.m_player[p].vpSteps, pSteps ) CONVERT_STEPS_POINTER( *pSteps );