CREATING A SOLID PROGRAM STRUCTURE…
NOTE: This should be the first agenda on your list. I just wanted to show you the game-loop theory to assure you that games programming isn’t a god-like task but something that can be broken down into simple steps…
Okay, lets clear our minds.
When you begin programming in most languages, the first function( I’ll use this term for now…) you’ll program is the “entry-point” - or the “Main” function. Think of it as the “General” of the enitre program. It will call a small amount of other functions - who in turn will call many other functions to do a specific task…a bit like a “tree-diagram”.
This concept should be familar to any programmer!
Now, then - lets take a look at the contents of a “General” function in a computer game…
Call 1: Program initialisation etc...
Call 2: Copyright & credits.
Call 3: Game/Story Introduction.
Call 4: The game itself...
Call 5: Cleanup and exit program.
…After “Call 5”, the program will end and return back to the calling Operating System. Each of the calls are functions - being called to perform an indivial part of the program. But the one thing that I want you all to take note of is this - EACH OF THESE FUNCTIONS COULD CONTAIN A “GAME-LOOP”!
However, before we get back to the game loop, we must also talk about an important group of variables that can act as a group of signals for the purpose of deciding which part of the program we want to go to. So lets make a “command group” of variables…
1) Current_menu_selected
2) Exit_program
3) Number_of_hours_played
…and thus we have three command( or global ) variables. Now we have these, we can use them to decide which part of the program we want to go to. The first variable, “Current_Menu_Selected”, would be used as a selector for a “Switch” or “Case” statement. Lets look at the “options” for a basic “Which menu shall we enter” switch/Case statement…
1) Menu for general game options.
2) Menu for Graphics options.
3) Menu for Audio options.
4) Menu for Controller calibration.
5) Start a new game.
…so maybe at run-time, you would encounter a menu that presented the above items - you would press “1” on the keyboard and thus the value stored at “Current_menu_Selected” would be changed to the value of “1”. So of course the switch statement will select the first item in the selection list and go to the area of the program that deals with general-game-options. This could be another basic function call…
Now at some point you want to be able to exit the program. That could be where the “Exit_Program” variable comes in. Storing a basic “True or False” value in “Exit_Program”, we can use these two values to decide in a conditional statement if we want to…ummm…exit the program! This could be in the “Main” or “General” function - most likey in a simple loop.
If there is a menu option that asks “Exit back to Windows” - we select it and the value stored at “Exit_program” changes from “0”( False ) to “1”( True ). And there for the “General”/“Main” function will then call the function to clean-up and then return control back to the operating system.
Lastly, there is “Number_Of_Hours_Played”. I’ve thrown this in as an example of additional information that you may need access to. For instance - how many games have you played where a “hidden extra” appears when you have played for a certain amount of hours? You get the idea. This is how important setting up a good program-architecture is…
Phew! A few basic concepts there that aren’t usually considered by most programming authors…and yet before we are finished, we must look a little more indepth at the “Game-loop” again…
. It’ll be interesting to see how Microsoft handles OpenGL 2.0 when it comes out. If they spit on it and ignore new specifications as they have done in the past, it’s dead in the water.

