techkaczynski.dev / code

summaryrefslogtreecommitdiff
path: root/app.c
blob: 18f0d9ce9a3e892c8440f783b999f425b481e3f4 (plain)
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
#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};

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();
}

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();
	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;
}