Datasheet
44 SYMBIANOSGAMEBASICS
user stops interacting with the application, the thread is suspended and
only continues executing on receipt of, for example:
• an event generated when the user next does something, for example,
by pressing a key or tapping the screen
• a system event such as a timer completion
• a notification of a change of focus, such as when the user switches
to use another application, or the application is sent into the back-
ground by an incoming call or other event. For instance, the Calendar
application may have an outstanding timer that expires when the
application needs to display a notification dialog to the user to remind
them of their next appointment.
The Symbian OS application model is said to be event-driven, which
means that it does not run on a tight polling loop, constantly checking
for input or changes of system state, but instead waits to be notified to
run when it needs to respond to an event. This makes the threads that
do need actually need to run more responsive, because they don’t have
to compete for a time slice. And when no threads need to run, Symbian
OS can enter a power-saving state where all threads are suspended, thus
optimizing the battery life.
Games, and other applications with constantly changing graphics,
have different requirements to the event-driven applications described
above, because they must continue to execute regularly in order to
update their graphics and perform other calculations (such as detecting
collisions or displaying countdown timers on their screens). For a game
to execute regularly, regardless of the user input received, it is driven by
what is known as a
game loop
, which is a loop that runs regularly for the
duration of the game.
Typically, each time the game loop runs:
• The time elapsed since the last time the game loop executed is
calculated, and any user input that has occurred since then is retrieved.
• The game engine updates the game internals, taking into account
factors such as the time elapsed and the user input received.
For example, in a game like
Asteroids
,
1
the user’s key presses are used
to calculate the new position of the player’s ship, based on the actual
input received and the time that has passed since the last graphics
update. Besides making calculations to correspond to the player’s
input, the game engine also computes the new positions of all other
moving graphics elements relative to the time of the last redraw. The
1
See
developer.symbian.com/roidsgame
for a paper which describes writing an
Aster-
oids
clone for Symbian OS v9.