Game Engine Architecture

(Ben Green) #1
333

// ...
}

In many instances, asynchronous code can kick off a request on one frame,
and pick up the results on the next. In this case, you may see code that looks
like this:


RayCastResult r;
boolrayJobPending = false;
while (true) // main game loop
{

// ...

// Wait for the results of last frame’s ray cast job.
if (rayJobPending)
{
waitForRayCastResults(&r);

// Process results...
if (r.hitSomething() && isEnemy(r.getHitObject()))
{
// Player can see the enemy.
// ...
}
}

// Cast a new ray for next frame.
rayJobPending = true;
requestRayCast(playerPos, enemyPos, &r);

// Do other work...

// ...
}

7.7 Networked Multiplayer Game Loops


The game loop of a networked multiplayer game is particularly interesting,
so we’ll have a brief look at how such loops are structured. We don’t have
room here to go into the all of the details of how multiplayer games work.
(Refer to [3] for an excellent in-depth discussion of the topic.) However, we’ll
provide a brief overview of the two most-common multiplayer architectures
here, and then look at how these architectures aff ect the structure of the game
loop.


7.7. Networked Multiplayer Game Loops

Free download pdf