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
|
#include "app.h"
#include "physics.h"
#include "res.h"
#include "ent.h"
#include "game.h"
#include "env.h"
#include "cam.h"
#include "editor.h"
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
App app = {0};
u64 dude_id = ENTITY_INVALID_IDX;
u64 car_id = ENTITY_INVALID_IDX;
static void
app_init(void) {
SetTraceLogLevel(LOG_WARNING);
SetConfigFlags(FLAG_MSAA_4X_HINT |
FLAG_VSYNC_HINT |
FLAG_WINDOW_RESIZABLE);
InitWindow(1280, 720, "Fun Game");
SetExitKey(KEY_NULL);
SetTargetFPS(60);
app.run = true;
FLAG_SET(app.flags, BIT(APP_FLAG_EDIT));
FLAG_SET(app.flags, BIT(APP_FLAG_DEBUG));
physics_init();
res_init();
env_init();
entity_system_init();
game_init();
editor_init();
cam_init();
// for (int i = 0; i < 10000; ++i) {
// u64 id = entity_create(false);
// Entity *ent = entity_get(id);
// char name[16];
// snprintf(name, 16, "Entity %i", i);
// free(ent->name);
// ent->name = strdup(name);
// ent->tr.pos = (Vec3){
// GetRandomValue(-50, 50),
// GetRandomValue(-10, 10),
// GetRandomValue(-50, 50),
// };
// }
// for (int i = 0; i < entity_count(); ++i) {
// u64 id = entity_id_at(i);
// if (i == 5) {
// u64 parent_id = entity_id_at(4);
// entity_set_parent(id, parent_id);
// }
// if (i == 10) {
// entity_delete(id);
// }
// }
}
static void
app_exit(void) {
editor_exit();
game_exit();
entity_system_exit();
env_exit();
res_exit();
physics_exit();
}
static void
app_loop(void) {
app.run = !WindowShouldClose();
/* this is some hypothetical bullshit, probably will change */
if (app.mode != APP_MODE_PLAY) {
editor_update();
}
physics_update();
res_update();
env_update();
entity_system_update();
BeginDrawing();
ClearBackground(RAYWHITE);
env_draw_sky(main_cam.cam);
BeginMode3D(main_cam.cam);
entity_system_draw_3d();
// delete this shit later
for (u32 i = 0; i < entity_count(); ++i) {
Matrix world = entity_world_matrix(entity_id_at(i));
rlPushMatrix();
rlMultMatrixf(MatrixToFloatV(world).v);
DrawCubeWiresV(Vector3Zero(), Vector3One(), GREEN);
rlPopMatrix();
}
EndMode3D();
if (FLAG_CHECK(app.flags, BIT(APP_FLAG_DEBUG)) ||
FLAG_CHECK(app.flags, BIT(APP_FLAG_EDIT))) {
BeginMode3D(main_cam.cam);
rlDisableDepthTest();
editor_draw_3d();
EndMode3D();
}
editor_draw_ui();
EndDrawing();
}
int
main(void) {
app_init();
while (app.run) {
app_loop();
}
app_exit();
return 0;
}
|