Datasheet

54 SYMBIANOSGAMEBASICS
2.6 System Events
As we’ve discussed, the game loop is driven by a timer active object
and runs regularly to update the game engine internals, resulting in a
given number of frames per second. For any length of time, on a mobile
operating system, this kind of regular looping can lead to a drain in
battery power. The requirement to regularly run the game thread prevents
the OS from powering down all but the most essential resources to make
efficient use of the battery.
2.6.1 Loss of Focus
As a developer, you need to be aware that the game is consuming battery
power whenever it is running the loop, and ensure that the heartbeat
timer runs only when required. For example, the game loop should be
paused when the game is interrupted by a system event, such as an
incoming call, or because the user has tasked to another application. The
game loop should also pause if the user stops interacting with the game
for any length of time; for example, if she is playing the game on the bus
and has to get off at her stop without quitting the game before doing so.
You should implement CCoeControl::FocusChanged() to be
notified of a change in focus of the game that is, when another applica-
tion or system dialog sends the game to the background. As the example
shows, the timer is halted when the focus is lost, and started when it is
regained. The benefit of having a single heartbeat time to drive the game
loop is that it is very straightforward to stop and start it when necessary.
void CSkeletonAppView::FocusChanged(TDrawNow aDrawNow)
{
if (IsFocused())
{// Focus gained
StartHeartbeat(); // Starts the gameloop
}
else
{// Focus lost
if (iPeriodicTimer->IsActive())
{
StopHeartbeat(); // Pauses the game loop
}
// Save game data here if necessary
}
if(aDrawNow)
DrawNow();
}
2.6.2 User Inactivity
If no user input is received, after a certain length of time, to minimize the
phone’s power usage, the system will gradually dim the backlight, and
eventually turn it off completely. The length of inactivity time before each