-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDXCore.h
102 lines (81 loc) · 3.02 KB
/
DXCore.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
#pragma once
#include <Windows.h>
#include <d3d11.h>
#include <string>
#include <wrl/client.h> // Used for ComPtr - a smart pointer for COM objects
// Base DXCore holds the owning pointer to the input wrangler
#include "InputSystem.h"
// We can include the correct library files here
// instead of in Visual Studio settings if we want
#pragma comment(lib, "d3d11.lib")
class DXCore
{
public:
DXCore(
HINSTANCE hInstance, // The application's handle
const char* titleBarText, // Text for the window's title bar
unsigned int windowWidth, // Width of the window's client area
unsigned int windowHeight, // Height of the window's client area
bool debugTitleBarStats); // Show extra stats (fps) in title bar?
~DXCore();
// Static requirements for OS-level message processing
static DXCore* DXCoreInstance;
static LRESULT CALLBACK WindowProc(
HWND hWnd, // Window handle
UINT uMsg, // Message
WPARAM wParam, // Message's first parameter
LPARAM lParam // Message's second parameter
);
// Internal method for message handling
LRESULT ProcessMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// Initialization and game-loop related methods
HRESULT InitWindow();
HRESULT InitDirectX();
HRESULT Run();
void Quit();
virtual void OnResize();
// Pure virtual methods for setup and game functionality
virtual void Init() = 0;
virtual void Update(float deltaTime, float totalTime) = 0;
virtual void Draw(float deltaTime, float totalTime) = 0;
protected:
HINSTANCE hInstance; // The handle to the application
HWND hWnd; // The handle to the window itself
std::string titleBarText; // Custom text in window's title bar
bool titleBarStats; // Show extra stats in title bar?
// Size of the window's client area
unsigned int width;
unsigned int height;
// Does our window currently have focus?
// Helpful if we want to pause while not the active window
bool hasFocus;
// DirectX related objects and variables
D3D_FEATURE_LEVEL dxFeatureLevel;
Microsoft::WRL::ComPtr<IDXGISwapChain> swapChain;
Microsoft::WRL::ComPtr<ID3D11Device> device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> context;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> backBufferRTV;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> depthStencilView;
// Helper function for allocating a console window
void CreateConsoleWindow(int bufferLines, int bufferColumns, int windowLines, int windowColumns);
// Helpers for determining the actual path to the executable
std::string GetExePath();
std::wstring GetExePath_Wide();
std::string GetFullPathTo(std::string relativeFilePath);
std::wstring GetFullPathTo_Wide(std::wstring relativeFilePath);
// Input System
Input::InputSystem* inputSystem;
private:
// Timing related data
double perfCounterSeconds;
float totalTime;
float deltaTime;
__int64 startTime;
__int64 currentTime;
__int64 previousTime;
// FPS calculation
int fpsFrameCount;
float fpsTimeElapsed;
void UpdateTimer(); // Updates the timer for this frame
void UpdateTitleBarStats(); // Puts debug info in the title bar
};