135
Chapter 4 Perspective, Scene Design, and Basic Animation
One solution to a device with low CPU power is to use blitting or double
buffering with bitmaps. The basic premise of blitting or double buffering a
bitmap is to significantly reduce the amount of CPU usage. Imagine running
the same scrolling image in one case where 90 percent of the CPU is used and
another that uses only 10 percent of the CPU—without loss of quality. This can
be achieved using blitting and double buffering.
Blitting
Blitting
is a computer operation that takes one or more bitmap images from
a memory block and displaying it on a display device or copying it into another
bitmap image. Blit stands for bit block transfer. When video games are designed
and programmed, several different images and objects must be displayed on
the screen. The computer tracks all of these images independently, combines
them, and displays them all as a single screen image. Blitting takes out all
the individual images and only sends a single rasterized image to the CPU
to display. The CPU has less work to do because only the pixels that change
from one screen to the next must be generated. The unchanged pixels remain
illuminated from the previous screen image.
Blitting works because the display refreshes very quickly. The
refresh
rate
is how often the screen is redrawn. Refresh rates are measured in Hertz
(Hz), which is how many times per second something occurs. A refresh rate
of 1 Hz refreshes the screen once every second. Refresh rate is different from
frame rate.
Frame rate
is the speed at which frames are played, while refresh
rate is the frequency that a displayed frame is redrawn. Video displays have a
refresh rate higher than the frame rate. For example, a computer typically has
a frame rate of 30 frames per second, but most monitors have a refresh rate
of at least 60 Hz. This combination means each frame is redrawn twice and
there are 60 calls to draw per second (30 × 2 = 60).
For digital video displays, each pixel must be drawn in at a refresh rate
of 60 Hz or higher. Because some television, movie, and HD monitors have
substantially higher refresh rates—as high as 600 Hz or more—blitting is not
needed for equipment with these high-end specifications.
Double Buffering
Blitting uses double buffering to combine the individual game objects into
a single bitmap that is rendered on the screen.
Buffering
is preloading data into
a section of memory called the buffer. Everyone who has downloaded a song,
game, movie, or other streaming video or audio has seen a playback bar at the
bottom of his or her screen, as shown in Figure 4-15. The data bar typically
shows the current position of the video and also the downloaded amount
in the buffer. The video display is reading the information directly from the
buffer memory location. If the playback rate is faster than the download rate,
the audio or video will stop, lag, pause, or even display an hourglass with a
message stating “Buffering…”.
Reducing CPU Usage