Game Development Reference
In-Depth Information
DataFiles g_DataFiles;
AudioSystem g_AudioSystem;
VideoSystem g_VideoSystem;
int main(void)
{
bool done = false;
while (! done)
{
// imagine a cool main loop here
}
return 0;
}
The global objects in this source code example are all complicated objects that could
encapsulate some game subsystems. The fledgling game programmer might briefly
enjoy the elegant look of this code, but that love affair will be quite short lived. When
any of these initialization tasks fail, and they will, there ' s no easy way to recover.
I
m
suggesting that any problem with initialization should give the player a chance to do
something about it, such as wiping the peanut butter off the DVD. To do this, you
need a user interface of some kind, and depending on where the failure happens,
your user interface might not be initialized yet.
Global objects under C++ are initialized before the entry point, in this case main(void) .
One problem with this is ordering; you can
'
m not talking about using exception handling as a recovery mechanism. Rather, I
'
t control the order in which global
objects are instantiated. Sometimes the objects are instantiated in the order of the
link, but you can
'
t count on that being the case with all compilers, and even if it
were predictable, you shouldn
'
'
t count on it. What makes this problem worse is that
since C++ constructors have no return value, you are forced to do something ugly to
find out if anything went wrong. The wise programmer will inform his game players
about what has gone wrong so they can have some possibility of fixing the problem.
The simpler alternative of failing and dropping back to the operating system with
some lame error message is sure to provoke a strong reaction.
If you want to inform the player, you might want to do it with a simple dialog box.
This assumes that you
ve already initialized the systems that make the dialog box
function: video, user interface, data files that contain the button art, font system,
and so on. This is certainly not always possible. What if your nosey game player
hacked into the art data files and screwed them up? You won
'
'
t have any button art
'
to display your nice dialog box telling hackers they
ve screwed themselves. You have
Search WWH ::




Custom Search