-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDark.cpp
329 lines (206 loc) · 4.46 KB
/
Dark.cpp
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// --- * --- * ---
// DARKAGE
// Comin at cha
//
// LIBRE SOFTWARE
// Licensed under GNU GPL3
// be a bro and inherit
//
// CONTRIBUTORS
// lyeb,
// --- * --- * ---
// deps
#include "chasm/Chasm.hpp"
#include "sin/Sin.hpp"
#include "DA_Default.hpp"
#include "Dark.hpp"
// --- * --- * ---
// cstruc
DARK::DARK(void) {
this->keyset = DA_Default::keys;
this->programs = DA_Default::programs;
};
// --- * --- * ---
// get program clock
Clock& DARK::get_clock(void) {
auto& Chasm=CHASM::ice();
return Chasm.win.clock();
};
// --- * --- * ---
// sin wrapper
//
// compiles params listed
// under this->programs
void DARK::load_shaders(void) {
// auto& Sin=SIN::ice();
// Sin.nit_programs(this->programs);
};
// --- * --- * ---
// creates window accto this->screen
void DARK::spawn_window(
std::string name
) {
auto& Chasm=CHASM::ice();
Win::Desc win_desc={
.title = name,
.width = this->screen.size.x,
.height = this->screen.size.y,
.fullscreen = this->screen.full,
.fps = this->fps,
.flags = this->screen.wflags
};
Chasm.nit(win_desc,this->keyset);
Chasm.win.set_ambient_color(8);
// set loop routines
Chasm.draw = DARK::draw;
Chasm.logic = DARK::logic;
// compile *.sg
this->load_shaders();
};
// --- * --- * ---
// creates camera accto this->screen
void DARK::spawn_camera(
const vec3& pos,
const quat& rot,
bool ortho
) {
auto& Sin = SIN::ice();
uint32_t ubo = Sin.program->get_ubo(0);
Camera::Lens lens={
.width = float(this->screen.size.x),
.height = float(this->screen.size.y),
.scale = this->screen.scale,
.fov = this->screen.fov,
.near = this->screen.znear,
.far = this->screen.zfar
};
cam.nit(pos,rot,lens,ubo);
if(ortho) {
cam.use_ortho();
} else {
cam.use_persp();
};
cam.get_view();
};
// --- * --- * ---
// create spacepart
void DARK::spawn_world(void) {
uvec3 dim {1,1,1};
world.nit(dim);
};
// --- * --- * ---
// push entity onto world
Node& DARK::spawn_object(
uint32_t meshid,
uint8_t type,
T3D xform
) {
auto& Sin = SIN::ice();
uint32_t mesh = Sin.sprites.size();
Sin.sprites.push_back(
Sin.batch->ice_asset(meshid)
);
Node::Bld bld={
.draw={
.batch = Sin.batch_id,
.mesh = mesh,
.type = type
},
.xform=xform
};
return world.push_node(bld);
};
// --- * --- * ---
// runs application
void DARK::loop(void) {
auto& Chasm = CHASM::ice();
auto& Sin = SIN::ice();
Sin.unbind_batch();
CHASM_RUN(
(void*) &this->draw_data,
(void*) &this->logic_data
);
};
// --- * --- * ---
// draw prologue
void DARK::draw_prologue(void) {
this->cam.get_view();
this->cam.get_visible();
};
// --- * --- * ---
// ^epilogue
void DARK::draw_epilogue(void) {
auto& Sin=SIN::ice();
Sin.draw_enqueued();
this->draw_ui();
};
// --- * --- * ---
// default drawing routine
int DARK::defdraw(void* data) {
auto& Sin = SIN::ice();
auto bat = (Nodes*) data;
// walk objects
for(auto& node : *bat) {
node.draw();
};
return bat->size();
};
// --- * --- * ---
// ^wrapper
int DARK::draw(void* data) {
auto& Dark=DARK::ice();
Dark.draw_prologue();
int out=Dark.draw_f(data);
Dark.draw_epilogue();
return out;
};
// --- * --- * ---
// draw step for ui panels
void DARK::draw_ui(void) {
for(auto& ref : m_ui) {
auto& panel=ref.get();
if(panel.enabled()) {
panel.draw();
};
};
};
// --- * --- * ---
// ^TODO: same Fs for logic
void DARK::logic_prologue(void) {};
void DARK::logic_epilogue(void) {
this->logic_ui();
};
int DARK::deflogic(void* data) {
return 1;
};
// --- * --- * ---
// ^wrapper
int DARK::logic(void* data) {
auto& Dark=DARK::ice();
Dark.logic_prologue();
int out=Dark.logic_f(data);
Dark.logic_epilogue();
return out;
};
// --- * --- * ---
// logic step for ui panels
void DARK::logic_ui(void) {
for(auto& ref : m_ui) {
auto& panel=ref.get();
if(panel.enabled()) {
panel.update();
};
};
};
// --- * --- * ---
// ui control
void DARK::register_panel(UI_Panel& panel) {
m_ui.push_back(panel);
};
// --- * --- * ---
// get user-controlled node
Node& DARK::player(void) {
auto& Dark=DARK::ice();
return Dark.cam;
};
// --- * --- * ---