Jump to content
  • Advertisement
Sign in to follow this  
Kanefa

Game Event System

This topic is 2056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was reading the Simple Event Handling article and I noticed every class that inherits IEventHandler registers as a listener for all events.  The class then implements the EventHandler member function and handles the events it is interested in.  

 

This is a bit different that what I expected.  In a more complex event system wouldn't the game event manager class register the listener and a specific event?  Then the game event manager class is tasked with matching the event with the listeners.

 

I just want clarify that this is a simplified implementation and not a mistake in my understanding.

 

 

Next, I have a question about integrating something similar to the Simple Event Handling article into my game.  My confusion stems from the fact my game loop already polls for events and then feeds these events to my already existing HandleEvent functions that cascades through my game.  I assume both these systems are necessary, but I would seem to need two different HandleEvents functions.  One for events coming from the OS and then one for events that I create at a much higher level.  I am having a hard time visualizing how I imeplement both these systems independently of each other in the same code base.  Any help would be much appreciated!

 

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

There are many possibilities to dispatch events, and there are many solutions of how to supply your game sub-systems with informations. Of course, it depends on your overall coding philosophy and the particular purpose you are interested in.

 

Registering to be notified for each and all events may be as bad as registering for each single kind of event. It depends on how many kinds of events exist, how high the rate of events is, how many listeners there are, how many kinds of events a listener is interested in, how many virtual functions need to be invoked for dispatching an event, how high the administrative effort is to manage listeners / listener plus event filters, and perhaps more. Dispatching inside the listener by using a switch, registering with distinct event queue's, using a filter on events before invoking the listener, … are all valid approaches. Perhaps a mix of several of those is the way to go in the end. However, the article is titled "Simple Event Handling" ;)

 

In the OP you are speaking of input (and perhaps other OS / windowing system generated evens) as events as well as game related "high level" events (without further specification). It is probably not wise to mix them up. Besides the fact that the solution I'd prefer don't propagates input at all, you may think of translating input into game events in an early stage. E.g. if a handler detects a specific input situation when investigating the current input queue (I mean a self implemented queue here, not the OS provided queue), then it generates a game event accordingly to an input configuration (you know, the player likes to map her owned input devices to game events).

Share this post


Link to post
Share on other sites

If this is your first experience with implementing your own Event System, I recommend just sticking with the Simple method to start.  Once you've gotten that fully functional you can think about enhancing it.  

 

One simple enhancement possibility:  Instead of maintaining a simple list of listeners and sending all events to all listeners, maintain a map of event type keys to list of listeners values.  Then each listener registers for a specific event type, or even registers for multiple event types, and your Event Dispatcher will only send an event to those listeners specifically registered for that event.

Share this post


Link to post
Share on other sites

Thanks guys that helped clear it up.  Also, I really like that idea of using a map with lists of listeners.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!