Messages and commands are nearly identical: they both have a name,

they can both have parameters stashed in a table, and they both play
stuff out of the actor command list.  Merge them; now the only
difference between playing and broadcasting a command is that playing
plays recursively on a tree and broadcasting sends to all subscribers.

The distinction between "messages" and "commands" is cosmetic now;
everything is a message.  The only thing special about commands intended
to be received as a broadcast is the "Message" suffix, which subscribes it.
This commit is contained in:
Glenn Maynard
2007-02-03 06:17:02 +00:00
parent 8dbb54a1c6
commit 9bc27fb390
13 changed files with 49 additions and 33 deletions
+6 -9
View File
@@ -1189,11 +1189,11 @@ const apActorCommands *Actor::GetCommand( const RString &sCommandName ) const
return &it->second; return &it->second;
} }
void Actor::PlayCommand( const RString &sCommandName, const LuaReference *pParamTable ) void Actor::HandleMessage( const Message &msg )
{ {
const apActorCommands *pCmd = GetCommand( sCommandName ); const apActorCommands *pCmd = GetCommand( msg.GetName() );
if( pCmd != NULL ) if( pCmd != NULL )
RunCommands( *pCmd, pParamTable ); RunCommands( *pCmd, &msg.GetParamTable() );
} }
void Actor::PushContext( lua_State *L ) void Actor::PushContext( lua_State *L )
@@ -1220,11 +1220,6 @@ void Actor::SetParent( Actor *pParent )
LUA->Release( L ); LUA->Release( L );
} }
void Actor::HandleMessage( const Message &msg )
{
PlayCommand( msg.GetName(), &msg.GetParamTable() );
}
Actor::TweenInfo::TweenInfo() Actor::TweenInfo::TweenInfo()
{ {
m_pTween = NULL; m_pTween = NULL;
@@ -1376,7 +1371,9 @@ public:
lua_pushvalue( L, 2 ); lua_pushvalue( L, 2 );
ParamTable.SetFromStack( L ); ParamTable.SetFromStack( L );
p->PlayCommand( SArg(1), &ParamTable ); Message msg( SArg(1), ParamTable );
p->HandleMessage( msg );
return 0; return 0;
} }
static int queuecommand( T* p, lua_State *L ) { p->QueueCommand(SArg(1)); return 0; } static int queuecommand( T* p, lua_State *L ) { p->QueueCommand(SArg(1)); return 0; }
+1 -1
View File
@@ -356,7 +356,7 @@ public:
void AddCommand( const RString &sCmdName, apActorCommands apac ); void AddCommand( const RString &sCmdName, apActorCommands apac );
bool HasCommand( const RString &sCmdName ); bool HasCommand( const RString &sCmdName );
const apActorCommands *GetCommand( const RString &sCommandName ) const; const apActorCommands *GetCommand( const RString &sCommandName ) const;
virtual void PlayCommand( const RString &sCommandName, const LuaReference *pParamTable = NULL ); void PlayCommand( const RString &sCommandName ) { HandleMessage( Message(sCommandName) ); }
virtual void RunCommands( const LuaReference& cmds, const LuaReference *pParamTable = NULL ); virtual void RunCommands( const LuaReference& cmds, const LuaReference *pParamTable = NULL );
void RunCommands( const apActorCommands& cmds, const LuaReference *pParamTable = NULL ) { this->RunCommands( *cmds, pParamTable ); } // convenience void RunCommands( const apActorCommands& cmds, const LuaReference *pParamTable = NULL ) { this->RunCommands( *cmds, pParamTable ); } // convenience
// If we're a leaf, then execute this command. // If we're a leaf, then execute this command.
+4 -4
View File
@@ -352,19 +352,19 @@ void ActorFrame::SetPropagateCommands( bool b )
m_bPropagateCommands = b; m_bPropagateCommands = b;
} }
void ActorFrame::PlayCommand( const RString &sCommandName, const LuaReference *pParamTable ) void ActorFrame::HandleMessage( const Message &msg )
{ {
Actor::PlayCommand( sCommandName, pParamTable ); Actor::HandleMessage( msg );
// HACK: Don't propogate Init. It gets called once for every Actor when the // HACK: Don't propogate Init. It gets called once for every Actor when the
// Actor is loaded, and we don't want to call it again. // Actor is loaded, and we don't want to call it again.
if( sCommandName == "Init" ) if( msg.GetName() == "Init" )
return; return;
for( unsigned i=0; i<m_SubActors.size(); i++ ) for( unsigned i=0; i<m_SubActors.size(); i++ )
{ {
Actor* pActor = m_SubActors[i]; Actor* pActor = m_SubActors[i];
pActor->PlayCommand( sCommandName, pParamTable ); pActor->HandleMessage( msg );
} }
} }
+1 -1
View File
@@ -64,7 +64,7 @@ public:
/* Amount of time until all tweens (and all children's tweens) have stopped: */ /* Amount of time until all tweens (and all children's tweens) have stopped: */
virtual float GetTweenTimeLeft() const; virtual float GetTweenTimeLeft() const;
virtual void PlayCommand( const RString &sCommandName, const LuaReference *pParamTable = NULL ); virtual void HandleMessage( const Message &msg );
virtual void RunCommands( const LuaReference& cmds, const LuaReference *pParamTable = NULL ); virtual void RunCommands( const LuaReference& cmds, const LuaReference *pParamTable = NULL );
void RunCommands( const apActorCommands& cmds, const LuaReference *pParamTable = NULL ) { this->RunCommands( *cmds, pParamTable ); } // convenience void RunCommands( const apActorCommands& cmds, const LuaReference *pParamTable = NULL ) { this->RunCommands( *cmds, pParamTable ); } // convenience
+21 -1
View File
@@ -158,6 +158,17 @@ Message::Message( const RString &s )
m_pParams = new LuaTable; m_pParams = new LuaTable;
} }
Message::Message( const RString &s, const LuaReference &params )
{
m_sName = s;
Lua *L = LUA->Get();
m_pParams = new LuaTable; // XXX: creates an extra table
params.PushSelf( L );
m_pParams->SetFromStack( L );
LUA->Release( L );
// m_pParams = new LuaTable( params );
}
Message::~Message() Message::~Message()
{ {
delete m_pParams; delete m_pParams;
@@ -168,6 +179,14 @@ void Message::PushParamTable( lua_State *L )
m_pParams->PushSelf( L ); m_pParams->PushSelf( L );
} }
void Message::SetParamTable( const LuaReference &params )
{
Lua *L = LUA->Get();
params.PushSelf( L );
m_pParams->SetFromStack( L );
LUA->Release( L );
}
const LuaReference &Message::GetParamTable() const const LuaReference &Message::GetParamTable() const
{ {
return *m_pParams; return *m_pParams;
@@ -305,7 +324,8 @@ public:
lua_pushvalue( L, 2 ); lua_pushvalue( L, 2 );
ParamTable.SetFromStack( L ); ParamTable.SetFromStack( L );
p->Broadcast( SArg(1) ); Message msg( SArg(1), ParamTable );
p->Broadcast( msg );
return 0; return 0;
} }
+2
View File
@@ -149,11 +149,13 @@ const RString& MessageIDToString( MessageID m );
struct Message struct Message
{ {
explicit Message( const RString &s ); explicit Message( const RString &s );
Message( const RString &s, const LuaReference &params );
~Message(); ~Message();
RString GetName() const { return m_sName; } RString GetName() const { return m_sName; }
void PushParamTable( lua_State *L ); void PushParamTable( lua_State *L );
const LuaReference &GetParamTable() const; const LuaReference &GetParamTable() const;
void SetParamTable( const LuaReference &params );
void GetParamFromStack( lua_State *L, const RString &sName ) const; void GetParamFromStack( lua_State *L, const RString &sName ) const;
void SetParamFromStack( lua_State *L, const RString &sName ); void SetParamFromStack( lua_State *L, const RString &sName );
+3 -6
View File
@@ -746,12 +746,9 @@ void NoteDisplay::DrawTap( const TapNote& tn, int iCol, float fBeat, bool bOnSam
if( tn.type == TapNote::attack ) if( tn.type == TapNote::attack )
{ {
Lua *L = LUA->Get(); Message msg( "SetAttack" );
LuaTable tab; msg.SetParam( "Modifiers", tn.sAttackModifiers );
LuaHelpers::Push( L, tn.sAttackModifiers ); pActor->HandleMessage( msg );
tab.Set( L, "Modifiers" );
pActor->PlayCommand( "SetAttack", &tab );
LUA->Release( L );
} }
const float fYOffset = ArrowEffects::GetYOffset( m_pPlayerState, iCol, fBeat ); const float fYOffset = ArrowEffects::GetYOffset( m_pPlayerState, iCol, fBeat );
+2 -2
View File
@@ -40,11 +40,11 @@ void ScoreDisplayAliveTime::Update( float fDelta )
BitmapText::Update( fDelta ); BitmapText::Update( fDelta );
} }
void ScoreDisplayAliveTime::PlayCommand( const RString &sCommandName, const LuaReference *pParamTable ) void ScoreDisplayAliveTime::HandleMessage( const Message &msg )
{ {
// TODO: Add handling of GoalComplete message // TODO: Add handling of GoalComplete message
BitmapText::PlayCommand( sCommandName, pParamTable ); BitmapText::HandleMessage( msg );
} }
void ScoreDisplayAliveTime::UpdateNumber() void ScoreDisplayAliveTime::UpdateNumber()
+1 -1
View File
@@ -19,7 +19,7 @@ public:
void LoadFromNode( const XNode* pNode ); void LoadFromNode( const XNode* pNode );
virtual ScoreDisplayAliveTime *Copy() const; virtual ScoreDisplayAliveTime *Copy() const;
void PlayCommand( const RString &sCommandName, const LuaReference *pParamTable ); virtual void HandleMessage( const Message &msg );
void UpdateNumber(); void UpdateNumber();
+3 -3
View File
@@ -49,14 +49,14 @@ void ScoreDisplayCalories::Update( float fDelta )
RollingNumbers::Update( fDelta ); RollingNumbers::Update( fDelta );
} }
void ScoreDisplayCalories::PlayCommand( const RString &sCommandName, const LuaReference *pParamTable ) void ScoreDisplayCalories::HandleMessage( const Message &msg )
{ {
if( sCommandName == m_sMessageOnStep ) if( msg.GetName() == m_sMessageOnStep )
{ {
UpdateNumber(); UpdateNumber();
} }
RollingNumbers::PlayCommand( sCommandName, pParamTable ); RollingNumbers::HandleMessage( msg );
} }
void ScoreDisplayCalories::UpdateNumber() void ScoreDisplayCalories::UpdateNumber()
+1 -1
View File
@@ -18,7 +18,7 @@ public:
void LoadFromNode( const XNode* pNode ); void LoadFromNode( const XNode* pNode );
virtual ScoreDisplayCalories *Copy() const; virtual ScoreDisplayCalories *Copy() const;
void PlayCommand( const RString &sCommandName, const LuaReference *pParamTable = NULL ); virtual void HandleMessage( const Message &msg );
void UpdateNumber(); void UpdateNumber();
+3 -3
View File
@@ -66,12 +66,12 @@ bool Transition::EarlyAbortDraw() const
/* Our parent might send us OnCommand. We do that ourself, because /* Our parent might send us OnCommand. We do that ourself, because
* we sometimes want to know GetLengthSeconds before StartTransitioning. * we sometimes want to know GetLengthSeconds before StartTransitioning.
* Make sure we don't process OnCommand twice. */ * Make sure we don't process OnCommand twice. */
void Transition::PlayCommand( const RString &sCommandName, const LuaReference *pParamTable ) void Transition::HandleMessage( const Message &msg )
{ {
if( sCommandName == "On" ) if( msg.GetName() == "On" )
return; return;
ActorFrame::PlayCommand( sCommandName, pParamTable ); ActorFrame::HandleMessage( msg );
} }
void Transition::StartTransitioning( ScreenMessage send_when_done ) void Transition::StartTransitioning( ScreenMessage send_when_done )
+1 -1
View File
@@ -16,7 +16,7 @@ public:
void Load( RString sBGAniDir ); void Load( RString sBGAniDir );
virtual void UpdateInternal( float fDeltaTime ); virtual void UpdateInternal( float fDeltaTime );
virtual void PlayCommand( const RString &sCommandName, const LuaReference *pParamTable = NULL ); virtual void HandleMessage( const Message &msg );
virtual void StartTransitioning( ScreenMessage send_when_done = SM_None ); virtual void StartTransitioning( ScreenMessage send_when_done = SM_None );
virtual bool EarlyAbortDraw() const; virtual bool EarlyAbortDraw() const;