diff --git a/stepmania/src/ActorFrame.cpp b/stepmania/src/ActorFrame.cpp index e697df89de..15c370fd10 100644 --- a/stepmania/src/ActorFrame.cpp +++ b/stepmania/src/ActorFrame.cpp @@ -2,6 +2,7 @@ #include "ActorFrame.h" #include "arch/Dialog/Dialog.h" #include "RageUtil.h" +#include "RageLog.h" #include "XmlFile.h" #include "ActorUtil.h" #include "LuaBinding.h" @@ -25,6 +26,7 @@ ActorFrame::ActorFrame() m_bPropagateCommands = false; m_bDeleteChildren = false; m_bDrawByZPosition = false; + m_DrawFunction.SetFromNil(); m_fUpdateRate = 1; m_fFOV = -1; m_fVanishX = SCREEN_CENTER_X; @@ -46,6 +48,7 @@ ActorFrame::ActorFrame( const ActorFrame &cpy ): CPY( m_bPropagateCommands ); CPY( m_bDeleteChildren ); CPY( m_bDrawByZPosition ); + CPY( m_DrawFunction ); CPY( m_fUpdateRate ); CPY( m_fFOV ); CPY( m_fVanishX ); @@ -204,6 +207,19 @@ void ActorFrame::DrawPrimitives() // any geometry that belongs to this object. // Actor::DrawPrimitives(); + if( unlikely(!m_DrawFunction.IsNil()) ) + { + Lua *L = LUA->Get(); + m_DrawFunction.PushSelf( L ); + ASSERT( !lua_isnil(L, -1) ); + this->PushSelf( L ); + RString sError; + if( !LuaHelpers::RunScriptOnStack(L, sError, 1, 0) ) // 1 arg, 0 results + LOG->Warn( "Error running DrawFunction: %s", sError.c_str() ); + LUA->Release(L); + return; + } + // draw all sub-ActorFrames while we're in the ActorFrame's local coordinate space if( m_bDrawByZPosition ) { @@ -423,6 +439,21 @@ public: } static int GetNumChildren( T* p, lua_State *L ) { lua_pushnumber( L, p->GetNumChildren() ); return 1; } static int SetDrawByZPosition( T* p, lua_State *L ) { p->SetDrawByZPosition( BArg(1) ); return 1; } + static int SetDrawFunction( T* p, lua_State *L ) + { + luaL_checktype( L, 1, LUA_TFUNCTION ); + + LuaReference ref; + lua_pushvalue( L, 1 ); + ref.SetFromStack( L ); + p->SetDrawFunction( ref ); + return 0; + } + static int GetDrawFunction( T* p, lua_State *L ) + { + p->GetDrawFunction().PushSelf(L); + return 1; + } LunaActorFrame() { @@ -438,6 +469,8 @@ public: ADD_METHOD( GetChildren ); ADD_METHOD( GetNumChildren ); ADD_METHOD( SetDrawByZPosition ); + ADD_METHOD( SetDrawFunction ); + ADD_METHOD( GetDrawFunction ); } }; diff --git a/stepmania/src/ActorFrame.h b/stepmania/src/ActorFrame.h index d37014112f..5ceddc8f8c 100644 --- a/stepmania/src/ActorFrame.h +++ b/stepmania/src/ActorFrame.h @@ -27,6 +27,8 @@ public: void SortByDrawOrder(); void SetDrawByZPosition( bool b ); + void SetDrawFunction( const LuaReference &DrawFunction ) { m_DrawFunction = DrawFunction; } + 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; } void DeleteAllChildren(); @@ -76,6 +78,7 @@ protected: bool m_bPropagateCommands; bool m_bDeleteChildren; bool m_bDrawByZPosition; + LuaReference m_DrawFunction; // state effects float m_fUpdateRate;