From 6182acd032696f63e03a15c9c8aa59704c375bdf Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 24 Mar 2007 00:38:11 +0000 Subject: [PATCH] add SetUpdateFunction --- stepmania/src/ActorFrame.cpp | 27 +++++++++++++++++++++++++++ stepmania/src/ActorFrame.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/stepmania/src/ActorFrame.cpp b/stepmania/src/ActorFrame.cpp index 06e22ba46f..02033678b4 100644 --- a/stepmania/src/ActorFrame.cpp +++ b/stepmania/src/ActorFrame.cpp @@ -27,6 +27,7 @@ ActorFrame::ActorFrame() m_bDeleteChildren = false; m_bDrawByZPosition = false; m_DrawFunction.SetFromNil(); + m_UpdateFunction.SetFromNil(); m_fUpdateRate = 1; m_fFOV = -1; m_fVanishX = SCREEN_CENTER_X; @@ -49,6 +50,7 @@ ActorFrame::ActorFrame( const ActorFrame &cpy ): CPY( m_bDeleteChildren ); CPY( m_bDrawByZPosition ); CPY( m_DrawFunction ); + CPY( m_UpdateFunction ); CPY( m_fUpdateRate ); CPY( m_fFOV ); CPY( m_fVanishX ); @@ -317,6 +319,20 @@ void ActorFrame::UpdateInternal( float fDeltaTime ) Actor *pActor = *it; pActor->Update(fDeltaTime); } + + if( unlikely(!m_UpdateFunction.IsNil()) ) + { + Lua *L = LUA->Get(); + m_UpdateFunction.PushSelf( L ); + ASSERT( !lua_isnil(L, -1) ); + this->PushSelf( L ); + lua_pushnumber( L, fDeltaTime ); + RString sError; + + if( !LuaHelpers::RunScriptOnStack(L, sError, 2, 0) ) // 1 args, 0 results + LOG->Warn( "Error running m_UpdateFunction: %s", sError.c_str() ); + LUA->Release(L); + } } #define PropagateActorFrameCommand( cmd ) \ @@ -481,6 +497,16 @@ public: p->GetDrawFunction().PushSelf(L); return 1; } + static int SetUpdateFunction( T* p, lua_State *L ) + { + luaL_checktype( L, 1, LUA_TFUNCTION ); + + LuaReference ref; + lua_pushvalue( L, 1 ); + ref.SetFromStack( L ); + p->SetUpdateFunction( ref ); + return 0; + } LunaActorFrame() { @@ -499,6 +525,7 @@ public: ADD_METHOD( SetDrawByZPosition ); ADD_METHOD( SetDrawFunction ); ADD_METHOD( GetDrawFunction ); + ADD_METHOD( SetUpdateFunction ); } }; diff --git a/stepmania/src/ActorFrame.h b/stepmania/src/ActorFrame.h index fb04b9519d..366442368e 100644 --- a/stepmania/src/ActorFrame.h +++ b/stepmania/src/ActorFrame.h @@ -28,6 +28,8 @@ public: void SetDrawByZPosition( bool b ); void SetDrawFunction( const LuaReference &DrawFunction ) { m_DrawFunction = DrawFunction; } + void SetUpdateFunction( const LuaReference &UpdateFunction ) { m_UpdateFunction = UpdateFunction; } + LuaReference GetDrawFunction() const { return m_DrawFunction; } virtual bool AutoLoadChildren() const { return false; } // derived classes override to automatically LoadChildrenFromNode void DeleteChildrenWhenDone( bool bDelete=true ) { m_bDeleteChildren = bDelete; } @@ -80,6 +82,7 @@ protected: bool m_bPropagateCommands; bool m_bDeleteChildren; bool m_bDrawByZPosition; + LuaReference m_UpdateFunction; LuaReference m_DrawFunction; // state effects