Quote:I highly recommend a robust message passing system. It will clean up your code in ways almost nothing else can, and helps make it thread safe if you plan to multi-thread it later.
I vaguely knew I was going to have write one of these sooner or later, especially since I was going to add a GUI to my games eventually. However I can't seem to find a good tutorial or article which outlines what I need to do to construct a simple yet robust, functional message passing system. I'm sure I've read something about how to construct a message pump and the appropriate data structures to use somewhere before, but I'm drawing a blank right now.
Does anyone have a link to a good link or reference about writing your own message passing system for a game?
void HandleMessage(MessageType q, int data1, int data2);
It's kind of useful because you can use data1 and data2 to trade out pointers. So you could send an "I am dying!" message with a pointer to yourself so that anything targeting you has a chance to drop that pointer before you are freed.
Basically, to handle the message you'd do something like:
I used sort of the same system for NPC interaction in Freezer 2, but it could be extended to large portions of the game code, including the internals. You'll need a message pump of course.