aboutsummaryrefslogtreecommitdiff
path: root/all.h
blob: 26ccffb6fbe65e2bf296f3158dd7b501a1367858 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef ALL_H
#define ALL_H

#include "raylib.h"
#include "raymath.h"
#include "rlgl.h"
#include "config.h"

// Resolve conflicts between Raylib and nonstd.h
#define Color NS_Color
#include "libraries/nonstd.h"
#undef Color

#include "libraries/vfs.h"
#include <stdbool.h>
#include <stddef.h>

#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];
} MapPlane;

typedef struct {
	MapPlane *planes;
	int plane_count;
} MapBrush;

typedef struct {
	char key[64];
	char value[256];
} MapProperty;

typedef struct {
	MapProperty *properties;
	int property_count;
	MapBrush *brushes;
	int brush_count;
} MapEntity;

typedef struct {
	MapEntity *entities;
	int entity_count;
} Map;

typedef struct {
	const char *data;
	size_t length;
	size_t pos;
} MapParser;

typedef struct {
	Vector3 normal;
	float dist;
} Plane;

typedef struct {
	Vector3 *verts;
	int count;
} Polygon;

typedef struct {
	char texture[64];
	array(float) vertices;
	array(float) texcoords;
	array(float) normals;
} TextureGroup;

typedef struct {
	char name[64];
	Texture2D tex;
} CachedTexture;

// 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
} 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_MENU,
	STATE_PLAYING
} GameStateMode;

typedef struct {
	GameStateMode mode;
	char map_path[256];
	Camera camera;
	bool cursor_captured;
	bool vsync;
	Font font_ui;

	PlayerState player;
	MapState map;
} GameState;

extern GameState game;

void InitGame(void);
void SetMap(const char *path);
void UpdateGame(void);
void DrawGame(void);

// 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);

// Interface
void DrawCrosshair(void);
void DrawDebugInfo(void);

#endif