diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-04-30 19:19:27 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-04-30 19:44:07 +0200 |
| commit | b4d0ad9e95226d225d5361b1182866884aaa6366 (patch) | |
| tree | 5440b34d97e89a08fc01abd49bb80e5b50dda945 /all.h | |
| parent | ddde2e8fdf05efac5914ca2b812b7762b78ba9ec (diff) | |
| download | stalag-b4d0ad9e95226d225d5361b1182866884aaa6366.tar.gz | |
Structural refactor
Diffstat (limited to 'all.h')
| -rw-r--r-- | all.h | 161 |
1 files changed, 85 insertions, 76 deletions
| @@ -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 | ||
| 20 | typedef struct { | 22 | typedef 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 | ||
| 28 | typedef struct { | 30 | typedef struct { |
| 29 | MapPlane *planes; | 31 | MapPlane *planes; |
| 30 | int plane_count; | 32 | int plane_count; |
| 31 | } MapBrush; | 33 | } MapBrush; |
| 32 | 34 | ||
| 33 | typedef struct { | 35 | typedef struct { |
| 34 | char key[64]; | 36 | char key[64]; |
| 35 | char value[256]; | 37 | char value[256]; |
| 36 | } MapProperty; | 38 | } MapProperty; |
| 37 | 39 | ||
| 38 | typedef struct { | 40 | typedef 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 | ||
| 45 | typedef struct { | 47 | typedef struct { |
| 46 | MapEntity *entities; | 48 | MapEntity *entities; |
| 47 | int entity_count; | 49 | int entity_count; |
| 48 | } Map; | 50 | } Map; |
| 49 | 51 | ||
| 50 | typedef struct { | 52 | typedef 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 | ||
| 56 | typedef struct { | 58 | typedef struct { |
| 57 | Vector3 normal; | 59 | Vector3 normal; |
| 58 | float dist; | 60 | float dist; |
| 59 | } Plane; | 61 | } Plane; |
| 60 | 62 | ||
| 61 | typedef struct { | 63 | typedef struct { |
| 62 | Vector3 *verts; | 64 | Vector3 *verts; |
| 63 | int count; | 65 | int count; |
| 64 | } Polygon; | 66 | } Polygon; |
| 65 | 67 | ||
| 66 | typedef struct { | 68 | typedef 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 | ||
| 73 | typedef struct { | 75 | typedef 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 |
| 81 | Texture2D GetTexture(const char *name); | ||
| 82 | void UnloadAssets(void); | ||
| 83 | Font LoadFontVFS(const char *path, int fontSize); | ||
| 84 | |||
| 85 | // Map Module | ||
| 86 | typedef struct { | ||
| 87 | Model *models; | ||
| 88 | int count; | ||
| 89 | } MapState; | ||
| 90 | |||
| 91 | bool LoadMap(const char *filename); | ||
| 92 | void UnloadMap(void); | ||
| 93 | bool CheckMapCollision(Vector3 start, Vector3 end, RayCollision *outCollision); | ||
| 94 | Map ParseMap(const char *filename); | ||
| 95 | void FreeMap(Map map); | ||
| 96 | |||
| 97 | // Menu Module | ||
| 98 | void UpdateMenu(void); | ||
| 99 | void DrawMenu(void); | ||
| 79 | 100 | ||
| 101 | // Player Module | ||
| 80 | typedef enum { | 102 | typedef enum { |
| 81 | MOVE_NORMAL, | 103 | MOVE_NORMAL, |
| 82 | MOVE_FLY | 104 | MOVE_FLY |
| 83 | } MovementMode; | 105 | } MovementMode; |
| 84 | 106 | ||
| 107 | typedef 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 | |||
| 119 | void UpdatePlayer(void); | ||
| 120 | |||
| 121 | // Game State Module | ||
| 85 | typedef enum { | 122 | typedef enum { |
| 86 | STATE_TITLE, | 123 | STATE_MENU, |
| 87 | STATE_PLAYING | 124 | STATE_PLAYING |
| 88 | } GameStateMode; | 125 | } GameStateMode; |
| 89 | 126 | ||
| 90 | typedef struct { | 127 | typedef 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 | ||
| 111 | extern GameState game; | 139 | extern GameState game; |
| 112 | 140 | ||
| 113 | // --- Prototypes --- | 141 | void InitGame(void); |
| 114 | 142 | void SetMap(const char *path); | |
| 115 | // Map | 143 | void UpdateGame(void); |
| 116 | char map_peek(MapParser *p); | 144 | void DrawGame(void); |
| 117 | char map_get(MapParser *p); | ||
| 118 | void map_skip_whitespace(MapParser *p); | ||
| 119 | bool map_expect(MapParser *p, char expected); | ||
| 120 | void map_parse_token(MapParser *p, char *buffer, int size); | ||
| 121 | Vector3 map_parse_vector(MapParser *p); | ||
| 122 | Map ParseMap(const char *filename); | ||
| 123 | void FreeMap(Map map); | ||
| 124 | 145 | ||
| 125 | // Geometry | 146 | // Geometry Helpers |
| 126 | Plane PlaneFromPoints(Vector3 p1, Vector3 p2, Vector3 p3); | 147 | Plane PlaneFromPoints(Vector3 p1, Vector3 p2, Vector3 p3); |
| 127 | void PolyFree(Polygon p); | 148 | void PolyFree(Polygon p); |
| 128 | Polygon PolyClip(Polygon poly, Plane plane); | 149 | Polygon PolyClip(Polygon poly, Plane plane); |
| 129 | Polygon CreateLargeQuad(Plane plane); | 150 | Polygon CreateLargeQuad(Plane plane); |
| 130 | Vector2 GetUV(Vector3 p, MapPlane *mp, Plane plane); | 151 | Vector2 GetUV(Vector3 p, MapPlane *mp, Plane plane); |
| 131 | 152 | ||
| 132 | // Game | ||
| 133 | Texture2D GetTexture(const char *name); | ||
| 134 | void InitGame(void); | ||
| 135 | void SetMap(const char *path); | ||
| 136 | void UpdateGame(void); | ||
| 137 | void DrawGame(void); | ||
| 138 | bool LoadMap(const char *filename); | ||
| 139 | void UnloadMap(void); | ||
| 140 | |||
| 141 | // Interface | 153 | // Interface |
| 142 | void DrawCrosshair(void); | 154 | void DrawCrosshair(void); |
| 143 | void DrawDebugInfo(void); | 155 | void DrawDebugInfo(void); |
| 144 | 156 | ||
| 145 | // Player | ||
| 146 | void UpdatePlayer(void); | ||
| 147 | |||
| 148 | #endif | 157 | #endif |
