Wednesday, October 31, 2007

General steps of a game program

Step(1) Initialization
We need to make standard operations such as creating and initialization of Windows to work, allocating required memory resources, declaration of variables and structures, opening files and loading required data form disks, and other necessary resources acquisition.

Step(2) Main game loop
Enter into the main game event loop which is typically infinite loop until the user gives special signal to exit form that loop and return to Windows. All the major game functions take place within this loop.

Step(3) Retrieve player's input
This takes place inside the main game loop. The game needs to know what player want to do base on the input signals from any input devices attached to the system. Even though there is not player input signal, the game logic need to continue without additional inputs.

Step(4) Perform AI and logics
This is the main part of the game. The new positions of the objects are determined with transformation mathematics, compute ingame artificial intelligence, physics calculations and other logics are computed to render next frame of display whether or not there is player input or not.

Step(5) Render the next frame
The result of the execution of AI and physics according to the player's input are used to generate next frame of rendering. Basically, the rendering is made only on the off-screen buffer (backbuffer) area and then it is transferred to the primary display very quickly to make animation.

Step(6) Synchronization of timing
To control the variation of rendering speeds of the system that depends upon the number of objects displayed on screen, we need to synchronize the frame rate of the animation to the some pre-defined amount.

Step(7) Loop again
After finishing of the rendering of the next frame, the control of the game goes back to the entry point of the main game loop. If player wants to continue the game, the game loop starts again. If the player wants to exit from the game, the loop transfers control to the existing function.

Step(8) Shutting down
This is the end of the game. Before leaving the game, all the necessary clearing of the resources acquired in the initialization step are made. The memory is released from game and reallocated to the system.
--------------------------------------------------
References:
"Tricks of the Windows game programming gurus"
"Introduction to 3D game programming with DirectX9"
"The art of game programming"

No comments:

Post a Comment