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:
Chris Danford
2006-02-06 01:26:52 +00:00
parent b03b2dc768
commit a05d1e8265
4 changed files with 68 additions and 49 deletions
+40 -20
View File
@@ -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: