source: GTP/trunk/App/Games/Jungle_Rumble/src/WuermerDX9.cpp @ 1384

Revision 1384, 13.9 KB checked in by giegl, 18 years ago (diff)

<cubemapsize>GTPD - Jungle Rumble - <cubemapsize> config setting

Line 
1#include "dxstdafx.h"
2#include "resource.h"
3#include "GameManager.h"
4#include "fmod.h"
5#import <msxml.dll> named_guids
6
7// Global Variables
8CDXUTDialogResourceManager DialogResourceManager;
9CDXUTDialog GUI;
10GameManager manager;
11bool firstFrame;
12bool secondFrame;
13bool usePhysXDebug;
14MSXML::IXMLDOMDocumentPtr configDomDocument;
15MSXML::IXMLDOMElementPtr  configDocRoot;
16int width;
17int height;
18
19
20//--------------------------------------------------------------------------------------
21// Rejects any devices that aren't acceptable by returning false
22//--------------------------------------------------------------------------------------
23bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext )
24{
25    // Skip backbuffer formats that don't support alpha blending
26    IDirect3D9* pD3D = DXUTGetD3DObject();
27    if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
28                    AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
29                    D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
30        return false;
31
32    // Must support cube textures
33    if( !( pCaps->TextureCaps & D3DPTEXTURECAPS_CUBEMAP ) )
34        return false;
35
36    // Must support pixel shader 3.0
37    if( pCaps->PixelShaderVersion < D3DPS_VERSION( 3, 0 ) )
38        return false;
39
40    // need to support D3DFMT_A32B32G32R32F render target
41    if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
42                    AdapterFormat, D3DUSAGE_RENDERTARGET,
43                    D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F ) ) )
44                return false;
45       
46        // Verify that the depth format exists
47    HRESULT hr = pD3D->CheckDeviceFormat(pCaps->AdapterOrdinal,
48                                         pCaps->DeviceType,
49                                         AdapterFormat,
50                                         D3DUSAGE_DEPTHSTENCIL,
51                                         D3DRTYPE_SURFACE,
52                                         D3DFMT_D16);
53   
54    if(FAILED(hr)) return FALSE;
55   
56    // Verify that the depth format is compatible
57    hr = pD3D->CheckDepthStencilMatch(pCaps->AdapterOrdinal,
58                                      pCaps->DeviceType,
59                                      AdapterFormat,
60                                      BackBufferFormat,
61                                      D3DFMT_D16);
62        if(FAILED(hr)) return false;
63
64    return true;
65}
66
67
68//--------------------------------------------------------------------------------------
69// Before a device is created, modify the device settings as needed
70//--------------------------------------------------------------------------------------
71bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext )
72{
73    // If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW then switch to SWVP.
74    if( (pCaps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||
75         pCaps->VertexShaderVersion < D3DVS_VERSION(1,1) )
76    {
77        pDeviceSettings->BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
78    }
79    else
80    {
81        pDeviceSettings->BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
82    }
83
84    // This application is designed to work on a pure device by not using
85    // IDirect3D9::Get*() methods, so create a pure device if supported and using HWVP.
86    if ((pCaps->DevCaps & D3DDEVCAPS_PUREDEVICE) != 0 &&
87        (pDeviceSettings->BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING) != 0 )
88        pDeviceSettings->BehaviorFlags |= D3DCREATE_PUREDEVICE;
89
90    // Debugging vertex shaders requires either REF or software vertex processing
91    // and debugging pixel shaders requires REF. 
92#ifdef DEBUG_VS
93    if( pDeviceSettings->DeviceType != D3DDEVTYPE_REF )
94    {
95        pDeviceSettings->BehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
96        pDeviceSettings->BehaviorFlags &= ~D3DCREATE_PUREDEVICE;
97        pDeviceSettings->BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
98    }
99#endif
100#ifdef DEBUG_PS
101    pDeviceSettings->DeviceType = D3DDEVTYPE_REF;
102#endif 
103
104       
105
106
107        return true;
108}
109
110
111//--------------------------------------------------------------------------------------
112// Create any D3DPOOL_MANAGED resources here
113//--------------------------------------------------------------------------------------
114HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
115{
116    //GUI Stuff:
117    manager.OnCreateDevice( pd3dDevice, pBackBufferSurfaceDesc, pUserContext );
118       
119        DialogResourceManager.OnCreateDevice(pd3dDevice);
120        return S_OK;
121}
122
123
124//--------------------------------------------------------------------------------------
125// Create any D3DPOOL_DEFAULT resources here
126//--------------------------------------------------------------------------------------
127HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice,
128                                const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
129{
130        manager.printToConsole("On Reset Device in WuermerDX9 Called!");
131        HRESULT hr = DialogResourceManager.OnResetDevice();
132        if(hr!=S_OK)
133                manager.printToConsole("Reset failed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
134        manager.OnResetDevice(pd3dDevice, pBackBufferSurfaceDesc, pUserContext);
135        return S_OK;
136}
137
138
139//--------------------------------------------------------------------------------------
140// Handle updates to the scene
141//--------------------------------------------------------------------------------------
142void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
143{
144}
145
146
147//--------------------------------------------------------------------------------------
148// Render the scene
149//--------------------------------------------------------------------------------------
150void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
151{
152        manager.updateGame(fElapsedTime);
153}
154
155
156//--------------------------------------------------------------------------------------
157// Handle messages to the application
158//--------------------------------------------------------------------------------------
159LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
160                          bool* pbNoFurtherProcessing, void* pUserContext )
161{
162    // Always allow dialog resource manager calls to handle global messages
163    // so GUI state is updated correctly
164        *pbNoFurtherProcessing = DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );
165    if( *pbNoFurtherProcessing )
166        return 0;
167
168    // Give the dialogs a chance to handle the message first
169        *pbNoFurtherProcessing = GUI.MsgProc( hWnd, uMsg, wParam, lParam );
170    if( *pbNoFurtherProcessing )
171        return 0;
172       
173    return 0;
174}
175
176
177//--------------------------------------------------------------------------------------
178// Release resources created in the OnResetDevice callback here
179//--------------------------------------------------------------------------------------
180void CALLBACK OnLostDevice( void* pUserContext )
181{
182        DialogResourceManager.OnLostDevice();
183        manager.OnLostDevice(pUserContext);
184}
185
186
187//--------------------------------------------------------------------------------------
188// Release resources created in the OnCreateDevice callback here
189//--------------------------------------------------------------------------------------
190void CALLBACK OnDestroyDevice( void* pUserContext )
191{
192        DialogResourceManager.OnDestroyDevice();
193        manager.OnDestroyDevice(pUserContext);
194}
195
196
197//--------------------------------------------------------------------------------------
198// As a convenience, DXUT inspects the incoming windows messages for
199// keystroke messages and decodes the message parameters to pass relevant keyboard
200// messages to the application.  The framework does not remove the underlying keystroke
201// messages, which are still passed to the application's MsgProc callback.
202//--------------------------------------------------------------------------------------
203void CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext )
204{
205        manager.keyPressed(nChar, bKeyDown, bAltDown, pUserContext);
206}
207
208void CALLBACK MouseCallback(bool bLeftButtonDown,  bool bRightButtonDown,bool bMiddleButtonDown,
209                            bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta,
210                            int xPos, int yPos, void* pUserContext)
211{
212        manager.setMouseStatus(bLeftButtonDown, bRightButtonDown, bMiddleButtonDown, bSideButton1Down, bSideButton2Down, nMouseWheelDelta, xPos, yPos);
213}
214
215void testfunktion() {
216}
217
218//--------------------------------------------------------------------------------------
219// Handles the GUI events
220//--------------------------------------------------------------------------------------
221void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
222{
223        manager.OnGUIEvent(nEvent, nControlID, pControl, pUserContext);
224}
225
226
227//--------------------------------------------------------------------------------------
228// Initialize everything and go into a render loop
229//--------------------------------------------------------------------------------------
230
231extern int CUBEMAP_SIZE;
232
233INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int )
234{
235    // Enable run-time memory check for debug builds.
236#if defined(DEBUG) | defined(_DEBUG)
237        _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
238       
239#endif
240
241    // Set the callback functions
242    DXUTSetCallbackDeviceCreated( OnCreateDevice );
243    DXUTSetCallbackDeviceReset( OnResetDevice );
244    DXUTSetCallbackDeviceLost( OnLostDevice );
245    DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
246        DXUTSetCallbackKeyboard( KeyboardProc );
247        DXUTSetCallbackMouse(MouseCallback,true);
248        DXUTSetCallbackMsgProc( MsgProc );
249    DXUTSetCallbackFrameRender( OnFrameRender );
250    DXUTSetCallbackFrameMove( OnFrameMove );
251
252
253    // TODO: Perform any application-level initialization here
254        manager.printToConsole("initialising game");
255
256        //Sound init
257        manager.printToConsole("initialising FMOD");
258        FSOUND_Init(44100, 32, 0);
259        FSOUND_3D_SetDistanceFactor(1.0f);
260
261        //Load Config XML
262        //XML Stuff
263        ::CoInitialize(NULL);
264
265        HRESULT hr = configDomDocument.CreateInstance(MSXML::CLSID_DOMDocument);
266        if (FAILED(hr)) {
267                manager.printToConsole("Unable to create XML instance!");
268                exit(0);
269        }
270
271        variant_t vResult;
272       
273        vResult = configDomDocument->load("./config.xml");
274        if (((bool)vResult) == TRUE) {
275                configDocRoot = configDomDocument->documentElement;
276        } else {
277                manager.printToConsole("Loading Configuration failed!");
278                exit(0);
279        }
280
281        _bstr_t tmpWidth("width");
282        _bstr_t tmpHeight("height");
283        _bstr_t tmpFullscreen("fullscreen");
284        _bstr_t tmpUsePhysX("physxdebug");
285        _bstr_t tmpChallenge("challenge");
286        _bstr_t tmpChallengeName("name");
287        _bstr_t tmpChallengeLocation("location");
288        _bstr_t tmpChallengeScreen("loadingScreen");
289
290        _bstr_t tmpCubemapSize("cubemapsize"); // MG
291       
292
293        int fullscreen;
294        for (MSXML::IXMLDOMNodePtr pChild = configDocRoot->firstChild;NULL != pChild;pChild = pChild->nextSibling) {
295                if(pChild->nodeType == MSXML::NODE_ELEMENT) {
296                        if(pChild->nodeName == tmpWidth) {
297                                width = atoi(pChild->firstChild->text);                 //Width
298                        } else if(pChild->nodeName == tmpHeight) {
299                                height = atoi(pChild->firstChild->text);                //Height
300                        } else if(pChild->nodeName == tmpFullscreen) {
301                                fullscreen = atoi(pChild->firstChild->text);    //Use Fullscreen?
302                        }
303                        else if(pChild->nodeName == tmpCubemapSize) {
304                                CUBEMAP_SIZE = atoi(pChild->firstChild->text); //Raytrace Effects Cubemap Size
305                        }
306                        else if(pChild->nodeName == tmpUsePhysX) {
307                                usePhysXDebug = (atoi(pChild->firstChild->text)==1);//Use Shader?
308                        } else if(pChild->nodeName == tmpChallenge) {           //A Challenge
309                                for(MSXML::IXMLDOMNodePtr pChallengeChild = pChild->firstChild; NULL != pChallengeChild; pChallengeChild  = pChallengeChild->nextSibling) {
310                                        if(pChallengeChild->nodeName == tmpChallengeName) {
311                                                std::string temp = pChallengeChild->firstChild->text;
312                                                manager.ms.getChallengeNameList()->push_back(temp);             //Challenge Name
313                                        } else if(pChallengeChild->nodeName == tmpChallengeLocation) {
314                                                std::string temp = pChallengeChild->firstChild->text;
315                                                manager.ms.getChallengeList()->push_back(temp);         //Challenge xml file location
316                                        } else if(pChallengeChild->nodeName == tmpChallengeScreen) {
317                                                std::string temp = pChallengeChild->firstChild->text;
318                                                manager.ms.getChallengeScreenList()->push_back(temp);           //Challenge loading screen file location
319                                        }
320                                }
321                        }
322                }
323        }
324
325        manager.gs.usePhysXDebugger = usePhysXDebug;
326
327    // Initialize DXUT and create the desired Win32 window and Direct3D device for the application
328    DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen
329
330        // init GUI:
331        GUI.Init(&DialogResourceManager);
332        GUI.SetCallback(OnGUIEvent);
333        manager.ms.setDialogResourceManager(&DialogResourceManager);
334        manager.ms.setGUI(&GUI);
335        manager.ms.initGUI();
336
337        //Setup Window
338    DXUTInit( true, false, true ); // Parse the command line, handle the default hotkeys, and show msgboxes
339        DXUTCreateWindow( L"WuermerDX9", hInstance, NULL, NULL, 0, 0 );
340    DXUTCreateDevice( D3DADAPTER_DEFAULT,
341                                                (fullscreen==0),                                                // windowed mode - set to false for full screen!
342                                                width,                                          // width
343                                                height,                                         // height
344                                                IsDeviceAcceptable,                     
345                                                ModifyDeviceSettings );
346
347       
348
349
350        // initialising game:
351        manager.setScreenDimension(width, height);
352        manager.initGame();
353        firstFrame = true;
354        secondFrame = false;
355    // Start the render loop
356    DXUTMainLoop();
357       
358    // TODO: Perform any application-level cleanup here
359        return DXUTGetExitCode();
360}
Note: See TracBrowser for help on using the repository browser.