Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Most application development is based around developing with events, but considering the game-loop style of developing games and the (often) need for high performance/throughput, what role does developing using events have and what are the trade-offs? Does the synchronization/locking that is often involved have a greater impact?

For instance: - How does the network [layer] notify the game-loop of data received? - How does the physics system notify of collisions

I ask, because I can remember a time when game development using events was a strict no-no. Has this changed?

share|improve this question
up vote 5 down vote accepted

Events system are powerful, and can be made very fast.

They also allow you to modulise sections of code in a very loose coupling structure. They let you job batch things and thread off tasks. The work well with multi-core and asynchronous functions.

Physics - Collision Callbacks, Activate or Rest Objects translate well to events. Networking - As much as possible should be an event (voice chat ect.. the exception) Game Logic - Naturally lends itself to an event model Menus & UI - Work brilliant in an event based system

Also many modern consoles, and middle-ware libraries use events.

The renderer and polling of input devices can be a bit confusing to fit in. Especially if you are using motion controls, as events can introduce a noticeable latency and be counter-intuitive to polling format.

share|improve this answer

I would say that using the main loop style is still recommended: It is fast, it gives you total control over the order of the actions (this is important in a game) and it is harder to make mistakes coding it. However, if the technology you are using allows you to easily use events, it can be really useful for a lot of things. For instance, I use them to notify when and where the enemies die, when the keyboard keys are pressed...

In conclusion: Use the game loop to control the main logic of the game, but have in mind that events can be useful in other situations.

share|improve this answer
I disagree that a main loop style is recommended. Main loop style games lose to a well-written event controlled game in several areas: 1) on multi-tasking system, they consume an unnecessarily high amount of the processor for a fixed set of features, 2) on portable devices, even on single-tasking systems the extra processor usage adversely affects battery life, 3) the simpler the game, the larger these problems become in comparison to a proper event-driven game. – Sam Harwell Aug 7 '10 at 14:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.