move message helper stuff out of Actor into a new base class so that it can be used w/o deriving from Actor
This commit is contained in:
+3
-23
@@ -89,7 +89,7 @@ void Actor::InitDefaults()
|
||||
m_bZWrite = false;
|
||||
m_CullMode = CULL_NONE;
|
||||
|
||||
UnsubcribeAndClearCommands();
|
||||
UnsubscribeAll();
|
||||
}
|
||||
|
||||
static bool GetMessageNameFromCommandName( const RString &sCommandName, RString &sMessageNameOut )
|
||||
@@ -105,13 +105,6 @@ static bool GetMessageNameFromCommandName( const RString &sCommandName, RString
|
||||
}
|
||||
}
|
||||
|
||||
void Actor::UnsubcribeAndClearCommands()
|
||||
{
|
||||
FOREACH_CONST( RString, m_vsSubscribedTo, s )
|
||||
MESSAGEMAN->Unsubscribe( this, *s );
|
||||
m_vsSubscribedTo.clear();
|
||||
}
|
||||
|
||||
Actor::Actor()
|
||||
{
|
||||
m_pLuaInstance = new LuaClass;
|
||||
@@ -123,11 +116,11 @@ Actor::Actor()
|
||||
Actor::~Actor()
|
||||
{
|
||||
StopTweening();
|
||||
UnsubcribeAndClearCommands();
|
||||
UnsubscribeAll();
|
||||
}
|
||||
|
||||
Actor::Actor( const Actor &cpy ):
|
||||
IMessageSubscriber( cpy )
|
||||
MessageSubscriber( cpy )
|
||||
{
|
||||
/* Don't copy an Actor in the middle of rendering. */
|
||||
ASSERT( cpy.m_pTempState == NULL );
|
||||
@@ -183,7 +176,6 @@ Actor::Actor( const Actor &cpy ):
|
||||
CPY( m_CullMode );
|
||||
|
||||
CPY( m_mapNameToCommands );
|
||||
CPY( m_vsSubscribedTo );
|
||||
#undef CPY
|
||||
}
|
||||
|
||||
@@ -1278,18 +1270,6 @@ void Actor::HandleMessage( const RString& sMessage )
|
||||
PlayCommand( sMessage );
|
||||
}
|
||||
|
||||
void Actor::SubscribeToMessage( const RString &sMessageName )
|
||||
{
|
||||
MESSAGEMAN->Subscribe( this, sMessageName );
|
||||
m_vsSubscribedTo.push_back( sMessageName );
|
||||
}
|
||||
|
||||
void Actor::SubscribeToMessage( Message message )
|
||||
{
|
||||
MESSAGEMAN->Subscribe( this, message );
|
||||
m_vsSubscribedTo.push_back( MessageToString(message) );
|
||||
}
|
||||
|
||||
Actor::TweenInfo::TweenInfo()
|
||||
{
|
||||
m_pTween = NULL;
|
||||
|
||||
@@ -22,14 +22,13 @@ class LuaClass;
|
||||
#define DRAW_ORDER_TRANSITIONS +110
|
||||
#define DRAW_ORDER_AFTER_EVERYTHING +200
|
||||
|
||||
class Actor : public IMessageSubscriber
|
||||
class Actor : public MessageSubscriber
|
||||
{
|
||||
public:
|
||||
Actor();
|
||||
Actor( const Actor &cpy );
|
||||
virtual ~Actor();
|
||||
virtual Actor *Copy() const;
|
||||
void UnsubcribeAndClearCommands();
|
||||
virtual void LoadFromNode( const RString& sDir, const XNode* pNode );
|
||||
bool IsType( const RString &sType );
|
||||
|
||||
@@ -346,11 +345,8 @@ public:
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
void SubscribeToMessage( Message message ); // will automatically unsubscribe
|
||||
void SubscribeToMessage( const RString &sMessageName ); // will automatically unsubscribe
|
||||
virtual void HandleMessage( const RString& sMessage );
|
||||
|
||||
|
||||
//
|
||||
// Animation
|
||||
//
|
||||
@@ -465,7 +461,6 @@ private:
|
||||
// commands
|
||||
//
|
||||
map<RString, apActorCommands> m_mapNameToCommands;
|
||||
vector<RString> m_vsSubscribedTo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -193,6 +193,30 @@ void IMessageSubscriber::ProcessMessages( float fDeltaTime )
|
||||
g_Mutex.Unlock();
|
||||
}
|
||||
|
||||
MessageSubscriber::MessageSubscriber( const MessageSubscriber &cpy )
|
||||
{
|
||||
m_vsSubscribedTo = cpy.m_vsSubscribedTo;
|
||||
}
|
||||
|
||||
void MessageSubscriber::SubscribeToMessage( const RString &sMessageName )
|
||||
{
|
||||
MESSAGEMAN->Subscribe( this, sMessageName );
|
||||
m_vsSubscribedTo.push_back( sMessageName );
|
||||
}
|
||||
|
||||
void MessageSubscriber::SubscribeToMessage( Message message )
|
||||
{
|
||||
MESSAGEMAN->Subscribe( this, message );
|
||||
m_vsSubscribedTo.push_back( MessageToString(message) );
|
||||
}
|
||||
|
||||
void MessageSubscriber::UnsubscribeAll()
|
||||
{
|
||||
FOREACH_CONST( RString, m_vsSubscribedTo, s )
|
||||
MESSAGEMAN->Unsubscribe( this, *s );
|
||||
m_vsSubscribedTo.clear();
|
||||
}
|
||||
|
||||
|
||||
// lua start
|
||||
#include "LuaBinding.h"
|
||||
|
||||
@@ -3,26 +3,6 @@
|
||||
#ifndef MessageManager_H
|
||||
#define MessageManager_H
|
||||
|
||||
class IMessageSubscriber
|
||||
{
|
||||
public:
|
||||
virtual ~IMessageSubscriber() { }
|
||||
virtual void HandleMessage( const RString& sMessage ) = 0;
|
||||
virtual void ProcessMessages( float fDeltaTime );
|
||||
void ClearMessages( const RString sMessage = "" );
|
||||
|
||||
private:
|
||||
struct QueuedMessage
|
||||
{
|
||||
RString sMessage;
|
||||
float fDelayRemaining;
|
||||
};
|
||||
void HandleMessageInternal( const RString& sMessage );
|
||||
vector<QueuedMessage> m_aMessages;
|
||||
|
||||
friend class MessageManager;
|
||||
};
|
||||
|
||||
struct lua_State;
|
||||
|
||||
enum Message
|
||||
@@ -86,6 +66,46 @@ enum Message
|
||||
};
|
||||
const RString& MessageToString( Message m );
|
||||
|
||||
|
||||
class IMessageSubscriber
|
||||
{
|
||||
public:
|
||||
virtual ~IMessageSubscriber() { }
|
||||
virtual void HandleMessage( const RString& sMessage ) = 0;
|
||||
virtual void ProcessMessages( float fDeltaTime );
|
||||
void ClearMessages( const RString sMessage = "" );
|
||||
|
||||
private:
|
||||
struct QueuedMessage
|
||||
{
|
||||
RString sMessage;
|
||||
float fDelayRemaining;
|
||||
};
|
||||
void HandleMessageInternal( const RString& sMessage );
|
||||
vector<QueuedMessage> m_aMessages;
|
||||
|
||||
friend class MessageManager;
|
||||
};
|
||||
|
||||
class MessageSubscriber : public IMessageSubscriber
|
||||
{
|
||||
public:
|
||||
MessageSubscriber() {}
|
||||
MessageSubscriber( const MessageSubscriber &cpy );
|
||||
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
void SubscribeToMessage( Message message ); // will automatically unsubscribe
|
||||
void SubscribeToMessage( const RString &sMessageName ); // will automatically unsubscribe
|
||||
|
||||
void UnsubscribeAll();
|
||||
|
||||
private:
|
||||
vector<RString> m_vsSubscribedTo;
|
||||
};
|
||||
|
||||
|
||||
class MessageManager
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user