add ActorUtil::ActorParam helper

This commit is contained in:
Glenn Maynard
2006-01-14 05:27:29 +00:00
parent 776ff285cf
commit 6344476389
3 changed files with 41 additions and 15 deletions
+29
View File
@@ -528,6 +528,35 @@ FileType ActorUtil::GetFileType( const CString &sPath )
else return FT_Invalid;
}
/* Helper: set actor parameters, and return them to their original value when released. */
ActorUtil::ActorParam::ActorParam( CString sName, CString sValue )
{
m_pOld = new LuaReference;
m_sName = sName;
Lua *L = LUA->Get();
LuaHelpers::Push( sValue, L );
ActorUtil::SetParamFromStack( L, m_sName, m_pOld );
LUA->Release( L );
}
ActorUtil::ActorParam::~ActorParam()
{
delete m_pOld;
Release();
}
void ActorUtil::ActorParam::Release()
{
if( m_pOld->IsSet() )
return;
/* Restore the old value. */
Lua *L = LUA->Get();
m_pOld->PushSelf( L );
ActorUtil::SetParamFromStack( L, m_sName );
m_pOld->Unset();
LUA->Release( L );
}
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
+11
View File
@@ -77,6 +77,17 @@ namespace ActorUtil
void SetParamFromStack( Lua *L, CString sName, LuaReference *pOld=NULL );
void GetParam( Lua *L, const CString &sName );
struct ActorParam
{
ActorParam( CString sName, CString sValue );
~ActorParam();
void Release();
private:
CString m_sName;
LuaReference *m_pOld;
};
};
#define SET_XY( actor ) ActorUtil::SetXY( actor, m_sName )
+1 -15
View File
@@ -20,23 +20,9 @@
void Screen::InitScreen( Screen *pScreen )
{
/* Set the name of the loading screen. */
LuaReference Old;
{
Lua *L = LUA->Get();
LuaHelpers::Push( pScreen->GetName(), L );
ActorUtil::SetParamFromStack( L, "LoadingScreen", &Old );
LUA->Release( L );
}
ActorUtil::ActorParam LoadingScreen( "LoadingScreen", pScreen->GetName() );
pScreen->Init();
/* Restore the old value. */
{
Lua *L = LUA->Get();
Old.PushSelf( L );
ActorUtil::SetParamFromStack( L, "LoadingScreen" );
LUA->Release( L );
}
}
Screen::Screen( CString sName )