Game Development Reference
In-Depth Information
Set your m_bQuitRequested = true
Call the model dialog box:
Are you sure you want to quit?
If (user said no)
{
Abort the quit request
-
return here.
}
}
// By here we are quitting the game, by request or by force.
Set you m_bQutting = true
If (a modal dialog box is up)
{
Force the dialog to close with a default answer
Repost the WM_SYSCOMMAND message again to close the game
Set m_bQuitRequested = false
}
You
ll want to take a closer look at the source code to see more, but this code will
allow the game to bring up a quit dialog even if the player presses Alt-F4 or another
app, like an install program, and attempts to shut down your game by force.
'
Shutting Down the Game
With some exceptions, you should shut down or deallocate game systems in the
reverse order of which they were created. This is a good rule of thumb to use when-
ever you are grabbing and releasing multiple resources that depend on each other.
Each data structure should be traversed and freed. Take care that any code that is
run inside destructors has the resources it needs to execute properly. It
s pretty easy
to imagine a situation where the careless programmer has uninitialized something in
the wrong order and a destructor somewhere fails catastrophically. Be extremely
aware of your dependencies, and where multiple dependencies exist, lean on a refer-
ence counting mechanism, such as smart pointers, to hold on to resources until they
really aren
'
t needed anymore.
The message pump, GameCodeApp::MsgProc , will receive a WM_CLOSE message
when it is time for you to shut down your game, and you
'
'
ll handle it by calling the
nonstatic GameCodeApp::OnClose method:
case WM_CLOSE:
{
result = g_pApp->OnClose();
break;
}
 
 
Search WWH ::




Custom Search