Most of the time we use a GameCommand to store state, we don't want

Apply() itself to load the screen; we want to stuff it in m_sNextScreen
and let the normal screen loading code path do it.  That's why we have
GetAndClearScreen.

However, GetAndClearScreen is a non-const, and applying a GameCommand
should be a const operation.  It doesn't get along well with screen
reuse; once you've applied it, you've destroyed the GameCommand.

Instead, hold a flag indicating whether or not to apply screens, and
set this true on load when we handle it manually.  We should probably
*always* do this, and never load a screen within GameCommand itself, so
this may go away soon (always on).
This commit is contained in:
Glenn Maynard
2006-01-15 08:00:37 +00:00
parent 1d186c481d
commit 55efe79054
2 changed files with 10 additions and 1 deletions
+3 -1
View File
@@ -23,6 +23,7 @@
void GameCommand::Init() void GameCommand::Init()
{ {
m_bApplyCommitsScreens = true;
m_sName = ""; m_sName = "";
m_sText = ""; m_sText = "";
m_bInvalid = true; m_bInvalid = true;
@@ -591,6 +592,7 @@ void GameCommand::Apply( const vector<PlayerNumber> &vpns ) const
{ {
GameCommand gc; GameCommand gc;
gc.m_bInvalid = false; gc.m_bInvalid = false;
gc.m_bApplyCommitsScreens = m_bApplyCommitsScreens;
gc.LoadOne( *cmd ); gc.LoadOne( *cmd );
gc.ApplySelf( vpns ); gc.ApplySelf( vpns );
} }
@@ -669,7 +671,7 @@ void GameCommand::ApplySelf( const vector<PlayerNumber> &vpns ) const
} }
LUA->Release(L); LUA->Release(L);
} }
if( m_sScreen != "" ) if( m_sScreen != "" && m_bApplyCommitsScreens )
SCREENMAN->SetNewScreen( m_sScreen ); SCREENMAN->SetNewScreen( m_sScreen );
if( m_pSong ) if( m_pSong )
{ {
+7
View File
@@ -41,6 +41,10 @@ public:
bool IsZero() const; bool IsZero() const;
CString GetAndClearScreen(); CString GetAndClearScreen();
/* If true, Apply() will apply m_sScreen. If false, it won't, and you need
* to do it yourself. */
void ApplyCommitsScreens( bool bOn ) { m_bApplyCommitsScreens = bOn; }
// Same as what was passed to Load. We need to keep the original commands // Same as what was passed to Load. We need to keep the original commands
// so that we know the order of commands when it comes time to Apply. // so that we know the order of commands when it comes time to Apply.
Commands m_Commands; Commands m_Commands;
@@ -82,6 +86,9 @@ public:
// Lua // Lua
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
private:
bool m_bApplyCommitsScreens;
}; };
#endif #endif