enforce that changed message is broadcast whenever value changes

This commit is contained in:
Chris Danford
2005-02-24 12:27:30 +00:00
parent 94743864e6
commit ab22e629d4
19 changed files with 54 additions and 26 deletions
+2 -2
View File
@@ -111,7 +111,7 @@ bool GameCommand::DescribesCurrentMode( PlayerNumber pn ) const
return false; return false;
} }
if( m_pSong && GAMESTATE->m_pCurSong != m_pSong ) if( m_pSong && GAMESTATE->m_pCurSong.Get() != m_pSong )
return false; return false;
if( m_pSteps && GAMESTATE->m_pCurSteps[pn] != m_pSteps ) if( m_pSteps && GAMESTATE->m_pCurSteps[pn] != m_pSteps )
return false; return false;
@@ -636,7 +636,7 @@ void GameCommand::Apply( const vector<PlayerNumber> &vpns ) const
SCREENMAN->SetNewScreen( m_sScreen ); SCREENMAN->SetNewScreen( m_sScreen );
if( m_pSong ) if( m_pSong )
{ {
GAMESTATE->m_pCurSong = m_pSong; GAMESTATE->m_pCurSong.Set( m_pSong );
GAMESTATE->m_pPreferredSong = m_pSong; GAMESTATE->m_pPreferredSong = m_pSong;
} }
if( m_pSteps ) if( m_pSteps )
+3 -4
View File
@@ -151,7 +151,7 @@ void GameState::Reset()
m_iGameSeed = rand(); m_iGameSeed = rand();
m_iRoundSeed = rand(); m_iRoundSeed = rand();
m_pCurSong = NULL; m_pCurSong.Set( NULL );
m_pPreferredSong = NULL; m_pPreferredSong = NULL;
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
m_pCurSteps[p] = NULL; m_pCurSteps[p] = NULL;
@@ -1826,9 +1826,8 @@ public:
static int GetCurrentSong( T* p, lua_State *L ) { if(p->m_pCurSong) p->m_pCurSong->PushSelf(L); else lua_pushnil(L); return 1; } static int GetCurrentSong( T* p, lua_State *L ) { if(p->m_pCurSong) p->m_pCurSong->PushSelf(L); else lua_pushnil(L); return 1; }
static int SetCurrentSong( T* p, lua_State *L ) static int SetCurrentSong( T* p, lua_State *L )
{ {
if( lua_isnil(L,1) ) { p->m_pCurSong = NULL; } if( lua_isnil(L,1) ) { p->m_pCurSong.Set( NULL ); }
else { Song *pS = Luna<Song>::check(L,1); p->m_pCurSong = pS; } else { Song *pS = Luna<Song>::check(L,1); p->m_pCurSong.Set( pS ); }
MESSAGEMAN->Broadcast( "CurrentSongChanged" );
return 0; return 0;
} }
static int GetCurrentSteps( T* p, lua_State *L ) static int GetCurrentSteps( T* p, lua_State *L )
+3 -1
View File
@@ -9,6 +9,7 @@
#include "Attack.h" #include "Attack.h"
#include "RageTimer.h" #include "RageTimer.h"
#include "Difficulty.h" #include "Difficulty.h"
#include "MessageManager.h"
#include <map> #include <map>
#include <deque> #include <deque>
@@ -26,6 +27,7 @@ struct StageStats;
struct PlayerState; struct PlayerState;
struct lua_State; struct lua_State;
class GameState class GameState
{ {
public: public:
@@ -127,7 +129,7 @@ public:
// //
// NULL on ScreenSelectMusic if the currently selected wheel item isn't a Song. // NULL on ScreenSelectMusic if the currently selected wheel item isn't a Song.
Song* m_pCurSong; BroadcastOnChangePtr<Song,MESSAGE_CURRENT_SONG_CHANGED> m_pCurSong;
// The last Song that the user manually changed to. // The last Song that the user manually changed to.
Song* m_pPreferredSong; Song* m_pPreferredSong;
Steps* m_pCurSteps[NUM_PLAYERS]; Steps* m_pCurSteps[NUM_PLAYERS];
+7
View File
@@ -3,10 +3,17 @@
#include "Foreach.h" #include "Foreach.h"
#include "Actor.h" #include "Actor.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "EnumHelper.h"
MessageManager* MESSAGEMAN = NULL; // global and accessable from anywhere in our program MessageManager* MESSAGEMAN = NULL; // global and accessable from anywhere in our program
static const CString MessageNames[NUM_MESSAGES] = {
"CurrentSongChanged",
};
XToString( Message );
MessageManager::MessageManager() MessageManager::MessageManager()
{ {
} }
+19
View File
@@ -12,6 +12,25 @@ public:
virtual void HandleMessage( const CString& sMessage ) = 0; virtual void HandleMessage( const CString& sMessage ) = 0;
}; };
enum Message
{
MESSAGE_CURRENT_SONG_CHANGED,
NUM_MESSAGES
};
const CString& MessageToString( Message m );
template<class T, Message M>
class BroadcastOnChangePtr
{
private:
T *val;
public:
const T* Get() { return val; }
void Set( T* t ) { val = t; MESSAGEMAN->Broadcast( MessageToString(M) ); }
operator T* () const { return val; }
T* operator->() const { return val; }
};
class MessageManager class MessageManager
{ {
public: public:
+3 -2
View File
@@ -171,7 +171,8 @@ void MusicWheel::Load()
pSteps, pSteps,
po, po,
so ); so );
GAMESTATE->m_pCurSong = GAMESTATE->m_pPreferredSong = pSong; GAMESTATE->m_pCurSong.Set( pSong );
GAMESTATE->m_pPreferredSong = pSong;
FOREACH_HumanPlayer( p ) FOREACH_HumanPlayer( p )
{ {
GAMESTATE->m_pCurSteps[p] = pSteps; GAMESTATE->m_pCurSteps[p] = pSteps;
@@ -235,7 +236,7 @@ void MusicWheel::Load()
&& !GAMESTATE->GetEventMode() && !GAMESTATE->GetEventMode()
&& !GAMESTATE->IsExtraStage() && !GAMESTATE->IsExtraStage2() ) && !GAMESTATE->IsExtraStage() && !GAMESTATE->IsExtraStage2() )
{ {
GAMESTATE->m_pCurSong = NULL; GAMESTATE->m_pCurSong.Set( NULL );
} }
// Select the the previously selected song (if any) // Select the the previously selected song (if any)
+1 -1
View File
@@ -946,7 +946,7 @@ void OptionRowHandlerList::FillSongsInCurrentSongGroup( OptionRowDefinition &def
SONGMAN->GetSongs( vpSongs, GAMESTATE->m_sPreferredSongGroup ); SONGMAN->GetSongs( vpSongs, GAMESTATE->m_sPreferredSongGroup );
if( GAMESTATE->m_pCurSong == NULL ) if( GAMESTATE->m_pCurSong == NULL )
GAMESTATE->m_pCurSong = vpSongs[0]; GAMESTATE->m_pCurSong.Set( vpSongs[0] );
defOut.name = "SongsInCurrentSongGroup"; defOut.name = "SongsInCurrentSongGroup";
defOut.bOneChoiceForAllPlayers = true; defOut.bOneChoiceForAllPlayers = true;
+1 -1
View File
@@ -110,7 +110,7 @@ void ScreenEditMenu::MenuStart( PlayerNumber pn )
Steps* pSourceNotes = m_Selector.GetSelectedSourceNotes(); Steps* pSourceNotes = m_Selector.GetSelectedSourceNotes();
EditMenu::Action action = m_Selector.GetSelectedAction(); EditMenu::Action action = m_Selector.GetSelectedAction();
GAMESTATE->m_pCurSong = pSong; GAMESTATE->m_pCurSong.Set( pSong );
GAMESTATE->m_pCurStyle = GAMEMAN->GetEditorStyleForStepsType( st ); GAMESTATE->m_pCurStyle = GAMEMAN->GetEditorStyleForStepsType( st );
GAMESTATE->m_pCurSteps[PLAYER_1] = pSteps; GAMESTATE->m_pCurSteps[PLAYER_1] = pSteps;
+1 -1
View File
@@ -148,7 +148,7 @@ ScreenEnding::ScreenEnding( CString sClassName ) : ScreenAttract( sClassName, fa
GAMESTATE->m_bSideIsJoined[PLAYER_1] = true; GAMESTATE->m_bSideIsJoined[PLAYER_1] = true;
GAMESTATE->m_bSideIsJoined[PLAYER_2] = true; GAMESTATE->m_bSideIsJoined[PLAYER_2] = true;
GAMESTATE->m_MasterPlayerNumber = PLAYER_1; GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
GAMESTATE->m_pCurSong = SONGMAN->GetRandomSong(); GAMESTATE->m_pCurSong.Set( SONGMAN->GetRandomSong() );
GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse(); GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse();
GAMESTATE->m_pCurSteps[PLAYER_1] = GAMESTATE->m_pCurSong->GetAllSteps()[0]; GAMESTATE->m_pCurSteps[PLAYER_1] = GAMESTATE->m_pCurSong->GetAllSteps()[0];
GAMESTATE->m_pCurSteps[PLAYER_2] = GAMESTATE->m_pCurSong->GetAllSteps()[0]; GAMESTATE->m_pCurSteps[PLAYER_2] = GAMESTATE->m_pCurSong->GetAllSteps()[0];
+1 -1
View File
@@ -108,7 +108,7 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName ) : ScreenWithMenuElement
GAMESTATE->m_bSideIsJoined[PLAYER_1] = true; GAMESTATE->m_bSideIsJoined[PLAYER_1] = true;
GAMESTATE->m_bSideIsJoined[PLAYER_2] = true; GAMESTATE->m_bSideIsJoined[PLAYER_2] = true;
GAMESTATE->m_MasterPlayerNumber = PLAYER_1; GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
GAMESTATE->m_pCurSong = SONGMAN->GetRandomSong(); GAMESTATE->m_pCurSong.Set( SONGMAN->GetRandomSong() );
STATSMAN->m_CurStageStats.vpSongs.push_back( GAMESTATE->m_pCurSong ); STATSMAN->m_CurStageStats.vpSongs.push_back( GAMESTATE->m_pCurSong );
GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse(); GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse();
GAMESTATE->m_pCurSteps[PLAYER_1] = GAMESTATE->m_pCurSong->GetAllSteps()[0]; GAMESTATE->m_pCurSteps[PLAYER_1] = GAMESTATE->m_pCurSong->GetAllSteps()[0];
+1 -1
View File
@@ -604,7 +604,7 @@ void ScreenEz2SelectMusic::HarderDifficulty( PlayerNumber pn )
void ScreenEz2SelectMusic::MusicChanged() void ScreenEz2SelectMusic::MusicChanged()
{ {
Song* pSong = m_MusicBannerWheel.GetSelectedSong(); Song* pSong = m_MusicBannerWheel.GetSelectedSong();
GAMESTATE->m_pCurSong = pSong; GAMESTATE->m_pCurSong.Set( pSong );
m_CurrentGroup.SetText( SONGMAN->ShortenGroupName( pSong->m_sGroupName ) , ""); m_CurrentGroup.SetText( SONGMAN->ShortenGroupName( pSong->m_sGroupName ) , "");
m_CurrentGroup.SetDiffuse( SONGMAN->GetGroupColor(pSong->m_sGroupName) ); m_CurrentGroup.SetDiffuse( SONGMAN->GetGroupColor(pSong->m_sGroupName) );
+3 -3
View File
@@ -903,7 +903,7 @@ void ScreenGameplay::LoadNextSong()
int iPlaySongIndex = GAMESTATE->GetCourseSongIndex(); int iPlaySongIndex = GAMESTATE->GetCourseSongIndex();
iPlaySongIndex %= m_apSongsQueue.size(); iPlaySongIndex %= m_apSongsQueue.size();
GAMESTATE->m_pCurSong = m_apSongsQueue[iPlaySongIndex]; GAMESTATE->m_pCurSong.Set( m_apSongsQueue[iPlaySongIndex] );
STATSMAN->m_CurStageStats.vpSongs.push_back( GAMESTATE->m_pCurSong ); STATSMAN->m_CurStageStats.vpSongs.push_back( GAMESTATE->m_pCurSong );
// No need to do this here. We do it in SongFinished(). // No need to do this here. We do it in SongFinished().
@@ -2162,10 +2162,10 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM )
int iPlaySongIndex = GAMESTATE->GetCourseSongIndex()+1; int iPlaySongIndex = GAMESTATE->GetCourseSongIndex()+1;
iPlaySongIndex %= m_apSongsQueue.size(); iPlaySongIndex %= m_apSongsQueue.size();
GAMESTATE->m_pCurSong = m_apSongsQueue[iPlaySongIndex]; GAMESTATE->m_pCurSong.Set( m_apSongsQueue[iPlaySongIndex] );
m_NextSongOut.Load( THEME->GetPathB(m_sName,"next song out") ); m_NextSongOut.Load( THEME->GetPathB(m_sName,"next song out") );
GAMESTATE->m_pCurSong = pCurSong; GAMESTATE->m_pCurSong.Set( pCurSong );
m_NextSongOut.StartTransitioning( SM_LoadNextSong ); m_NextSongOut.StartTransitioning( SM_LoadNextSong );
LoadCourseSongNumber( GetMaxSongsPlayed()+1 ); LoadCourseSongNumber( GetMaxSongsPlayed()+1 );
+1 -1
View File
@@ -348,7 +348,7 @@ void ScreenGameplayMultiplayer::LoadNextSong()
int iPlaySongIndex = GAMESTATE->GetCourseSongIndex(); int iPlaySongIndex = GAMESTATE->GetCourseSongIndex();
iPlaySongIndex %= m_vpSongsQueue.size(); iPlaySongIndex %= m_vpSongsQueue.size();
GAMESTATE->m_pCurSong = m_vpSongsQueue[iPlaySongIndex]; GAMESTATE->m_pCurSong.Set( m_vpSongsQueue[iPlaySongIndex] );
STATSMAN->m_CurStageStats.vpSongs.push_back( GAMESTATE->m_pCurSong ); STATSMAN->m_CurStageStats.vpSongs.push_back( GAMESTATE->m_pCurSong );
// No need to do this here. We do it in SongFinished(). // No need to do this here. We do it in SongFinished().
+1 -1
View File
@@ -154,7 +154,7 @@ void ScreenHowToPlay::Init()
pSteps->GetNoteData( tempNoteData ); pSteps->GetNoteData( tempNoteData );
pStyle->GetTransformedNoteDataForStyle( PLAYER_1, tempNoteData, m_NoteData ); pStyle->GetTransformedNoteDataForStyle( PLAYER_1, tempNoteData, m_NoteData );
GAMESTATE->m_pCurSong = &m_Song; GAMESTATE->m_pCurSong.Set( &m_Song );
GAMESTATE->m_bPastHereWeGo = true; GAMESTATE->m_bPastHereWeGo = true;
GAMESTATE->m_pPlayerState[PLAYER_1]->m_PlayerController = PC_AUTOPLAY; GAMESTATE->m_pPlayerState[PLAYER_1]->m_PlayerController = PC_AUTOPLAY;
+1 -1
View File
@@ -99,7 +99,7 @@ bool ScreenJukebox::SetSong( bool bDemonstration )
continue; // skip continue; // skip
// Found something we can use! // Found something we can use!
GAMESTATE->m_pCurSong = pSong; GAMESTATE->m_pCurSong.Set( pSong );
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
GAMESTATE->m_pCurSteps[p] = pSteps; GAMESTATE->m_pCurSteps[p] = pSteps;
+3 -3
View File
@@ -271,7 +271,7 @@ void ScreenNetSelectMusic::HandleScreenMessage( const ScreenMessage SM )
} }
break; break;
case SM_SongChanged: case SM_SongChanged:
GAMESTATE->m_pCurSong = m_MusicWheel.GetSelectedSong(); GAMESTATE->m_pCurSong.Set( m_MusicWheel.GetSelectedSong() );
MusicChanged(); MusicChanged();
break; break;
case SM_SMOnlinePack: case SM_SMOnlinePack:
@@ -389,7 +389,7 @@ void ScreenNetSelectMusic::MenuStart( PlayerNumber pn )
if ( pSong == NULL ) if ( pSong == NULL )
return; return;
GAMESTATE->m_pCurSong = pSong; GAMESTATE->m_pCurSong.Set( pSong );
if ( NSMAN->useSMserver ) if ( NSMAN->useSMserver )
{ {
@@ -439,7 +439,7 @@ void ScreenNetSelectMusic::TweenOffScreen()
void ScreenNetSelectMusic::StartSelectedSong() void ScreenNetSelectMusic::StartSelectedSong()
{ {
Song * pSong = m_MusicWheel.GetSelectedSong(); Song * pSong = m_MusicWheel.GetSelectedSong();
GAMESTATE->m_pCurSong = pSong; GAMESTATE->m_pCurSong.Set( pSong );
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType; //STEPS_TYPE_DANCE_SINGLE; StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType; //STEPS_TYPE_DANCE_SINGLE;
FOREACH_EnabledPlayer (pn) FOREACH_EnabledPlayer (pn)
{ {
+1 -1
View File
@@ -223,7 +223,7 @@ void ScreenSelectGroup::MenuStart( PlayerNumber pn )
m_MenuTimer->Stop(); m_MenuTimer->Stop();
m_bChosen = true; m_bChosen = true;
GAMESTATE->m_pCurSong = NULL; GAMESTATE->m_pCurSong.Set( NULL );
GAMESTATE->m_sPreferredSongGroup = (m_GroupList.GetSelectionName()=="ALL MUSIC" ? GROUP_ALL_MUSIC : m_GroupList.GetSelectionName() ); GAMESTATE->m_sPreferredSongGroup = (m_GroupList.GetSelectionName()=="ALL MUSIC" ? GROUP_ALL_MUSIC : m_GroupList.GetSelectionName() );
if( GAMESTATE->m_sPreferredSongGroup == GROUP_ALL_MUSIC ) if( GAMESTATE->m_sPreferredSongGroup == GROUP_ALL_MUSIC )
+1 -1
View File
@@ -1384,7 +1384,7 @@ void ScreenSelectMusic::AfterMusicChange()
} }
Song* pSong = m_MusicWheel.GetSelectedSong(); Song* pSong = m_MusicWheel.GetSelectedSong();
GAMESTATE->m_pCurSong = pSong; GAMESTATE->m_pCurSong.Set( pSong );
if( pSong ) if( pSong )
GAMESTATE->m_pPreferredSong = pSong; GAMESTATE->m_pPreferredSong = pSong;
+1 -1
View File
@@ -917,7 +917,7 @@ void SongManager::GetExtraStageInfo( bool bExtra2, const Style *sd,
{ {
/* This normally shouldn't happen, but it's helpful to permit it for testing. */ /* This normally shouldn't happen, but it's helpful to permit it for testing. */
LOG->Warn( "GetExtraStageInfo() called in GROUP_ALL_MUSIC, but GAMESTATE->m_pCurSong == NULL" ); LOG->Warn( "GetExtraStageInfo() called in GROUP_ALL_MUSIC, but GAMESTATE->m_pCurSong == NULL" );
GAMESTATE->m_pCurSong = SONGMAN->GetRandomSong(); GAMESTATE->m_pCurSong.Set( SONGMAN->GetRandomSong() );
} }
sGroup = GAMESTATE->m_pCurSong->m_sGroupName; sGroup = GAMESTATE->m_pCurSong->m_sGroupName;
} }