Sign in to follow this  
simhau

Global messaging system

Recommended Posts

simhau    140
Hi. I'm designing some of the core of my game, and is having a little problem knowing if I'm picking the best solution for the job. The game will be a roguelike, so there will be many traps, monsters etc. on the map at any time. My first thought would be to use events (I'm using .Net), but thinking about it, I realised that everything had to listen to every object, so I started designing a messaging system. Every object tells the messaging system what kind of messages it wishes to listen to (attacking, door opening, player moving, monster dieing etc.). Once a player makes a move it sends a moving message to the messaging system. Everything that does something sends a message to the messaging system, and at the end of the turn, the messaging system loops thru the queue and dispatches the messages to all the objects that is interested in a messagetype like this. I've allready programmed a test, and it seems to be working ok. But this will be a very central element in the core of the game, and I do not wish to screw up being required to refactor 6 months after I start the development. Can anyone see a better sollution for a system like this? EDIT: I have moved this message to game programming as it fits more in that forum [Edited by - simhau on August 5, 2004 1:57:25 PM]

Share this post


Link to post
Share on other sites
sporff    166
it's a good system. i have a very large messaging system in my little AI project. the one difference is that there is a global message queue which handles a lot of global things but then there's also queues for each "entity". i find it much easier if entities can talk directly to one and other instead of say.. an entity getting the ID or pointer of another one and sending a global message and the global messenger telling the other entity what to do. i use linked lists to keep the memory to a minimum. seems to be plenty fast enough.

don't know exactly what your needs are though. messaging systems are very powerful as it allows you to communicate between objects in a more common sense way instead of say one object calling a member function of another. you just send it a message.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this