Game Development Reference
In-Depth Information
printf(
The video system is screwed.
);
return 1;
}
bool done = false;
while (! done)
{
// imagine a cool main loop here
}
SAFE_DELETE(gp_VideoSystem);
// AVOID DEADLOCK!!!
SAFE_DELETE(gp_AudioSystem);
SAFE_DELETE(gp_DataFiles);
return 0;
}
Note that the objects are released in the reverse order in which they were instanti-
ated. This is no mistake, and it is a great practice whenever you need to grab a
bunch of resources of different kinds in order to do something. In multithreaded oper-
ating systems with limited resources, deadlock occurs when two threads can ' tdotheir
work because each has a resource the other needs. You can avoid deadlock by allocating
and deallocating your resources in this way. You
'
ll learn more about deadlock in Chap-
ter 20,
Computers are very patient and will hap-
pily wait until the sun explodes. Get in the habit of programming with that problem in
mind, even if your code will never run on an operating system where that will be a
problem. It
Introduction to Multiprogramming.
'
s a great habit, and you
'
ll avoid some nasty bugs.
The Game's Application Layer
We
ll create
the class for your application layer, a very Windows-specific thing. The application
layer would be completely rewritten for different operating systems, such as Linux,
or consoles like the Wii. The application layer class is instantiated as a global single-
ton object and is referred to throughout your code through a pointer. It is con-
structed globally, too, since it has to be there from the entry point to the program
termination.
'
re now ready to work our way through the initialization checklist. We
'
WinMain : The Windows Entry Point
The GameCode4 framework sets its Windows entry point to the function below; this is
the code that will begin executing after any global constructor code is finishing running.
It sets up calls for DirectX to work properly, runs the initialization sequence, enters the
main loop, and runs any shutdown code after the main loop exits.
 
 
 
Search WWH ::




Custom Search