Event Driven Messaging System

Hi all,

I have just started on an event driven messaging system where by an entity sends another entity a message which can be sent at a particular moment in time.



The message will include:



Stimulus, e.g. Shooting (This can be pre diffined in games )

From, e.g. Player

To, e.g. Bird

Time, e.g. in 3 secs

Data, e.g. Ray’s location and direction.



So the complete message:



Stimulus: PLAYER_SHOOTING_USING_9MM

From: Player

To: Bird

Time: 0.2f

Data: new Ray(camera.getLocation(), camera.getDirection());



would anybody like something else in there? You could always extend the Message object and add more, but as default, what else should be included?



DP

True message driven events are usually multi-threaded. How are you going to handle your message queues, and to keep them thread safe? What kind of synchronization techniques are you using?

why does it need to be thread safe? I was thinking of creating a MessageManager which will be a pool for all messages to be sent to their entities. an update(float time) to the manager on each frame will bind the manager to time. This will in effect create the delay effect in the time variable.



DP

It’s probably pretty likely that multiple threads will be accessing that MessageManager at the same time… so at least it will need to be thread safe. (Multiple messages being added to the queue – need to make sure they don’t screw each other up.)



As an alternative, you could do something like Swing does with its single event thread… making other threads use a utility to insert code within the Swing event thread. (See: SwingUtilities.invokeLater and SwingUtilities.invokeAndWait for examples) It’s not nearly as user friendly as just making the manager thread safe, though.



It shouldn’t be too bad… has the feel of just a couple synchronized blocks and/or methods.



(As a barely-passing-for-interesting side note, I spent the better part of last week trying to fix one bug related to concurrency issues. Eventually, the code and I just had to throw down and have a good old-fashioned refactoring brawl. American-speak aside… I basically had to reorganize a huge chunk of code because under high-stress conditions, we were getting a deadlock.)





–K

Ok, an Event Driven Messaging system is complete and its fully functional.



Its extremely customisable and very simple to use too.



So the question is, which shall I go on to do? Pathfinding, or Neural Networks?



DP

My vote? Pathfinding.

thought youd say that. Ive already started 8)

I think path finding will extremely improve JME. What method are you using?

me and outrunner’s methods will be very abstract, it will be up to the scripting engine to do most of the work because we feel that it is impossible to create a one-for-all solution.



Having said that, we will include a demo on how to get A* working.



DP