Repository navigation
Expand file tree
/
Copy pathGame.h
More file actions
145 lines (129 loc) · 3.06 KB
/
Copy pathGame.h
File metadata and controls
145 lines (129 loc) · 3.06 KB
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
#pragma once
#include "Common.h"
#include "GameWindow.h"
class CCamera;
class CSkybox;
class CShader;
class CShaderProgram;
class CPlane;
class CFreeTypeFont;
class CHighResolutionTimer;
class COpenAssetImportMesh;
class CAudio;
class CSplineTrack;
class CPrimitiveMeshes;
class CFrameBufferObject;
class Game
{
private:
enum CameraMode
{
CAMERA_FREE = 0,
CAMERA_CHASE,
CAMERA_COCKPIT,
CAMERA_FOLLOW
};
enum TrackObjectType
{
OBJECT_HAZARD = 0,
OBJECT_PICKUP,
OBJECT_ROADSIDE
};
// Runtime state for the player and score systems that change every frame.
struct CarState
{
float progress;
float speed;
float laneOffset;
int lane;
float health;
int score;
float boostMeter;
bool isBoosting;
int comboMultiplier;
float comboTimer;
bool finished;
bool crashed;
};
// Route-space object definition: progress selects where it sits on the loop and lane picks
// which side of the centreline it occupies.
struct TrackObject
{
TrackObjectType type;
float progress;
int lane;
bool active;
float value;
float timer;
};
// Small key latches stop toggle inputs from firing every frame while a key is held down.
struct InputLatch
{
bool laneLeft;
bool laneRight;
bool toggleCamera;
bool toggleFree;
bool toggleFollow;
bool togglePostFx;
bool restart;
};
void Initialise();
void Update();
void Render();
void ResetGameState();
void BuildTrackObjects();
void UpdateGameplay(float dtSeconds);
void UpdateCamera(float dtSeconds);
void UpdateInput(float dtSeconds);
void RenderWorldScene();
void RenderPostProcess();
bool CreatePostProcessResources(int width, int height);
void ReleasePostProcessResources();
void RenderHUD();
bool ConsumeKeyPress(int virtualKey, bool& latch);
void SetMaterial(CShaderProgram* program, const glm::vec3& ambient, const glm::vec3& diffuse, const glm::vec3& specular, float shininess);
void SetMatrices(CShaderProgram* program, const glm::mat4& viewMatrix, const glm::mat4& modelMatrix);
CSkybox* m_pSkybox;
CCamera* m_pCamera;
vector<CShaderProgram*>* m_pShaderPrograms;
CPlane* m_pGroundPlane;
CFreeTypeFont* m_pFtFont;
COpenAssetImportMesh* m_pCarMesh;
CHighResolutionTimer* m_pHighResolutionTimer;
CAudio* m_pAudio;
CSplineTrack* m_pTrack;
CPrimitiveMeshes* m_pPrimitiveMeshes;
CFrameBufferObject* m_pSceneFBO;
UINT m_postProcessVAO;
UINT m_postProcessVBO;
bool m_postFxEnabled;
bool m_postFxReady;
double m_dt;
int m_framesPerSecond;
bool m_appActive;
CarState m_carState;
vector<TrackObject> m_trackObjects;
InputLatch m_inputLatch;
CameraMode m_cameraMode;
CameraMode m_lastRideCameraMode;
glm::vec3 m_carPosition;
glm::vec3 m_carForward;
glm::vec3 m_carRight;
glm::vec3 m_carUp;
float m_worldTime;
public:
Game();
~Game();
static Game& GetInstance();
LRESULT ProcessEvents(HWND window, UINT message, WPARAM w_param, LPARAM l_param);
void SetHinstance(HINSTANCE hinstance);
WPARAM Execute();
private:
static const int FPS = 60;
void DisplayFrameRate();
void GameLoop();
GameWindow m_gameWindow;
HINSTANCE m_hInstance;
int m_frameCount;
double m_elapsedTime;
};