We have two "gamestate Lua environments": mapEnv and m_Environment. The
former is a map<CString,CString>; 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.
This commit is contained in:
@@ -694,7 +694,14 @@ void GameCommand::ApplySelf( const vector<PlayerNumber> &vpns ) const
|
||||
FOREACH_CONST( PlayerNumber, vpns, pn )
|
||||
GAMESTATE->m_pCurCharacters[*pn] = m_pCharacter;
|
||||
for( map<CString,CString>::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 )
|
||||
|
||||
@@ -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<CString,CString>::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 )
|
||||
|
||||
@@ -69,7 +69,6 @@ public:
|
||||
bool IsCourseDifficultyShown( CourseDifficulty cd );
|
||||
Difficulty GetEasiestStepsDifficulty() const;
|
||||
RageTimer m_timeGameStarted; // from the moment the first player pressed Start
|
||||
map<CString,CString> m_mapEnv;
|
||||
LuaTable *m_Environment;
|
||||
|
||||
/* This is set to a random number per-game/round; it can be used for a random seed. */
|
||||
|
||||
Reference in New Issue
Block a user