enforce that changed message is broadcast whenever value changes
This commit is contained in:
@@ -111,7 +111,7 @@ bool GameCommand::DescribesCurrentMode( PlayerNumber pn ) const
|
||||
return false;
|
||||
}
|
||||
|
||||
if( m_pSong && GAMESTATE->m_pCurSong != m_pSong )
|
||||
if( m_pSong && GAMESTATE->m_pCurSong.Get() != m_pSong )
|
||||
return false;
|
||||
if( m_pSteps && GAMESTATE->m_pCurSteps[pn] != m_pSteps )
|
||||
return false;
|
||||
@@ -636,7 +636,7 @@ void GameCommand::Apply( const vector<PlayerNumber> &vpns ) const
|
||||
SCREENMAN->SetNewScreen( m_sScreen );
|
||||
if( m_pSong )
|
||||
{
|
||||
GAMESTATE->m_pCurSong = m_pSong;
|
||||
GAMESTATE->m_pCurSong.Set( m_pSong );
|
||||
GAMESTATE->m_pPreferredSong = m_pSong;
|
||||
}
|
||||
if( m_pSteps )
|
||||
|
||||
@@ -151,7 +151,7 @@ void GameState::Reset()
|
||||
m_iGameSeed = rand();
|
||||
m_iRoundSeed = rand();
|
||||
|
||||
m_pCurSong = NULL;
|
||||
m_pCurSong.Set( NULL );
|
||||
m_pPreferredSong = NULL;
|
||||
FOREACH_PlayerNumber( p )
|
||||
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 SetCurrentSong( T* p, lua_State *L )
|
||||
{
|
||||
if( lua_isnil(L,1) ) { p->m_pCurSong = NULL; }
|
||||
else { Song *pS = Luna<Song>::check(L,1); p->m_pCurSong = pS; }
|
||||
MESSAGEMAN->Broadcast( "CurrentSongChanged" );
|
||||
if( lua_isnil(L,1) ) { p->m_pCurSong.Set( NULL ); }
|
||||
else { Song *pS = Luna<Song>::check(L,1); p->m_pCurSong.Set( pS ); }
|
||||
return 0;
|
||||
}
|
||||
static int GetCurrentSteps( T* p, lua_State *L )
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Attack.h"
|
||||
#include "RageTimer.h"
|
||||
#include "Difficulty.h"
|
||||
#include "MessageManager.h"
|
||||
|
||||
#include <map>
|
||||
#include <deque>
|
||||
@@ -26,6 +27,7 @@ struct StageStats;
|
||||
struct PlayerState;
|
||||
struct lua_State;
|
||||
|
||||
|
||||
class GameState
|
||||
{
|
||||
public:
|
||||
@@ -127,7 +129,7 @@ public:
|
||||
//
|
||||
|
||||
// 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.
|
||||
Song* m_pPreferredSong;
|
||||
Steps* m_pCurSteps[NUM_PLAYERS];
|
||||
|
||||
@@ -3,10 +3,17 @@
|
||||
#include "Foreach.h"
|
||||
#include "Actor.h"
|
||||
#include "RageUtil.h"
|
||||
#include "EnumHelper.h"
|
||||
|
||||
MessageManager* MESSAGEMAN = NULL; // global and accessable from anywhere in our program
|
||||
|
||||
|
||||
static const CString MessageNames[NUM_MESSAGES] = {
|
||||
"CurrentSongChanged",
|
||||
};
|
||||
XToString( Message );
|
||||
|
||||
|
||||
MessageManager::MessageManager()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -12,6 +12,25 @@ public:
|
||||
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
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -171,7 +171,8 @@ void MusicWheel::Load()
|
||||
pSteps,
|
||||
po,
|
||||
so );
|
||||
GAMESTATE->m_pCurSong = GAMESTATE->m_pPreferredSong = pSong;
|
||||
GAMESTATE->m_pCurSong.Set( pSong );
|
||||
GAMESTATE->m_pPreferredSong = pSong;
|
||||
FOREACH_HumanPlayer( p )
|
||||
{
|
||||
GAMESTATE->m_pCurSteps[p] = pSteps;
|
||||
@@ -235,7 +236,7 @@ void MusicWheel::Load()
|
||||
&& !GAMESTATE->GetEventMode()
|
||||
&& !GAMESTATE->IsExtraStage() && !GAMESTATE->IsExtraStage2() )
|
||||
{
|
||||
GAMESTATE->m_pCurSong = NULL;
|
||||
GAMESTATE->m_pCurSong.Set( NULL );
|
||||
}
|
||||
|
||||
// Select the the previously selected song (if any)
|
||||
|
||||
@@ -946,7 +946,7 @@ void OptionRowHandlerList::FillSongsInCurrentSongGroup( OptionRowDefinition &def
|
||||
SONGMAN->GetSongs( vpSongs, GAMESTATE->m_sPreferredSongGroup );
|
||||
|
||||
if( GAMESTATE->m_pCurSong == NULL )
|
||||
GAMESTATE->m_pCurSong = vpSongs[0];
|
||||
GAMESTATE->m_pCurSong.Set( vpSongs[0] );
|
||||
|
||||
defOut.name = "SongsInCurrentSongGroup";
|
||||
defOut.bOneChoiceForAllPlayers = true;
|
||||
|
||||
@@ -110,7 +110,7 @@ void ScreenEditMenu::MenuStart( PlayerNumber pn )
|
||||
Steps* pSourceNotes = m_Selector.GetSelectedSourceNotes();
|
||||
EditMenu::Action action = m_Selector.GetSelectedAction();
|
||||
|
||||
GAMESTATE->m_pCurSong = pSong;
|
||||
GAMESTATE->m_pCurSong.Set( pSong );
|
||||
GAMESTATE->m_pCurStyle = GAMEMAN->GetEditorStyleForStepsType( st );
|
||||
GAMESTATE->m_pCurSteps[PLAYER_1] = pSteps;
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ ScreenEnding::ScreenEnding( CString sClassName ) : ScreenAttract( sClassName, fa
|
||||
GAMESTATE->m_bSideIsJoined[PLAYER_1] = true;
|
||||
GAMESTATE->m_bSideIsJoined[PLAYER_2] = true;
|
||||
GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
|
||||
GAMESTATE->m_pCurSong = SONGMAN->GetRandomSong();
|
||||
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];
|
||||
|
||||
@@ -108,7 +108,7 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName ) : ScreenWithMenuElement
|
||||
GAMESTATE->m_bSideIsJoined[PLAYER_1] = true;
|
||||
GAMESTATE->m_bSideIsJoined[PLAYER_2] = true;
|
||||
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 );
|
||||
GAMESTATE->m_pCurCourse = SONGMAN->GetRandomCourse();
|
||||
GAMESTATE->m_pCurSteps[PLAYER_1] = GAMESTATE->m_pCurSong->GetAllSteps()[0];
|
||||
|
||||
@@ -604,7 +604,7 @@ void ScreenEz2SelectMusic::HarderDifficulty( PlayerNumber pn )
|
||||
void ScreenEz2SelectMusic::MusicChanged()
|
||||
{
|
||||
Song* pSong = m_MusicBannerWheel.GetSelectedSong();
|
||||
GAMESTATE->m_pCurSong = pSong;
|
||||
GAMESTATE->m_pCurSong.Set( pSong );
|
||||
|
||||
m_CurrentGroup.SetText( SONGMAN->ShortenGroupName( pSong->m_sGroupName ) , "");
|
||||
m_CurrentGroup.SetDiffuse( SONGMAN->GetGroupColor(pSong->m_sGroupName) );
|
||||
|
||||
@@ -903,7 +903,7 @@ void ScreenGameplay::LoadNextSong()
|
||||
|
||||
int iPlaySongIndex = GAMESTATE->GetCourseSongIndex();
|
||||
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 );
|
||||
|
||||
// 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;
|
||||
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") );
|
||||
GAMESTATE->m_pCurSong = pCurSong;
|
||||
GAMESTATE->m_pCurSong.Set( pCurSong );
|
||||
|
||||
m_NextSongOut.StartTransitioning( SM_LoadNextSong );
|
||||
LoadCourseSongNumber( GetMaxSongsPlayed()+1 );
|
||||
|
||||
@@ -348,7 +348,7 @@ void ScreenGameplayMultiplayer::LoadNextSong()
|
||||
|
||||
int iPlaySongIndex = GAMESTATE->GetCourseSongIndex();
|
||||
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 );
|
||||
|
||||
// No need to do this here. We do it in SongFinished().
|
||||
|
||||
@@ -154,7 +154,7 @@ void ScreenHowToPlay::Init()
|
||||
pSteps->GetNoteData( tempNoteData );
|
||||
pStyle->GetTransformedNoteDataForStyle( PLAYER_1, tempNoteData, m_NoteData );
|
||||
|
||||
GAMESTATE->m_pCurSong = &m_Song;
|
||||
GAMESTATE->m_pCurSong.Set( &m_Song );
|
||||
GAMESTATE->m_bPastHereWeGo = true;
|
||||
GAMESTATE->m_pPlayerState[PLAYER_1]->m_PlayerController = PC_AUTOPLAY;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ bool ScreenJukebox::SetSong( bool bDemonstration )
|
||||
continue; // skip
|
||||
|
||||
// Found something we can use!
|
||||
GAMESTATE->m_pCurSong = pSong;
|
||||
GAMESTATE->m_pCurSong.Set( pSong );
|
||||
FOREACH_PlayerNumber( p )
|
||||
GAMESTATE->m_pCurSteps[p] = pSteps;
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ void ScreenNetSelectMusic::HandleScreenMessage( const ScreenMessage SM )
|
||||
}
|
||||
break;
|
||||
case SM_SongChanged:
|
||||
GAMESTATE->m_pCurSong = m_MusicWheel.GetSelectedSong();
|
||||
GAMESTATE->m_pCurSong.Set( m_MusicWheel.GetSelectedSong() );
|
||||
MusicChanged();
|
||||
break;
|
||||
case SM_SMOnlinePack:
|
||||
@@ -389,7 +389,7 @@ void ScreenNetSelectMusic::MenuStart( PlayerNumber pn )
|
||||
if ( pSong == NULL )
|
||||
return;
|
||||
|
||||
GAMESTATE->m_pCurSong = pSong;
|
||||
GAMESTATE->m_pCurSong.Set( pSong );
|
||||
|
||||
if ( NSMAN->useSMserver )
|
||||
{
|
||||
@@ -439,7 +439,7 @@ void ScreenNetSelectMusic::TweenOffScreen()
|
||||
void ScreenNetSelectMusic::StartSelectedSong()
|
||||
{
|
||||
Song * pSong = m_MusicWheel.GetSelectedSong();
|
||||
GAMESTATE->m_pCurSong = pSong;
|
||||
GAMESTATE->m_pCurSong.Set( pSong );
|
||||
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType; //STEPS_TYPE_DANCE_SINGLE;
|
||||
FOREACH_EnabledPlayer (pn)
|
||||
{
|
||||
|
||||
@@ -223,7 +223,7 @@ void ScreenSelectGroup::MenuStart( PlayerNumber pn )
|
||||
m_MenuTimer->Stop();
|
||||
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() );
|
||||
|
||||
if( GAMESTATE->m_sPreferredSongGroup == GROUP_ALL_MUSIC )
|
||||
|
||||
@@ -1384,7 +1384,7 @@ void ScreenSelectMusic::AfterMusicChange()
|
||||
}
|
||||
|
||||
Song* pSong = m_MusicWheel.GetSelectedSong();
|
||||
GAMESTATE->m_pCurSong = pSong;
|
||||
GAMESTATE->m_pCurSong.Set( pSong );
|
||||
if( pSong )
|
||||
GAMESTATE->m_pPreferredSong = pSong;
|
||||
|
||||
|
||||
@@ -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. */
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user