Archived

This topic is now archived and is closed to further replies.

Tealc

Messaging-System

Recommended Posts

Hello, currently I''m planning a game and want to implement a generic messaging system which can handle nearby all messages in my game (graphics, sound, etc.). I''ve looked for some tutorials or articles but I didn''t found one (except those about the windows message queue). So I would like to know if somebody knows a good resource for it or some ideas how to create such a messaging system. Best Regards, Tealc

Share this post


Link to post
Share on other sites
I've never done this before but here goes.

Define a general (perhaps template) message object.

    
template <typename T>
class CMessage{
public:
// these tell you who the message is from to

unsigned int m_uiFromID;
unsigned int m_uiToID;
// whatever other gear a message may need

unsigned int m_uiTimeStamp;
unsigned int m_uiPriority; ?? might be cool
...
}

then you can have messages specifically for sound

    
class CSoundMessage : public Message<CSound>{
// some extra info in the message which especially pertains

// to sound messages

...
}

if you don't use templates on CMessage then
you can have a general message queue which holds CMessages.
these can be CSoundMessage or whatever since they'll be type
compatible...
or if you do you can have a separate queue for each resource,
one for sound one for graphics - this is where using templates
is good because it provides type safety.

  
template
class CMessageQueue{
private:
std::queue m_Queue;
// whatever else

public:
// returns the first message off the queue which is for you

T GetMessage(unsigned int uiToID);
// posts a message

PostMessage(T Message);
}


then you could go

        
class CSoundMessageQueue : CMessageQueue<CSoundMessage>{
// any other specifics you want for sound message queues

}


like I said before its something I made up as I went along, but it might work. however its probably a fairly average design, software architecture ain't my strong point.

good luck
Toby


Gobsmacked - by Toby Murray

[edited by - tobymurray on August 15, 2002 12:25:50 PM]

Share this post


Link to post
Share on other sites