From 9c867fdd706ee5462352ed9a28ecc7d9e06e75c5 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 13 Jan 2006 21:49:35 +0000 Subject: [PATCH] We have two "gamestate Lua environments": mapEnv and m_Environment. The former is a map; the latter is a Lua table. The former is reset on gamestate reset, the latter is not. Merge the map into the table, and eliminate it. We only need one, and it makes sense for a Lua environment to be a Lua table. Do reset the table on Reset. Otherwise, there's little point; if you want to store data inside Lua, you don't need GameState to help. --- stepmania/src/GameCommand.cpp | 9 ++++++++- stepmania/src/GameState.cpp | 22 +++++++++++++++------- stepmania/src/GameState.h | 1 - 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index 9490e76e1b..a87310d052 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -694,7 +694,14 @@ void GameCommand::ApplySelf( const vector &vpns ) const FOREACH_CONST( PlayerNumber, vpns, pn ) GAMESTATE->m_pCurCharacters[*pn] = m_pCharacter; for( map::const_iterator i = m_SetEnv.begin(); i != m_SetEnv.end(); i++ ) - GAMESTATE->m_mapEnv[ i->first ] = i->second; + { + Lua *L = LUA->Get(); + GAMESTATE->m_Environment->PushSelf(L); + lua_pushstring( L, i->first ); + lua_pushstring( L, i->second ); + lua_settable( L, -3 ); + LUA->Release(L); + } if( !m_sSongGroup.empty() ) GAMESTATE->m_sPreferredSongGroup.Set( m_sSongGroup ); if( m_SortOrder != SORT_INVALID ) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index dafa761431..be0c03830a 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -178,7 +178,7 @@ void GameState::Reset() // m_iCoins = 0; // don't reset coin count! m_MasterPlayerNumber = PLAYER_INVALID; m_bMultiplayer = false; - m_mapEnv.clear(); + *m_Environment = LuaTable(); m_sPreferredSongGroup.Set( GROUP_ALL ); m_sPreferredCourseGroup.Set( GROUP_ALL ); m_bChangedFailTypeOnScreenSongOptions = false; @@ -726,6 +726,7 @@ Stage GameState::GetCurrentStage() const else return (Stage)(STAGE_1+m_iCurrentStageIndex); } +// Return true if it's possible for GetCurrentStage() to return the given stage. bool GameState::IsStagePossible( Stage s ) const { /* HACK: Find out what the stage would be without long or marathon. @@ -1883,14 +1884,21 @@ public: } static int SetTemporaryEventMode( T* p, lua_State *L ) { p->m_bTemporaryEventMode = BArg(1); return 0; } static int Env( T* p, lua_State *L ) { p->m_Environment->PushSelf(L); return 1; } - static int SetEnv( T* p, lua_State *L ) { p->m_mapEnv[SArg(1)] = SArg(2); return 0; } + static int SetEnv( T* p, lua_State *L ) + { + int iTop = lua_gettop(L); + p->m_Environment->PushSelf(L); + lua_pushvalue( L, iTop-1 ); + lua_pushvalue( L, iTop ); + lua_settable( L, -3 ); + return 0; + } static int GetEnv( T* p, lua_State *L ) { - map::const_iterator iter = p->m_mapEnv.find(SArg(1)); - if( iter != p->m_mapEnv.end() ) - lua_pushstring(L,iter->second); - else - lua_pushnil(L); + int iTop = lua_gettop(L); + p->m_Environment->PushSelf(L); + lua_pushvalue( L, iTop ); + lua_gettable( L, -2 ); return 1; } static int GetEditSourceSteps( T* p, lua_State *L ) diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 57fe2168a7..ade46b5331 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -69,7 +69,6 @@ public: bool IsCourseDifficultyShown( CourseDifficulty cd ); Difficulty GetEasiestStepsDifficulty() const; RageTimer m_timeGameStarted; // from the moment the first player pressed Start - map m_mapEnv; LuaTable *m_Environment; /* This is set to a random number per-game/round; it can be used for a random seed. */