Game Development Reference
In-Depth Information
Structuring each frame
All games start up, initialize, and run in a loop until it is time to close down and clean
up. The big difference that games have over other applications is they will often load,
reinitialize, and destroy content multiple times over the life of the process, as the play-
er progresses through different levels or stages of the game.
Another difference lies in the interactive element of games. To create an immersive
and responsive experience, games need to iterate through all of the subsystems, pro-
cessing input and logic before presenting video and audio to the player at a high
rate. Each video iteration presented to the player is called a Frame . The performance
of games can be drawn from the number of frames that appear on the monitor in a
second, which leads to the term Frames Per Second or FPS (not to be confused with
First Person Shooter). Modern games need to process an incredible amount of data
and repeatedly draw highly detailed objects 30-60 times per second, which means
that they need to do all of the work in a short span of time. For modern games that
claim to run at 60 FPS, this means that they need to complete all of the process-
ing and rendering in under 1/60th of a second. Some games spread the processing
across multiple frames, or make use of multithreading to allow intensive calculations,
while still maintaining the desired frame rate. The key thing to ensure here is that the
latency from user input to the result appearing on screen is minimized, as this can
impact the player experience, depending on the type of game being developed.
The loop that operates at the frame rate of the game is called the game loop. In the
days of Win32 games, there was a lot of discussion about the best way to structure
the game loop so that the system would have enough time to process the operating
system messages. Now that we have shifted from polling operating system messages
to an event-based system, we no longer need to worry, and can instead just create a
simple while loop to handle everything.
A modern game loop would look like the following:
while the game is running
{
Update the timer
Dispatch Events
Update the Game State
Search WWH ::




Custom Search