1 //-----------------------------------------------------------------------------
2 // File: XBApp.h
3 //
4 // Desc: Application class for the XBox samples.
5 //
6 // Hist: 11.01.00 - New for November XDK release
7 //       12.15.00 - Changes for December XDK release
8 //       02.19.01 - Changes for March XDK release
9 //
10 // Copyright (c) Microsoft Corporation. All rights reserved.
11 //-----------------------------------------------------------------------------
12 #ifndef XBAPP_H
13 #define XBAPP_H
14 
15 #include <xtl.h>
16 #include <xgraphics.h>
17 #include <stdio.h>
18 #include "XBInput.h"
19 #include "XBUtil.h"
20 
21 
22 
23 
24 //-----------------------------------------------------------------------------
25 // Global access to common members
26 //-----------------------------------------------------------------------------
27 extern LPDIRECT3DDEVICE8 g_pd3dDevice;
28 
29 
30 
31 
32 //-----------------------------------------------------------------------------
33 // Error codes
34 //-----------------------------------------------------------------------------
35 #define XBAPPERR_MEDIANOTFOUND       0x82000003
36 
37 
38 
39 
40 //-----------------------------------------------------------------------------
41 // Name: class CXBApplication
42 // Desc: A base class for creating sample Xbox applications. To create a simple
43 //       Xbox application, simply derive this class and override the following
44 //       functions:
45 //          Initialize()          - To initialize the device-dependant objects
46 //          FrameMove()           - To animate the scene
47 //          Render()              - To render the scene
48 //-----------------------------------------------------------------------------
49 class CXBApplication
50 {
51 public:
52 	D3DPRESENT_PARAMETERS m_d3dpp;
53 	LPDIRECT3DDEVICE8     m_pd3dDevice;        // The D3D rendering device
54 	LPDIRECT3D8           m_pD3D;              // The D3D enumerator object
55 protected:
56 	// Main objects used for creating and rendering the 3D scene
57 	LPDIRECT3DSURFACE8    m_pBackBuffer;       // The back buffer
58 	LPDIRECT3DSURFACE8    m_pDepthBuffer;      // The depth buffer
59 
60 	// Variables for timing
61 	FLOAT      m_fTime;             // Current absolute time in seconds
62 	FLOAT      m_fElapsedTime;      // Elapsed absolute time since last frame
63 	FLOAT      m_fAppTime;          // Current app time in seconds
64 	FLOAT      m_fElapsedAppTime;   // Elapsed app time since last frame
65 	BOOL       m_bPaused;           // Whether app time is paused by user
66 	FLOAT      m_fFPS;              // instantaneous frame rate
67 	WCHAR      m_strFrameRate[20];  // Frame rate written to a string
68 	HANDLE     m_hFrameCounter;     // Handle to frame rate perf counter
69 
70 	// Members to init the XINPUT devices.
71 	XDEVICE_PREALLOC_TYPE* m_InputDeviceTypes;
72 	DWORD                  m_dwNumInputDeviceTypes;
73 	XBGAMEPAD*             m_Gamepad;
74 	XBGAMEPAD              m_DefaultGamepad;
75 
76 	// Helper functions
77 
78 	// Overridable functions for the 3D scene created by the app
Initialize()79 	virtual HRESULT Initialize()            { return S_OK; }
FrameMove()80 	virtual HRESULT FrameMove()             { return S_OK; }
Render()81 	virtual HRESULT Render()                { return S_OK; }
Cleanup()82 	virtual HRESULT Cleanup()               { return S_OK; }
83 	HRESULT RenderGradientBackground( DWORD dwTopColor, DWORD dwBottomColor );
84 
85 public:
86 	// Functions to create, run, and clean up the application
87 	HRESULT Create();
88 	INT     Run();
89 	VOID    Destroy();
90 
91 	// Internal constructor
92 	CXBApplication();
93 };
94 
95 
96 
97 
98 #endif
99