Game Development Reference
In-Depth Information
Figure 7.2
A multithreaded main loop.
rendering. One problem with rendering is that on modern hardware, your CPU
spends most of its time waiting for the video card to process what it just sent. By
putting the rendering system on another thread, you free up the CPU while the
GPU is working its magic (see Figure 7.2).
This is a great technique for squeezing more out of your processor, especially consid-
ering that modern processors aren
'
t really getting faster clock cycles, they
'
re getting
more cores.
Why not put everything on its own thread? You could have an architecture like the
one in Figure 7.3, where every system gets its own separate thread of execution.
One problem with using a multithreaded architecture is communication between
threads. When you have multiple threads all running at the same time and trying to
communicate with each other, you have to take steps to ensure thread safety. Fur-
thermore, threads tend to be pretty heavyweight objects, so it
'
s inefficient to use
threads for everything.
I
m not going to get too deep into the details here, since multithreaded architecture is
beyond the scope of this chapter. You
'
ll learn more about these exact issues and how
you can work around them in Chapter 19,
'
An Introduction to Game AI.
Search WWH ::




Custom Search