From 55efe79054f1a5e1c311208eb01283756adc013e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 15 Jan 2006 08:00:37 +0000 Subject: [PATCH] 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). --- stepmania/src/GameCommand.cpp | 4 +++- stepmania/src/GameCommand.h | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index 8545d0ef09..a90c4c094d 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -23,6 +23,7 @@ void GameCommand::Init() { + m_bApplyCommitsScreens = true; m_sName = ""; m_sText = ""; m_bInvalid = true; @@ -591,6 +592,7 @@ void GameCommand::Apply( const vector &vpns ) const { GameCommand gc; gc.m_bInvalid = false; + gc.m_bApplyCommitsScreens = m_bApplyCommitsScreens; gc.LoadOne( *cmd ); gc.ApplySelf( vpns ); } @@ -669,7 +671,7 @@ void GameCommand::ApplySelf( const vector &vpns ) const } LUA->Release(L); } - if( m_sScreen != "" ) + if( m_sScreen != "" && m_bApplyCommitsScreens ) SCREENMAN->SetNewScreen( m_sScreen ); if( m_pSong ) { diff --git a/stepmania/src/GameCommand.h b/stepmania/src/GameCommand.h index 8189536a88..3bff3e8c22 100644 --- a/stepmania/src/GameCommand.h +++ b/stepmania/src/GameCommand.h @@ -40,6 +40,10 @@ public: bool IsPlayable( CString *why = NULL ) const; bool IsZero() const; 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 // so that we know the order of commands when it comes time to Apply. @@ -82,6 +86,9 @@ public: // Lua void PushSelf( lua_State *L ); + +private: + bool m_bApplyCommitsScreens; }; #endif