331
As shown in Figure 7.8, the fact that jobs are relatively fi ne-grained and
independent of one another helps to maximize processor utilization. It can
also reduce or eliminate some of the restrictions placed on the main thread
in the one-thread-per-subsystem design. This architecture also scales up or
down naturally to hardware with any number of processing units (something
the one-thread-per-subsystem architecture does not do particularly well).
7.6.6. Asynchronous Program Design
When writing or retrofi tt ing a game engine to take advantage of multitasking
hardware, programmers must be careful to design their code in an asynchro-
nous manner. This means that the results of an operation will usually not be
available immediately aft er requesting it, as they would be in a synchronous
design. For example, a game might request that a ray be cast into the world, in
order to determine whether the player has line-of-sight to an enemy character.
In a synchronous design, the ray cast would be done immediately in response
to the request, and when the ray casting function returned, the results would
be available, as shown below.
Figure 7.8. In a job architecture, work is broken down into fi ne-grained chunks that can
be picked up by any available processor. This can help maximize processor utilization, while
providing the main game loop with improved fl exibility.
7.6. Multiprocessor Game Loops