diff options
Diffstat (limited to 'all.h')
| -rw-r--r-- | all.h | 161 |
1 files changed, 91 insertions, 70 deletions
| @@ -15,122 +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; | ||
| 79 | 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); | ||
| 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 | ||
| 85 | typedef struct { | 107 | typedef struct { |
| 86 | Camera camera; | 108 | MovementMode move_mode; |
| 87 | Model *world_models; | 109 | Vector3 pos; |
| 88 | int world_model_count; | 110 | Vector3 velocity; |
| 89 | bool cursor_captured; | 111 | bool is_grounded; |
| 90 | bool vsync; | 112 | float yaw; |
| 91 | Font font_ui; | 113 | float pitch; |
| 92 | 114 | float lean_amount; | |
| 93 | MovementMode move_mode; | 115 | float crouch_amount; |
| 94 | Vector3 pos; | 116 | float horizontal_speed; |
| 95 | Vector3 velocity; | 117 | } PlayerState; |
| 96 | bool is_grounded; | 118 | |
| 97 | float yaw; | 119 | void UpdatePlayer(void); |
| 98 | float pitch; | 120 | |
| 99 | float lean_amount; | 121 | // Game State Module |
| 100 | float crouch_amount; | 122 | typedef enum { |
| 101 | float horizontal_speed; | 123 | STATE_MENU, |
| 124 | STATE_PLAYING | ||
| 125 | } GameStateMode; | ||
| 126 | |||
| 127 | typedef struct { | ||
| 128 | GameStateMode mode; | ||
| 129 | char map_path[256]; | ||
| 130 | Camera camera; | ||
| 131 | bool cursor_captured; | ||
| 132 | bool vsync; | ||
| 133 | Font font_ui; | ||
| 134 | |||
| 135 | PlayerState player; | ||
| 136 | MapState map; | ||
| 102 | } GameState; | 137 | } GameState; |
| 103 | 138 | ||
| 104 | extern GameState game; | 139 | extern GameState game; |
| 105 | 140 | ||
| 106 | // --- Prototypes --- | 141 | void InitGame(void); |
| 107 | 142 | void SetMap(const char *path); | |
| 108 | // Map | 143 | void UpdateGame(void); |
| 109 | char map_peek(MapParser *p); | 144 | void DrawGame(void); |
| 110 | char map_get(MapParser *p); | ||
| 111 | void map_skip_whitespace(MapParser *p); | ||
| 112 | bool map_expect(MapParser *p, char expected); | ||
| 113 | void map_parse_token(MapParser *p, char *buffer, int size); | ||
| 114 | Vector3 map_parse_vector(MapParser *p); | ||
| 115 | Map ParseMap(const char *filename); | ||
| 116 | void FreeMap(Map map); | ||
| 117 | 145 | ||
| 118 | // Geometry | 146 | // Geometry Helpers |
| 119 | Plane PlaneFromPoints(Vector3 p1, Vector3 p2, Vector3 p3); | 147 | Plane PlaneFromPoints(Vector3 p1, Vector3 p2, Vector3 p3); |
| 120 | void PolyFree(Polygon p); | 148 | void PolyFree(Polygon p); |
| 121 | Polygon PolyClip(Polygon poly, Plane plane); | 149 | Polygon PolyClip(Polygon poly, Plane plane); |
| 122 | Polygon CreateLargeQuad(Plane plane); | 150 | Polygon CreateLargeQuad(Plane plane); |
| 123 | Vector2 GetUV(Vector3 p, MapPlane *mp, Plane plane); | 151 | Vector2 GetUV(Vector3 p, MapPlane *mp, Plane plane); |
| 124 | 152 | ||
| 125 | // Game | 153 | // Interface |
| 126 | Texture2D GetTexture(const char *name); | 154 | void DrawCrosshair(void); |
| 127 | void InitGame(void); | 155 | void DrawDebugInfo(void); |
| 128 | void UpdateGame(void); | ||
| 129 | void DrawGame(void); | ||
| 130 | bool LoadMap(const char *filename); | ||
| 131 | void UnloadMap(void); | ||
| 132 | |||
| 133 | // Player | ||
| 134 | void UpdatePlayer(void); | ||
| 135 | 156 | ||
| 136 | #endif | 157 | #endif |
