1#ifndef ALL_H
2#define ALL_H
3
4#include "raylib.h"
5#include "raymath.h"
6#include "rlgl.h"
7#include "config.h"
8
9// Resolve conflicts between Raylib and nonstd.h
10#define Color NS_Color
11#include "libraries/nonstd.h"
12#undef Color
13
14#include "libraries/vfs.h"
15#include <stdbool.h>
16#include <stddef.h>
17
18#ifndef PLAYER_FOV
19#define PLAYER_FOV 90.0f
20#endif
21
22typedef struct {
23 Vector3 p[3];
24 char texture[64];
25 float shift[2];
26 float rotate;
27 float scale[2];
28} MapPlane;
29
30typedef struct {
31 MapPlane *planes;
32 int plane_count;
33} MapBrush;
34
35typedef struct {
36 char key[64];
37 char value[256];
38} MapProperty;
39
40typedef struct {
41 MapProperty *properties;
42 int property_count;
43 MapBrush *brushes;
44 int brush_count;
45} MapEntity;
46
47typedef struct {
48 MapEntity *entities;
49 int entity_count;
50} Map;
51
52typedef struct {
53 const char *data;
54 size_t length;
55 size_t pos;
56} MapParser;
57
58typedef struct {
59 Vector3 normal;
60 float dist;
61} Plane;
62
63typedef struct {
64 Vector3 *verts;
65 int count;
66} Polygon;
67
68typedef struct {
69 char texture[64];
70 array(float) vertices;
71 array(float) texcoords;
72 array(float) normals;
73} TextureGroup;
74
75typedef struct {
76 char name[64];
77 Texture2D tex;
78} CachedTexture;
79
80// Asset Module
81Texture2D get_texture(const char *name);
82void unload_assets(void);
83Font load_font_vfs(const char *path, int fontSize);
84
85// Map Module
86typedef struct {
87 Model *models;
88 int count;
89} MapState;
90
91bool load_map(const char *filename);
92void unload_map(void);
93bool check_map_collision(Vector3 start, Vector3 end, RayCollision *outCollision);
94Map parse_map(const char *filename);
95void free_map(Map map);
96
97// Menu Module
98void update_menu(void);
99void draw_menu(void);
100
101// Player Module
102typedef enum {
103 MOVE_NORMAL,
104 MOVE_FLY
105} MovementMode;
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 float camera_offset_y; // Vertical offset for stair smoothing
118} PlayerState;
119
120void update_player(void);
121
122// Game State Module
123typedef enum {
124 STATE_MENU,
125 STATE_PLAYING
126} GameStateMode;
127
128typedef struct {
129 GameStateMode mode;
130 char map_path[256];
131 Camera camera;
132 bool cursor_captured;
133 bool vsync;
134 int target_fps;
135 int screen_width;
136 int screen_height;
137 Font font_ui;
138
139 PlayerState player;
140 MapState map;
141} GameState;
142
143extern GameState game;
144
145void init_game(void);
146void set_map(const char *path);
147void update_game(void);
148void draw_game(void);
149
150// Geometry Helpers
151Plane plane_from_points(Vector3 p1, Vector3 p2, Vector3 p3);
152void poly_free(Polygon p);
153Polygon poly_clip(Polygon poly, Plane plane);
154Polygon create_large_quad(Plane plane);
155Vector2 get_uv(Vector3 p, MapPlane *mp, Plane plane, int texWidth, int texHeight);
156
157// Interface
158void draw_crosshair(void);
159void draw_debug_info(void);
160
161#endif