Gaffer Docs

Game Loops Within the APE Pattern

As discussed previously, the traditional main game loop is a form of concurrency called cooperative multitasking. One issue with that pattern is that a main game loop runs within a single thread, and therefore can only utilize a single core.

The APE Pattern calls for a game loop to be run on every core. Thus, Gaffer creates a separate thread, one for each core in the system. Each of these threads is running what equates to a traditional game loop with a few distinctions.

Primary and Auxiliary Game Loops

There is always exactly one primary game loop. This loop has the responsibilities of handling inputs and rendering. There's only one display, keyboard, and mouse, so activities involving those can't be made concurrent.

There can be zero or more auxiliary game loops. For optimal concurrency, if there are N cores, there should be N - 1 auxiliary game loops each running in its own thread.

Game Loops Figure