Game Development Reference
In-Depth Information
There's more…
To make the
OnStop()
method work on Windows, just call it after the exit from the main loop
in
Wrapper_Windows.cpp
:
while ( !PendingExit )
{
…
}
OnStop();
The solution is now portable, and all of the logic can be debugged on Windows.
See also
F
Implementing the main loop
Implementing the main loop
In the previous chapters our code examples used the
OnTimer()
callback with a rough ixed
timestep to update the state and the
OnDrawFrame()
callback to render graphics. This is
not suitable for a real-time game where we should update the state based on the real time
elapsed since the last frame. However, it is still desirable to use a small ixed timestep in
the call to
OnTimer()
. We can solve this problem by interleaving calls to
OnTimer()
and
OnDrawFrame()
in a tricky fashion and put this logic into a game main loop.
Getting ready
There is a very interesting article called Fix Your Timestep! available at
http://
gafferongames.com/game-physics/fix-your-timestep
, which explains in great
detail different approaches to the implementation of a game main loop and why ixed
timesteps are important.
How to do it…
1.
The logic of the game main loop is platform-independent and can be put into a
method:
void GenerateTicks()
{