-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.hpp
168 lines (148 loc) · 3.83 KB
/
game.hpp
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
#ifndef _GAME_HPP_
#define _GAME_HPP_
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "chunkindex.hpp"
#include "sprite.hpp"
#include "util.hpp"
#include "camera.hpp"
#include <GLFW/glfw3.h>
#include <vector>
#include <string>
#ifdef WIN32
#include <DirectXMath.h>
extern ID3D11ShaderResourceView* g_helpinfo_srv11;
#endif
#undef max
#undef min
//
class Particles {
public:
Particles();
void SpawnDefaultSprite(const glm::vec3& pos, float lifetime, float v0);
void Spawn(ChunkIndex* src, const glm::vec3& pos, float lifetime, float v0);
struct State {
ChunkSprite* sprite;
float lifetime, lifetime_full;
};
std::vector<State> particles;
void Update(float secs);
static void InitStatic(ChunkIndex* x);
static ChunkIndex* default_particle;
void DeleteAll();
};
class MainMenu {
public:
enum MenuKind {
MAIN = 0,
HELP = 1,
OPTIONS = 2,
EDIT_MODE = 3,
LEVEL_SELECT,
};
enum class MenuItemType {
Text,
Selectable,
Toggle
};
class MenuItem {
public:
MenuItemType type;
std::wstring text;
std::vector<std::wstring> choices;
int choice_idx;
enum ValueType {
ValueTypeBool,
ValueTypeInt,
};
ValueType valuetype;
typedef union {
int asInt;
bool asBool;
} MenuChoiceValue ;
std::vector<MenuChoiceValue> values;
union {
bool* pBool;
int* pInt;
} ptr;
MenuItem(const wchar_t* _text) {
type = MenuItemType::Selectable;
text = _text;
choice_idx = 0;
}
std::wstring GetTextForDisplay() {
std::wstring ret = text;
if (type == MenuItemType::Toggle) {
if (choices.empty()) { }
else ret = ret + L" <" + choices[choice_idx] + L">";
}
return ret;
}
};
MainMenu();
MenuItem GetMenuItem(const char*);
std::vector<std::wstring> menutitle;
std::vector<MenuItem> menuitems;
std::vector<ImageSprite2D*> keys_sprites;
void Render(const glm::mat4& uitransform);
void Render_D3D11(const glm::mat4& uitransform);
void Render_D3D12(const glm::mat4& uitransform);
void OnUpDownPressed(int delta); // -1: up; +1: down
void OnLeftRightPressed(int delta); // -1: left; +1: right
void OnEscPressed();
void OnEnter();
void EnterMenu(const MenuKind idx, bool is_from_exit);
void ExitMenu();
bool IsInHelp() { return is_in_help; }
void DrawHelpScreen();
void PrintStatus();
Camera* cam_helpinfo;
FullScreenQuad* fsquad;
// Dynamic Sprites in Help Screen
std::vector<Sprite*> sprites_helpinfo;
#ifdef WIN32
std::vector<D3D11_VIEWPORT> viewports11_helpinfo;
D3D11_VIEWPORT viewport_vollight;
#endif
float secs_elapsed;
void PrepareLightsForGoalDemo();
void RenderLightsForGoalDemo();
DirectionalLight* lights[3];
std::vector<int> curr_selection;
std::vector<MenuKind> curr_menu;
bool is_in_help;
unsigned fade_millis0, fade_millis1, fade_millis;
float fade_alpha0, fade_alpha1, fade_alpha;
static int FADE_DURATION;
void FadeInHelpScreen();
void FadeOutHelpScreen();
void Update(float delta_secs);
static void InitStatic(unsigned p) { program = p; }
static unsigned program;
private:
void do_Render(GraphicsAPI api, const glm::mat4& uitransform);
};
class TextMessage {
public:
std::vector<std::wstring> messages;
unsigned millis_expire;
TextMessage() { millis_expire = 0; }
void SetMessage(const std::wstring& _msg, float seconds) {
unsigned elapsed = GetElapsedMillis();
millis_expire = (elapsed + seconds * 1000);
messages.clear();
messages.push_back(_msg);
}
void AppendLine(const std::wstring& _msg) {
messages.push_back(_msg);
}
bool IsExpired() {
int x = int(GetElapsedMillis());
return x >= millis_expire;
}
void Render(GraphicsAPI api);
static void InitStatic(unsigned p) { program = p; }
static unsigned program;
};
#endif