/
Globalization.cpp
executable file
·313 lines (261 loc) · 12.7 KB
/
Globalization.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//--------------------------------------------------------------------------------------
// File: Globalization.cpp
//
// Empty starting point for new Direct3D applications
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "dxstdafx.h"
#include "resource.h"
#include "mp3player.h"
#include "game.h"
#include "globaldefine.h"
//--------------------------------------------------------------------------------------
// Globals
//--------------------------------------------------------------------------------------
Cmp3player g_mp3p; //! MP3 Player used to play music!
CGame* g_pGame; //! uhhh
//--------------------------------------------------------------------------------------
// Function Prototypes
//--------------------------------------------------------------------------------------
void InitApp(); //! Initializes
void CleanupApp(); //! Cleans up memory allocated in InitApp()
//VOID RenderText();
VOID HandleGraphEvent(); //! Used to handle graph mp3 player
UINT WCharStringToCharString(LPCWSTR fn, LPSTR pszFilename, int MAXLENGTH);
bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext );
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext );
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext );
HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext );
void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext );
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext );
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext );
void CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext );
void CALLBACK MouseProc(bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext);
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );
void CALLBACK OnLostDevice( void* pUserContext );
void CALLBACK OnDestroyDevice( void* pUserContext );
//--------------------------------------------------------------------------------------
// Preloads the music and sound effects
//--------------------------------------------------------------------------------------
void InitApp()
{
//! Play bg music
g_mp3p.PlayFile(g_cstrThemeSong, DXUTGetHWND(), WM_GRAPHNOTIFY);
//! Setup Sound manager and Preload soundfx
g_pGame->InitApp(DXUTGetHWND());
//TODO:
}
void CleanupApp()
{
g_mp3p.CleanUp();
}
//--------------------------------------------------------------------------------------
// Used to handle mp3 player
//--------------------------------------------------------------------------------------
VOID HandleGraphEvent() {
if(!g_mp3p.IsEventInit())
return;
long evCode;
LONG_PTR param1, param2;
while(SUCCEEDED(g_mp3p.pEvent->GetEvent(&evCode, ¶m1, ¶m2, 0))) {
g_mp3p.pEvent->FreeEventParams(evCode, param1, param2);
switch(evCode) {
case EC_COMPLETE: // loop bg music
g_mp3p.CleanUp();
g_mp3p.PlayFile(g_cstrThemeSong, DXUTGetHWND(), WM_GRAPHNOTIFY);
return;
case EC_USERABORT: // Fall through.
case EC_ERRORABORT:
g_mp3p.CleanUp();
return;
}
}
}
//! Converts a psz wchar to a psz char.
UINT WCharStringToCharString(LPCWSTR fn, LPSTR pszFilename, int MAXLENGTH) {
UINT nLength;
StringCchLength(fn, MAXLENGTH, &nLength);
WideCharToMultiByte(CP_ACP, NULL, fn, nLength, pszFilename, MAXLENGTH, NULL, NULL);
pszFilename[nLength] = 0; // null terminate string
return nLength;
}
//--------------------------------------------------------------------------------------
// Rejects any devices that aren't acceptable by returning false
//--------------------------------------------------------------------------------------
bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat,
D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext )
{
// Typically want to skip backbuffer formats that don't support alpha blending
IDirect3D9* pD3D = DXUTGetD3DObject();
if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
return false;
return true;
}
//--------------------------------------------------------------------------------------
// Before a device is created, modify the device settings as needed
//--------------------------------------------------------------------------------------
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext )
{
return true;
}
//--------------------------------------------------------------------------------------
// Create any D3DPOOL_MANAGED resources here
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
float width = (float)pBackBufferSurfaceDesc->Width;
float height= (float)pBackBufferSurfaceDesc->Height;
g_pGame = new CGame(pd3dDevice, width, height);
return S_OK;
}
//--------------------------------------------------------------------------------------
// Create any D3DPOOL_DEFAULT resources here
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice,
const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
g_pGame->OnResetDevice();
return S_OK;
}
//--------------------------------------------------------------------------------------
// Handle updates to the scene
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
g_pGame->OnFrameMove(fElapsedTime);
}
//--------------------------------------------------------------------------------------
// Render the scene
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
HRESULT hr;
// Clear the render target and the zbuffer
V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0) );
// Render the scene
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
V( g_pGame->OnFrameRender(pd3dDevice) );
V( pd3dDevice->EndScene() );
}
}
//--------------------------------------------------------------------------------------
// Handle messages to the application
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
bool* pbNoFurtherProcessing, void* pUserContext )
{
/*
*pbNoFurtherProcessing = g_UI.MsgProc( hWnd, uMsg, wParam, lParam );
if( *pbNoFurtherProcessing )
return 0;
*pbNoFurtherProcessing = g_NextLevelButton.MsgProc( hWnd, uMsg, wParam, lParam );
if( *pbNoFurtherProcessing )
return 0;
*/
switch(uMsg)
{
case WM_GRAPHNOTIFY: // event by mp3player
HandleGraphEvent();
break;
case WM_MOUSEMOVE:
g_pGame->MouseEvent(LOWORD(lParam), HIWORD(lParam), false, false, 0, true);
break;
}
return 0;
}
//--------------------------------------------------------------------------------------
// Release resources created in the OnResetDevice callback here
//--------------------------------------------------------------------------------------
void CALLBACK OnLostDevice( void* pUserContext )
{
g_pGame->OnLostDevice();
}
//--------------------------------------------------------------------------------------
// Release resources created in the OnCreateDevice callback here
//--------------------------------------------------------------------------------------
void CALLBACK OnDestroyDevice( void* pUserContext )
{
SAFE_DELETE(g_pGame);
}
//--------------------------------------------------------------------------------------
// Keyboard Event handler
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
{
/*
WCHAR wszInput[9];
UINT pw;
switch(nControlID)
{
case IDC_LOADPASSWORD:
g_UI.GetEditBox( IDC_PASSWORDENTRY )->GetTextCopy(wszInput, 9);
char rawr[9];
WCharStringToCharString(wszInput, rawr, 9);
pw = static_cast<int>(strtol(rawr, NULL, 16));
if(g_pJunkie->LoadPassword(pw))
g_UI.GetEditBox( IDC_PASSWORDENTRY )->SetText(L"LEVEL LOADED");
else
g_UI.GetEditBox( IDC_PASSWORDENTRY )->SetText(L"Password Failed!");
break;
case IDC_LOADNEXTLEVEL:
g_bDisplayNextLevelOption = false;
g_pJunkie->LoadNextLevel();
break;
}
*/
}
//--------------------------------------------------------------------------------------
// Keyboard Event handler
//--------------------------------------------------------------------------------------
void CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext )
{
g_pGame->KeyboardEvent(nChar, bKeyDown);
}
//--------------------------------------------------------------------------------------
// Mouse Event Handler
//--------------------------------------------------------------------------------------
void CALLBACK MouseProc(bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown,
bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta,
int xPos, int yPos, void* pUserContext)
{
g_pGame->MouseEvent(xPos, yPos, bLeftButtonDown, bRightButtonDown, nMouseWheelDelta, false);
}
//--------------------------------------------------------------------------------------
// Initialize everything and go into a render loop
//--------------------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
// Set the callback functions
DXUTSetCallbackDeviceCreated( OnCreateDevice );
DXUTSetCallbackDeviceReset( OnResetDevice );
DXUTSetCallbackDeviceLost( OnLostDevice );
DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
DXUTSetCallbackMsgProc( MsgProc );
DXUTSetCallbackKeyboard( KeyboardProc );
DXUTSetCallbackMouse( MouseProc );
DXUTSetCallbackFrameRender( OnFrameRender );
DXUTSetCallbackFrameMove( OnFrameMove );
// Initialize DXUT and create the desired Win32 window and Direct3D device for the application
DXUTInit( true, false, true ); // Parse the command line, handle the default hotkeys, and show msgboxes
DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen
DXUTCreateWindow( L"Globalization" );
DXUTCreateDevice( D3DADAPTER_DEFAULT, true, 1024, 768, IsDeviceAcceptable, ModifyDeviceSettings );
InitApp();
// Start the render loop
DXUTMainLoop();
CleanupApp();
#if defined(DEBUG) || defined(_DEBUG)
// Functions to pinpoint memory leaks
// _CrtDumpMemoryLeaks ();
_CrtCheckMemory();
#endif
return DXUTGetExitCode();
}