From b4d0ad9e95226d225d5361b1182866884aaa6366 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 30 Apr 2026 19:19:27 +0200 Subject: Structural refactor --- all.h | 161 +++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 85 insertions(+), 76 deletions(-) (limited to 'all.h') diff --git a/all.h b/all.h index 59bdd32..26ccffb 100644 --- a/all.h +++ b/all.h @@ -15,134 +15,143 @@ #include #include -// --- Map Structures --- +#ifndef PLAYER_FOV +#define PLAYER_FOV 90.0f +#endif typedef struct { - Vector3 p[3]; - char texture[64]; - float shift[2]; - float rotate; - float scale[2]; + Vector3 p[3]; + char texture[64]; + float shift[2]; + float rotate; + float scale[2]; } MapPlane; typedef struct { - MapPlane *planes; - int plane_count; + MapPlane *planes; + int plane_count; } MapBrush; typedef struct { - char key[64]; - char value[256]; + char key[64]; + char value[256]; } MapProperty; typedef struct { - MapProperty *properties; - int property_count; - MapBrush *brushes; - int brush_count; + MapProperty *properties; + int property_count; + MapBrush *brushes; + int brush_count; } MapEntity; typedef struct { - MapEntity *entities; - int entity_count; + MapEntity *entities; + int entity_count; } Map; typedef struct { - const char *data; - size_t length; - size_t pos; + const char *data; + size_t length; + size_t pos; } MapParser; typedef struct { - Vector3 normal; - float dist; + Vector3 normal; + float dist; } Plane; typedef struct { - Vector3 *verts; - int count; + Vector3 *verts; + int count; } Polygon; typedef struct { - char texture[64]; - array(float) vertices; - array(float) texcoords; - array(float) normals; + char texture[64]; + array(float) vertices; + array(float) texcoords; + array(float) normals; } TextureGroup; typedef struct { - char name[64]; - Texture2D tex; + char name[64]; + Texture2D tex; } CachedTexture; -// --- Game State --- +// Asset Module +Texture2D GetTexture(const char *name); +void UnloadAssets(void); +Font LoadFontVFS(const char *path, int fontSize); + +// Map Module +typedef struct { + Model *models; + int count; +} MapState; + +bool LoadMap(const char *filename); +void UnloadMap(void); +bool CheckMapCollision(Vector3 start, Vector3 end, RayCollision *outCollision); +Map ParseMap(const char *filename); +void FreeMap(Map map); + +// Menu Module +void UpdateMenu(void); +void DrawMenu(void); +// Player Module typedef enum { - MOVE_NORMAL, - MOVE_FLY + MOVE_NORMAL, + MOVE_FLY } MovementMode; +typedef struct { + MovementMode move_mode; + Vector3 pos; + Vector3 velocity; + bool is_grounded; + float yaw; + float pitch; + float lean_amount; + float crouch_amount; + float horizontal_speed; +} PlayerState; + +void UpdatePlayer(void); + +// Game State Module typedef enum { - STATE_TITLE, - STATE_PLAYING + STATE_MENU, + STATE_PLAYING } GameStateMode; typedef struct { - GameStateMode mode; - char map_path[256]; - Camera camera; - Model *world_models; - int world_model_count; - bool cursor_captured; - bool vsync; - Font font_ui; - - MovementMode move_mode; - Vector3 pos; - Vector3 velocity; - bool is_grounded; - float yaw; - float pitch; - float lean_amount; - float crouch_amount; - float horizontal_speed; + GameStateMode mode; + char map_path[256]; + Camera camera; + bool cursor_captured; + bool vsync; + Font font_ui; + + PlayerState player; + MapState map; } GameState; extern GameState game; -// --- Prototypes --- - -// Map -char map_peek(MapParser *p); -char map_get(MapParser *p); -void map_skip_whitespace(MapParser *p); -bool map_expect(MapParser *p, char expected); -void map_parse_token(MapParser *p, char *buffer, int size); -Vector3 map_parse_vector(MapParser *p); -Map ParseMap(const char *filename); -void FreeMap(Map map); +void InitGame(void); +void SetMap(const char *path); +void UpdateGame(void); +void DrawGame(void); -// Geometry +// Geometry Helpers Plane PlaneFromPoints(Vector3 p1, Vector3 p2, Vector3 p3); void PolyFree(Polygon p); Polygon PolyClip(Polygon poly, Plane plane); Polygon CreateLargeQuad(Plane plane); Vector2 GetUV(Vector3 p, MapPlane *mp, Plane plane); -// Game -Texture2D GetTexture(const char *name); -void InitGame(void); -void SetMap(const char *path); -void UpdateGame(void); -void DrawGame(void); -bool LoadMap(const char *filename); -void UnloadMap(void); - // Interface void DrawCrosshair(void); void DrawDebugInfo(void); -// Player -void UpdatePlayer(void); - #endif -- cgit v1.2.3