303
7 The Game Loop and Real-Time Simulation
G
ames are real-time, dynamic, interactive computer simulations. As such,
time plays an incredibly important role in any electronic game. There are
many diff erent kinds of time to deal with in a game engine—real time , game
time , the local timeline of an animation, the actual CPU cycles spent within
a particular function, and the list goes on. Every engine system might defi ne
and manipulate time diff erently. We must have a solid understanding of all
the ways time can be used in a game. In this chapter, we’ll take a look at how
real-time, dynamic simulation soft ware works and explore the common ways
in which time plays a role in such a simulation.
7.1 The Rendering Loop
In a graphical user interface (GUI), of the sort found on a Windows PC or a
Macintosh, the majority of the screen’s contents are static. Only a small part
of any one window is actively changing appearance at any given moment.
Because of this, graphical user interfaces have traditionally been drawn on-
screen via a technique known as rectangle invalidation , in which only the small
portions of the screen whose contents have actually changed are re-drawn.
Older 2D video games used similar techniques to minimize the number of
pixels that needed to be drawn.