experimental: allow implementing effects in Lua.

The biggest risk here is performance; we rarely call Lua per-frame.  However,
there are lots of places where we can call Lua while rendering (any time we
call a command), and there's little difference between calling Lua once
every ten frames or once every frame; either way you're counting against the
per-frame time quota to hit vsync.  So, this probably isn't much of a stretch.

Usage is simple:

  OnCommand=luaeffect,Foo
  FooCommand=addx,math.random()*10

Actor commands run during the effect will only apply for that frame.  Don't
call tweening commands ("linear") or anything else that doesn't make sense
in this context; you're modifying m_TempState instead of the tweening queue.
This is hoped to replace some of the more esoteric stuff in the effect code.

For this to be of much use, Lua access to m_fSecsIntoEffect and probably
other stuff is needed.
This commit is contained in:
Glenn Maynard
2005-04-28 10:18:36 +00:00
parent 0a71994d01
commit 8b76b5eafd
2 changed files with 29 additions and 2 deletions
+21
View File
@@ -15,6 +15,7 @@
#include "ThemeManager.h"
#include "LuaReference.h"
#include "MessageManager.h"
#include "LightsManager.h" // for NUM_CABINET_LIGHTS
// lua start
@@ -171,6 +172,19 @@ void Actor::BeginDraw() // set the world matrix and calculate actor properties
{
m_pTempState = &m_current;
}
else if( m_Effect == effect_lua )
{
/* Allow a Lua function to set the frame's draw state. This may be expensive
* and has not been well-benchmarked yet; use wisely. This allows arbitrary
* effects, instead of the mess of parameters below. (In fact, all this does
* is run a command, but to avoid calling RunCommand() all the time, and due
* to the fact that this is the only place where the TempState is meaningful,
* we treat this as an effect.) */
m_pTempState = &m_tempState;
m_tempState = m_current;
PlayCommand( m_sEffectCommand );
}
else
{
m_pTempState = &m_tempState;
@@ -348,6 +362,7 @@ void Actor::SetTextureRenderStates()
void Actor::EndDraw()
{
DISPLAY->PopMatrix();
m_pTempState = NULL;
}
void Actor::UpdateTweening( float fDeltaTime )
@@ -621,6 +636,12 @@ void Actor::StretchTo( const RectF &r )
// effect "macros"
void Actor::SetEffectLua( const CString &sCommand )
{
m_Effect = effect_lua;
m_sEffectCommand = sCommand;
}
void Actor::SetEffectDiffuseBlink( float fEffectPeriodSeconds, RageColor c1, RageColor c2 )
{
if( m_Effect != diffuse_blink )
+8 -2
View File
@@ -41,7 +41,7 @@ public:
TWEEN_BOUNCE_END,
TWEEN_SPRING,
};
enum Effect { no_effect,
enum Effect { no_effect, effect_lua,
diffuse_blink, diffuse_shift, diffuse_ramp,
glow_blink, glow_shift,
rainbow,
@@ -205,7 +205,9 @@ public:
virtual float GetTweenTimeLeft() const; // Amount of time until all tweens have stopped
TweenState& DestTweenState() // where Actor will end when its tween finish
{
if( m_Tweens.empty() ) // not tweening
if( m_pTempState != NULL ) // effect_lua running
return *m_pTempState;
else if( m_Tweens.empty() ) // not tweening
return m_current;
else
return LatestTween();
@@ -249,6 +251,7 @@ public:
void SetEffectMagnitude( RageVector3 vec ) { m_vEffectMagnitude = vec; }
void SetEffectLua( const CString &sCommand );
void SetEffectDiffuseBlink(
float fEffectPeriodSeconds = 1.0f,
RageColor c1 = RageColor(0.5f,0.5f,0.5f,1),
@@ -402,6 +405,7 @@ protected:
// Stuff for effects
//
Effect m_Effect;
CString m_sEffectCommand; // effect_lua
float m_fSecsIntoEffect, m_fEffectDelta;
float m_fEffectPeriodSeconds;
float m_fEffectDelay;
@@ -507,6 +511,7 @@ public:
static int shadowlength( T* p, lua_State *L ) { p->SetShadowLength(FArg(1)); return 0; }
static int horizalign( T* p, lua_State *L ) { p->SetHorizAlignString(SArg(1)); return 0; }
static int vertalign( T* p, lua_State *L ) { p->SetVertAlignString(SArg(1)); return 0; }
static int luaeffect( T* p, lua_State *L ) { p->SetEffectLua(SArg(1)); return 0; }
static int diffuseblink( T* p, lua_State *L ) { p->SetEffectDiffuseBlink(); return 0; }
static int diffuseshift( T* p, lua_State *L ) { p->SetEffectDiffuseShift(); return 0; }
static int diffuseramp( T* p, lua_State *L ) { p->SetEffectDiffuseRamp(); return 0; }
@@ -612,6 +617,7 @@ public:
ADD_METHOD( shadowlength )
ADD_METHOD( horizalign )
ADD_METHOD( vertalign )
ADD_METHOD( luaeffect )
ADD_METHOD( diffuseblink )
ADD_METHOD( diffuseshift )
ADD_METHOD( diffuseramp )