Game Programming - Game Structure

Game Structure

The central component of any game, from a programming standpoint, is the game loop. The game loop allows the game to run smoothly regardless of a user's input or lack thereof.

Most traditional software programs respond to user input and do nothing without it. For example, a word processor formats words and text as a user types. If the user doesn't type anything, the word processor does nothing. Some functions may take a long time to complete, but all are initiated by a user telling the program to do something.

Games, on the other hand, must continue to operate regardless of a user's input. The game loop allows this. A highly simplified game loop, in pseudocode, might look something like this:

while( user doesn't exit ) check for user input run AI move enemies resolve collisions draw graphics play sounds end while

The game loop may be refined and modified as game development progresses, but most games are based on this basic idea.

Game loops differ depending on the platform they are developed for. For example, games written for DOS and most consoles can dominate and exploit available processing resources without restraint. However, game for a modern PC operating system such as Microsoft Windows must operate within the constraints of the process scheduler. Some modern games run multiple threads so that, for example, the computation of character AI can be decoupled from the generation of smooth motion within the game. This has the disadvantage of (slightly) increased overhead, but the game may run more smoothly and efficiently on hyper-threading or multicore processors and on multiprocessor platforms. With the computer industry's focus on CPUs with more cores that can execute more threads, this is becoming increasingly important. Consoles like the Xbox 360 and PlayStation 3 already have more than one core per processor, and execute more than one thread per core.

Read more about this topic:  Game Programming

Famous quotes containing the words game and/or structure:

    Truth is the cry of all, but the game of few.
    George Berkeley (1685–1753)

    Each structure and institution here was so primitive that you could at once refer it to its source; but our buildings commonly suggest neither their origin nor their purpose.
    Henry David Thoreau (1817–1862)