Game Development Reference
In-Depth Information
Initialization 101
Initializing games involves performing setup tasks in a particular order, especially on
Windows platforms. Initialization tasks for Windows games are a superset of console
games due to more unpredictable hardware and OS configuration. Of course, every
platform will be different, and to cover even a few of them is beyond the scope of
this topic. If you see how this is done in a more complicated system such as Win-
dows, you
'
ll have a jump start on doing this for other platforms.
There are some tasks you must perform before creating your window, and others that
must have a valid window handle (or HWND ) and therefore happen after you create
your window. Initialization tasks for a Windows game should happen in this order:
n Check system resources: hard drive space, memory, input and output devices.
n Check the CPU speed.
n Initialize your main random number generator (this was covered in Chapter 3).
n Load programmer
'
s options for debugging purposes.
n Initialize your memory cache.
n Create your window.
n Initialize the audio system.
n Load the player
'
s game options and saved game files.
n Create your drawing surface.
n Perform initialization for game systems: physics, AI, and so on.
Some C++ Initialization Pitfalls
Before we work through our initialization checklist, let
'
s get some critical initializa-
tion pitfalls out of the way, starting with the misuse of C++ constructors. I ' ve heard
that power corrupts, and absolute power corrupts absolutely. You might get some
disagreement from Activision
ll prove it to you by show-
ing you some problems with going too far using C++ constructors to perform initiali-
zation. It turns out that C++ constructors are horrible at initializing game objects,
especially if you declare your C++ objects globally.
Programming in C++ gives you plenty of options for initializing objects and subsys-
tems. Since the constructor runs when an object comes into scope, you might believe
that you can write your initialization code like this:
'
s executives on this point. I
'
// Main.cpp
-
initialization using globals
//
 
 
 
Search WWH ::




Custom Search