Game Development Reference
In-Depth Information
What's interesting is that although much has changed in programming games over
the years, many concepts from the earlier eras still carry over today. In the rest of
this chapter we'll cover concepts that, on a basic level, have not changed in over
20 years: the game loop, management of time, and game object models.
The Game Loop
The game loop is the overall flow control for the entire game program. It's a loop
because the game keeps doing a series of actions over and over again until the user
quits. Each iteration of the game loop is known as a frame . Most real-time games
update several times per second: 30 and 60 are the two most common intervals. If
a game runs at 60 FPS ( frames per second ), this means that the game loop com-
pletes 60 iterations every second.
There can be many variations of the game loop, depending on a number of factors,
most notably the target hardware. Let's first discuss the traditional game loop
before exploring a more advanced formulation that's designed for more modern
hardware.
Traditional Game Loop
A traditional game loop is broken up into three distinct phases: processing inputs,
updating the game world, and generating outputs. At a high level, a basic game
loop might look like this:
while game is running
process inputs
update game world
generate outputs
loop
Each of these three phases has more depth than might be apparent at first glance.
For instance, processing inputs clearly involves detecting any inputs from devices
such as a keyboard, mouse, or controller. But those aren't the only inputs to be
considered; any external input must be processed during this phase of the game
loop.
As one example, consider a game that supports online multiplayer. An important
input for such a game is any data received over the Internet, because the state of
the game world will directly be affected by this information. Or take the case of
a sports game that supports instant replay. When a previous play is being viewed
Search WWH ::




Custom Search