Datasheet

46 SYMBIANOSGAMEBASICS
Calculate time elapsed
Retrieve user input
Update game internals
Update graphics
Synchronize audio
LOO
P
Figure 2.1 A graphical representation of a game loop
2.3 The Heartbeat Timer
On Symbian OS, it is important not to hog the CPU so you should not
run a tight synchronous loop like the one shown in pseudocode above.
The game loop must return control to the thread’s active scheduler to
allow other system events to run as necessary, allowing other threads in
the system the opportunity to run. If the game loop prevents the active
scheduler from running a particular active object associated with the view
server regularly, between 10 and 20 seconds, the infamous EVwsView-
EventTimeOut panic occurs. This terminates the game thread with
panic category ViewSrv and error code 11.
So instead of trying to work around this, on Symbian OS, a game loop
should be run using a timer active object, such as CTimer or CPeriodic,
to trigger the game loop to run regularly. It is better to use a single timer to
run one iteration of the game loop than to use multiple timers to control
different time-based events in the game. The latter approach can lead to
very complex code, since there may be many elements in a game that
respond after different timeouts have expired, which would be difficult
to synchronize and to debug. Active objects cannot be pre-empted, so
the accuracy of a timer active object is also dependent on other active
objects in the system. If multiple timers are used for different events, the
combination could lead to significant timer drift for some lower-priority
active objects. Additionally, each timer consumes kernel resources if a
large number are required, this could add up to an undesirable system
overhead.