State Tables and Event Handling

Post: #1
I am laying out a design for a game engine, and I've never written one before, so I have a few fundamental design questions. The one I'm tackling right now is event handling. Right now, what I plan to do is implement a finite state table system to dictate the motions and behaviors of in-game objects as well as control several internal parts of the engine (like parsing data files). The way I plan to set it all up is to create an event buffer which each instance of the state table class would cross reference each cycle to see if it needs to change state. This method seems a bit slow, as there could be hundreds of objects checking the event buffer each cycle. Is there a better way to do this?

Thanks in advance for your help.
Quote this message in a reply
Posts: 1,563
Joined: 2003.10
Post: #2
Rather than having every event receiver poll the event queue, what's generally better is to have the event queue use callbacks to notify receivers when an event occurs. Each receiver registers a function pointer and a set of event types for which it wants to receive notifications. Once per cycle, your event queue can iterate through its pending events, and dispatch them to those receivers who are interested in hearing about them. Carbon and Cocoa bolth use this event model. It's a very clean and efficient way to do things.

- Alex Diener
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [C++] How do you implement a state chart or state machine? riruilo 1 3,843 Jul 27, 2009 10:37 PM
Last Post: wadesworld
  Full Screen Event Handling kodex 4 5,788 Jun 27, 2008 08:37 PM
Last Post: OneSadCookie
  Event Handling (Keyboard and Mouse) bwalters 6 8,717 Mar 12, 2006 08:17 PM
Last Post: OneSadCookie
  Handling a return or enter key event on an edit text control monteboyd 7 7,282 Nov 7, 2005 03:29 PM
Last Post: monteboyd
  Sin/Cos lookup tables. How? Joseph Duchesne 10 6,927 Sep 14, 2004 08:59 PM
Last Post: arekkusu