PDA

View Full Version : State Tables and Event Handling


geolycosa
2005.08.29, 04:02 PM
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.

ThemsAllTook
2005.08.29, 04:58 PM
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