-
Notifications
You must be signed in to change notification settings - Fork 3
/
Game.h
235 lines (186 loc) · 8.03 KB
/
Game.h
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
//--------------------------------------------------------------------------------------
// File: Game.cpp
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//--------------------------------------------------------------------------------------
#pragma once
#include "StepTimer.h"
#include "ArcBall.h"
#include "RenderTexture.h"
#ifdef _GAMING_XBOX
#define XBOX
#include "DeviceResourcesGXDK.h"
#elif defined(_XBOX_ONE) && defined(_TITLE)
#define XBOX
#define COREWINDOW
#include "DeviceResourcesXDK.h"
#else
#define PC
#define LOSTDEVICE
#include "DeviceResourcesPC.h"
#endif
// A basic game implementation that creates a D3D12 device and
// provides a game loop.
class Game
#ifdef LOSTDEVICE
final : public DX::IDeviceNotify
#endif
{
public:
Game() noexcept(false);
~Game();
Game(Game&&) = default;
Game& operator= (Game&&) = default;
Game(Game const&) = delete;
Game& operator= (Game const&) = delete;
// Initialization and management
#ifdef COREWINDOW
void Initialize(IUnknown* window);
#elif defined(XBOX)
void Initialize(HWND window);
#else
void Initialize(HWND window, int width, int height);
#endif
// Basic game loop
void Tick();
#ifdef LOSTDEVICE
// IDeviceNotify
void OnDeviceLost() override;
void OnDeviceRestored() override;
#endif
// Messages
void OnActivated();
void OnDeactivated() {}
void OnSuspending();
void OnResuming();
void OnFileOpen(const wchar_t* filename);
#ifdef PC
void OnWindowMoved();
void OnDisplayChange();
void OnWindowSizeChanged(int width, int height);
#endif
// Properties
void GetDefaultSize( int& width, int& height ) const noexcept;
bool RequestHDRMode() const noexcept { return m_deviceResources ? (m_deviceResources->GetDeviceOptions() & DX::DeviceResources::c_EnableHDR) != 0 : false; }
static void SetRender4K() noexcept { s_render4k = true; }
private:
void Update(DX::StepTimer const& timer);
void Render();
void Clear();
void CreateDeviceDependentResources();
void CreateWindowSizeDependentResources();
void LoadModel();
void DrawGrid(ID3D12GraphicsCommandList *commandList);
void DrawCross(ID3D12GraphicsCommandList *commandList);
void CameraHome();
void CycleBackgroundColor();
void CycleToneMapOperator();
void CycleBoneRenderMode();
void CreateProjection();
void RotateView(DirectX::SimpleMath::Quaternion& q);
#ifdef XBOX
void EnumerateModelFiles();
#endif
// Device resources.
std::unique_ptr<DX::DeviceResources> m_deviceResources;
std::unique_ptr<DX::RenderTexture> m_hdrScene;
// Rendering loop timer.
DX::StepTimer m_timer;
std::unique_ptr<DirectX::GraphicsMemory> m_graphicsMemory;
std::unique_ptr<DirectX::DescriptorPile> m_resourceDescriptors;
std::unique_ptr<DirectX::DescriptorHeap> m_renderDescriptors;
std::unique_ptr<DirectX::CommonStates> m_states;
std::unique_ptr<DirectX::BasicEffect> m_lineEffect;
std::unique_ptr<DirectX::PrimitiveBatch<DirectX::VertexPositionColor>> m_lineBatch;
std::unique_ptr<DirectX::ToneMapPostProcess> m_toneMapSaturate;
std::unique_ptr<DirectX::ToneMapPostProcess> m_toneMapReinhard;
std::unique_ptr<DirectX::ToneMapPostProcess> m_toneMapACESFilmic;
#ifdef PC
std::unique_ptr<DirectX::ToneMapPostProcess> m_toneMapLinear;
std::unique_ptr<DirectX::ToneMapPostProcess> m_toneMapHDR10;
#endif
std::unique_ptr<DirectX::EffectFactory> m_fxFactory;
std::unique_ptr<DirectX::PBREffectFactory> m_pbrFXFactory;
std::unique_ptr<DirectX::EffectTextureFactory> m_modelResources;
std::unique_ptr<DirectX::Model> m_model;
std::vector<std::shared_ptr<DirectX::IEffect>> m_modelClockwise;
std::vector<std::shared_ptr<DirectX::IEffect>> m_modelCounterClockwise;
std::vector<std::shared_ptr<DirectX::IEffect>> m_modelWireframe;
std::vector<std::shared_ptr<DirectX::IEffect>> m_unlitWireframe;
std::vector<std::shared_ptr<DirectX::IEffect>> m_unlitClockwise;
std::vector<std::shared_ptr<DirectX::IEffect>> m_unlitCounterClockwise;
DirectX::ModelBone::TransformArray m_bones;
std::unique_ptr<DirectX::SpriteBatch> m_spriteBatch;
std::unique_ptr<DirectX::SpriteFont> m_fontConsolas;
std::unique_ptr<DirectX::SpriteFont> m_fontComic;
static constexpr size_t s_nIBL = 3;
Microsoft::WRL::ComPtr<ID3D12Resource> m_radianceIBL[s_nIBL];
Microsoft::WRL::ComPtr<ID3D12Resource> m_irradianceIBL[s_nIBL];
std::wstring m_defaultTextureName;
enum Descriptors : size_t
{
ConsolasFont,
ComicFont,
SceneTex,
RadianceIBL1,
RadianceIBL2,
RadianceIBL3,
IrradianceIBL1,
IrradianceIBL2,
IrradianceIBL3,
Reserve,
Count = 1024
};
enum RTVDescriptors : size_t
{
HDRScene,
RTVCount
};
std::unique_ptr<DirectX::GamePad> m_gamepad;
std::unique_ptr<DirectX::Keyboard> m_keyboard;
std::unique_ptr<DirectX::Mouse> m_mouse;
DirectX::Keyboard::KeyboardStateTracker m_keyboardTracker;
DirectX::Mouse::ButtonStateTracker m_mouseButtonTracker;
DirectX::GamePad::ButtonStateTracker m_gamepadButtonTracker;
DirectX::SimpleMath::Matrix m_world;
DirectX::SimpleMath::Matrix m_view;
DirectX::SimpleMath::Matrix m_proj;
DirectX::SimpleMath::Vector3 m_cameraFocus;
DirectX::SimpleMath::Vector3 m_lastCameraPos;
DirectX::SimpleMath::Quaternion m_cameraRot;
DirectX::SimpleMath::Quaternion m_viewRot;
DirectX::SimpleMath::Color m_clearColor;
DirectX::SimpleMath::Color m_uiColor;
DirectX::SimpleMath::Quaternion m_modelRot;
float m_gridScale;
float m_fov;
float m_zoom;
float m_distance;
float m_farPlane;
float m_sensitivity;
size_t m_gridDivs;
uint32_t m_ibl;
bool m_showHud;
bool m_showCross;
bool m_showGrid;
bool m_usingGamepad;
bool m_wireframe;
bool m_ccw;
bool m_lighting;
bool m_reloadModel;
bool m_lhcoords;
bool m_fpscamera;
bool m_boneMode;
bool m_skinning;
int m_toneMapMode;
wchar_t m_szModelName[MAX_PATH];
wchar_t m_szStatus[512];
wchar_t m_szError[512];
ArcBall m_ballCamera;
ArcBall m_ballModel;
int m_selectFile;
int m_firstFile;
std::vector<std::wstring> m_fileNames;
static bool s_render4k;
};