Game Development Reference
In-Depth Information
m_screenSize = CPoint(screenWidth, screenHeight);
DXUTCreateDevice( D3D_FEATURE_LEVEL_10_1, true, screenWidth, screenHeight);
m_Renderer = shared_ptr<IRenderer>(GCC_NEW D3DRenderer11());
m_Renderer->VSetBackgroundColor(255, 20, 20, 200);
m_Renderer->VOnRestore();
m_pGame = VCreateGameAndView();
if (!m_pGame)
return false;
// now that all the major systems are initialized, preload resources
m_ResCache->Preload(
*.ogg
, NULL);
m_ResCache->Preload(
*.dds
, NULL);
m_ResCache->Preload(
*.jpg
, NULL);
, NULL);
You have to make sure that everything is initialized before some other subsystem
needs it to exist. Inevitably, you
m_ResCache->Preload(
*.sdkmesh
'
ll find yourself in a catch-22 situation, and you
'
ll
'
see that two subsystems depend on each other
s existence. The way out is to create
one in a hobbled state, initialize the other, and then notify the first that the other
exists. It may seem a little weird, but you
ll probably run into this more than once.
The next sections tell you more about how to do these tasks and why each is
important.
'
Checking for Multiple Instances of Your Game
If your game takes a moment to get around to creating a window, a player might get
a little impatient and double-click the game
'
s icon a few times. If you don
'
t take the
precaution of handling this problem, you
ll find that users can quickly create a few
dozen instances of your game, none of which will properly initialize. You should cre-
ate a splash screen to help minimize this problem, but it
'
'
s still a good idea to detect
an existing instance of your game.
bool IsOnlyInstance(LPCTSTR gameTitle)
{
// Find the window. If active, set and return false
// Only one game instance may have this mutex at a time...
HANDLE handle = CreateMutex(NULL, TRUE, gameTitle);
// Does anyone else think
'
ERROR_SUCCESS
'
is a bit of an oxymoron?
if (GetLastError() != ERROR_SUCCESS)
{
HWND hWnd = FindWindow(gameTitle, NULL);
if (hWnd)
{
 
 
Search WWH ::




Custom Search