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:

    The most disgusting cad in the world is the man who, on grounds of decorum and morality, avoids the game of love. He is one who puts his own ease and security above the most laudable of philanthropies.
    —H.L. (Henry Lewis)

    One theme links together these new proposals for family policy—the idea that the family is exceedingly durable. Changes in structure and function and individual roles are not to be confused with the collapse of the family. Families remain more important in the lives of children than other institutions. Family ties are stronger and more vital than many of us imagine in the perennial atmosphere of crisis surrounding the subject.
    Joseph Featherstone (20th century)