9
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

5
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Aug 7, 2010 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .