aboutsummaryrefslogtreecommitdiff
path: root/all.h
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-04-30 19:19:27 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-04-30 19:44:07 +0200
commitb4d0ad9e95226d225d5361b1182866884aaa6366 (patch)
tree5440b34d97e89a08fc01abd49bb80e5b50dda945 /all.h
parentddde2e8fdf05efac5914ca2b812b7762b78ba9ec (diff)
downloadstalag-b4d0ad9e95226d225d5361b1182866884aaa6366.tar.gz
Structural refactor
Diffstat (limited to 'all.h')
-rw-r--r--all.h161
1 files changed, 85 insertions, 76 deletions
diff --git a/all.h b/all.h
index 59bdd32..26ccffb 100644
--- a/all.h
+++ b/all.h
@@ -15,134 +15,143 @@
15#include <stdbool.h> 15#include <stdbool.h>
16#include <stddef.h> 16#include <stddef.h>
17 17
18// --- Map Structures --- 18#ifndef PLAYER_FOV
19#define PLAYER_FOV 90.0f
20#endif
19 21
20typedef struct { 22typedef struct {
21 Vector3 p[3]; 23 Vector3 p[3];
22 char texture[64]; 24 char texture[64];
23 float shift[2]; 25 float shift[2];
24 float rotate; 26 float rotate;
25 float scale[2]; 27 float scale[2];
26} MapPlane; 28} MapPlane;
27 29
28typedef struct { 30typedef struct {
29 MapPlane *planes; 31 MapPlane *planes;
30 int plane_count; 32 int plane_count;
31} MapBrush; 33} MapBrush;
32 34
33typedef struct { 35typedef struct {
34 char key[64]; 36 char key[64];
35 char value[256]; 37 char value[256];
36} MapProperty; 38} MapProperty;
37 39
38typedef struct { 40typedef struct {
39 MapProperty *properties; 41 MapProperty *properties;
40 int property_count; 42 int property_count;
41 MapBrush *brushes; 43 MapBrush *brushes;
42 int brush_count; 44 int brush_count;
43} MapEntity; 45} MapEntity;
44 46
45typedef struct { 47typedef struct {
46 MapEntity *entities; 48 MapEntity *entities;
47 int entity_count; 49 int entity_count;
48} Map; 50} Map;
49 51
50typedef struct { 52typedef struct {
51 const char *data; 53 const char *data;
52 size_t length; 54 size_t length;
53 size_t pos; 55 size_t pos;
54} MapParser; 56} MapParser;
55 57
56typedef struct { 58typedef struct {
57 Vector3 normal; 59 Vector3 normal;
58 float dist; 60 float dist;
59} Plane; 61} Plane;
60 62
61typedef struct { 63typedef struct {
62 Vector3 *verts; 64 Vector3 *verts;
63 int count; 65 int count;
64} Polygon; 66} Polygon;
65 67
66typedef struct { 68typedef struct {
67 char texture[64]; 69 char texture[64];
68 array(float) vertices; 70 array(float) vertices;
69 array(float) texcoords; 71 array(float) texcoords;
70 array(float) normals; 72 array(float) normals;
71} TextureGroup; 73} TextureGroup;
72 74
73typedef struct { 75typedef struct {
74 char name[64]; 76 char name[64];
75 Texture2D tex; 77 Texture2D tex;
76} CachedTexture; 78} CachedTexture;
77 79
78// --- Game State --- 80// Asset Module
81Texture2D GetTexture(const char *name);
82void UnloadAssets(void);
83Font LoadFontVFS(const char *path, int fontSize);
84
85// Map Module
86typedef struct {
87 Model *models;
88 int count;
89} MapState;
90
91bool LoadMap(const char *filename);
92void UnloadMap(void);
93bool CheckMapCollision(Vector3 start, Vector3 end, RayCollision *outCollision);
94Map ParseMap(const char *filename);
95void FreeMap(Map map);
96
97// Menu Module
98void UpdateMenu(void);
99void DrawMenu(void);
79 100
101// Player Module
80typedef enum { 102typedef enum {
81 MOVE_NORMAL, 103 MOVE_NORMAL,
82 MOVE_FLY 104 MOVE_FLY
83} MovementMode; 105} MovementMode;
84 106
107typedef struct {
108 MovementMode move_mode;
109 Vector3 pos;
110 Vector3 velocity;
111 bool is_grounded;
112 float yaw;
113 float pitch;
114 float lean_amount;
115 float crouch_amount;
116 float horizontal_speed;
117} PlayerState;
118
119void UpdatePlayer(void);
120
121// Game State Module
85typedef enum { 122typedef enum {
86 STATE_TITLE, 123 STATE_MENU,
87 STATE_PLAYING 124 STATE_PLAYING
88} GameStateMode; 125} GameStateMode;
89 126
90typedef struct { 127typedef struct {
91 GameStateMode mode; 128 GameStateMode mode;
92 char map_path[256]; 129 char map_path[256];
93 Camera camera; 130 Camera camera;
94 Model *world_models; 131 bool cursor_captured;
95 int world_model_count; 132 bool vsync;
96 bool cursor_captured; 133 Font font_ui;
97 bool vsync; 134
98 Font font_ui; 135 PlayerState player;
99 136 MapState map;
100 MovementMode move_mode;
101 Vector3 pos;
102 Vector3 velocity;
103 bool is_grounded;
104 float yaw;
105 float pitch;
106 float lean_amount;
107 float crouch_amount;
108 float horizontal_speed;
109} GameState; 137} GameState;
110 138
111extern GameState game; 139extern GameState game;
112 140
113// --- Prototypes --- 141void InitGame(void);
114 142void SetMap(const char *path);
115// Map 143void UpdateGame(void);
116char map_peek(MapParser *p); 144void DrawGame(void);
117char map_get(MapParser *p);
118void map_skip_whitespace(MapParser *p);
119bool map_expect(MapParser *p, char expected);
120void map_parse_token(MapParser *p, char *buffer, int size);
121Vector3 map_parse_vector(MapParser *p);
122Map ParseMap(const char *filename);
123void FreeMap(Map map);
124 145
125// Geometry 146// Geometry Helpers
126Plane PlaneFromPoints(Vector3 p1, Vector3 p2, Vector3 p3); 147Plane PlaneFromPoints(Vector3 p1, Vector3 p2, Vector3 p3);
127void PolyFree(Polygon p); 148void PolyFree(Polygon p);
128Polygon PolyClip(Polygon poly, Plane plane); 149Polygon PolyClip(Polygon poly, Plane plane);
129Polygon CreateLargeQuad(Plane plane); 150Polygon CreateLargeQuad(Plane plane);
130Vector2 GetUV(Vector3 p, MapPlane *mp, Plane plane); 151Vector2 GetUV(Vector3 p, MapPlane *mp, Plane plane);
131 152
132// Game
133Texture2D GetTexture(const char *name);
134void InitGame(void);
135void SetMap(const char *path);
136void UpdateGame(void);
137void DrawGame(void);
138bool LoadMap(const char *filename);
139void UnloadMap(void);
140
141// Interface 153// Interface
142void DrawCrosshair(void); 154void DrawCrosshair(void);
143void DrawDebugInfo(void); 155void DrawDebugInfo(void);
144 156
145// Player
146void UpdatePlayer(void);
147
148#endif 157#endif