Game Engine Architecture

(Ben Green) #1

7.4. Abstract Timelines 311


advancing the game clock by one target frame interval (e.g., 1/30 of a second)
each time a “single-step” butt on is pressed on the joypad or keyboard while
the game is in a paused state.
When using the approach described above, it’s important to realize that
the game loop is still running when the game is paused—only the game clock
has stopped. Single-stepping the game by adding 1/30 of a second to a paused
game clock is not the same thing as sett ing a break point in your main loop,
and then hitt ing the F5 key repeatedly to run one iteration of the loop at a
time. Both kinds of single-stepping can be useful for tracking down diff erent
kinds of problems. We just need to keep the diff erences between these ap-
proaches in mind.


7.4.3. Local and Global Timelines


We can envision all sorts of other timelines. For example, an animation clip or
audio clip might have a local timeline, with its origin (t = 0) defi ned to coincide
with the start of the clip. The local timeline measures how time progressed
when the clip was originally authored or recorded. When the clip is played
back in-game, we needn’t play it at the original rate. We might want to speed
up an animation, or slow down an audio sample. We can even play an anima-
tion backwards by running its local clock in reverse.
Any one of these eff ects can be visualized as a mapping between the lo-
cal timeline and a global timeline, such as real time or game time. To play an
animation clip back at its originally-authored speed, we simply map the start
of the animation’s local timeline (t = 0) onto the desired start time ()τ =τstart
along the global timeline. This is shown in Figure 7.1.
To play an animation clip back at half speed, we can imagine scaling the
local timeline to twice its original size prior to mapping it onto the global
timeline. To accomplish this, we simply keep track of a time scale factor or
playback rate R, in addition to the clip’s global start time τstart. This is illus-
trated in Figure 7.2. A clip can even be played in reverse, by using a negative
time scale (R < 0) as shown in Figure 7.3.


Clip A
t= 0 sec 5 sec

τsta rt = 102 sec
τ = 105 sec 110 sec

Figure 7.1. Playing an animation clip can be envisioned as mapping its local timeline onto the
global game timeline.

Free download pdf