Game Development Reference
In-Depth Information
basically a huge memory leak, even though the operating system cleans it up. A tight
exit mechanism will show you a single byte of leaked memory before returning con-
trol to the operating system. This is important for all games, Windows or console.
Always Fix Leaks, Fast
Games should never leak memory. Period. The reality of it is that some
Windows API calls leak resources, and you just have to live with it. That
s
no reason your game code should be sloppy; hold yourself to a higher
standard, and you won
'
'
t get a reputation for crappy software.
How Do I Get Out of Here?
There are two ways to stop a game from executing without yanking the power cord:
n The player quits the game on purpose.
n The operating system shuts the application down.
If the player chooses to stop playing, the first thing you should do is ask the player if he
wants to save his game. The last thing someone needs is to lose six hours of progress only
to hit the wrong button by accident. One standard detects if the current state of the game
has changed since the last time the user saved, and only if the state is different does the
system ask if the player wants to save his game. It is equally annoying to save your game,
select quit, and have the idiot application ask if the game needs saving all over again.
Console programmers can stop here and simply run their exit code, destroying all the
game systems generally in the reverse order in which they were created. Windows
programmers, as usual, don
t get off nearly that easy.
When Windows decides your game has to shut down, it sends a different message.
Windows apps should intercept the WM_SYSCOMMAND message and look for
SC_CLOSE in the wParam . This is what Windows sends to applications that are
being closed, perhaps against their will. This can happen if the machine is shut
down, runs low on battery power, or if the player hits Alt-F4.
The problem with this message is that Alt-F4 should act just like your normal exit,
asking you if you want to quit. If you can save to a temporary location and load that
state the next time the player starts, your players will thank you. Most likely, they
were just getting to the boss encounter, and the batteries on their laptop finally ran
out of motivated electrons.
You have to double-check for multiple entries into this code with a Boolean variable.
If your players hit Alt-F4 and bring up a dialog box in your game asking if they want
'
 
 
Search WWH ::




Custom Search