Skip to main content
GameDev.net gamedev.net
🔒 Locked

Messaging System

Started by Hippokrates May 12, 2003 at 3:17 PM 3 replies 450+ views
Original Post
Hippokrates
Hippokrates
For my engine-to-hopefully-one-day-be I would like to create a messaging system. It should be able to fulfill the following: 1) Any Object (derived from some base class) can register for any message 2) Messages are only sent to registered receivers 3) The Engine will be packed into a DLL but the ''User'' should still be able to create his own messages and send them via the system 4) It should not be too slow I would appreciate any comments on how I could do this
Im Anfang war die Tat...Faust
Vich
Vich
Just make some kind of client-server system with a message class.
Like:


  
class CMessageHandler
{
CMessageHandler();
~CMessageHandler();
SendMessage(char *message);
RegisterClient(CReceiver *client);
};


class CReceiver
{
CReceiver(int id);
~CReceiver();
};

class CSender
{
CSender(int id);
~CSender();
};

[www.LifeIsDigital.net - My open source projects and articles.
Hippokrates
Hippokrates
hm.
Well, what I thought of was:
Any instance of any class can register for any specific message, meaning that every object gets only the messages it needs.
And how would I handle this situation:
The GUI class manages some layouts which, in turn, manage controls. When the user now clicks with the mouse the Input Engine will generate a Mouseclick message and hand it over to a global message handler.

1) Who should register for ''mouse-click''? The controls or the GUI as a whole?
2) Since the interface for sending messages should be abstract, how do I figure out what message I got?
3) How do I handle the message?
Since controls should do what the user wants them to and the engine cannot know that. There will be no difference between the ''ok'' and ''cancel'' button except that they should provoke different user defined actions. How can I have the user supply the final message handling once I know which button (or whatever) was clicked?
Im Anfang war die Tat...Faust
antareus
antareus
These are very open ended questions that are best answered through prototyping. I have gone through 10 or 11 such prototypes like that.

Closest, type-safe way of doing it is the "typed message" pattern. Google it.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Vich
Vich
quote:
Original post by antareus
These are very open ended questions that are best answered through prototyping. I have gone through 10 or 11 such prototypes like that.

Closest, type-safe way of doing it is the "typed message" pattern. Google it.



Yeah, one can get really far by just using his/her creativity, some common sense and google off course.

[offtopic]
My personal wisdom of the day is:
"My basic needs in life are food, love and a C++ compiler"

[/offtopic]

[edited by - Vich on May 13, 2003 4:34:06 PM]
[www.LifeIsDigital.net - My open source projects and articles.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.