-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.h
More file actions
176 lines (161 loc) · 3.51 KB
/
Copy pathstate.h
File metadata and controls
176 lines (161 loc) · 3.51 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef __ENGINE_STATE_STATE_H
#define __ENGINE_STATE_STATE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "../platform.h"
#include "../types/numeric.h"
/**
* @brief Current state of the game.
*
* Contains information about the game, the variables, flags
* entities and everything else. Is used to communicate the
* current state of things between various systems of the
* game engine.
*
*/
typedef struct GameState {
void *window;
char *preferred_platform;
u64 tick;
u32 flags;
u32 tickrate;
u32 fps_max;
u32 width;
u32 height;
} GameState;
/**
* @brief Game state flags.
*
* Various boolean variables that are used to control the
* behavior of the engine.
*
*/
enum GameFlag { GS_PAUSED = 1, GS_DEBUG = 2, GS_EXIT = 4, GS_FULLSCREEN = 8, GS_VERBOSE = 16 };
/**
* @brief Creates a new game state.
*
* **Don't forget to free after allocating.**
*
* ```
* GameState *state = game_new_state();
* ```
*
* @return GameState* Newly created game state.
*/
GameState *game_new_state();
/**
* @brief Creates a new game state with default values.
*
* Basically the same as `game_new_state` but also populates the
* struct fields with default values.
*
* **Don't forget to free after allocating.**
*
* ```
* GameState *state = game_default_state();
* ```
*
* @return GameState* Newly created game state
*/
GameState *game_default_state();
/**
* @brief Adds a boolean flag to the game flags.
*
* ```
* game_add_flag(state, GameFlag::PAUSED);
* ```
*
* @param state Current game state
* @param flag The flag to add
*/
void game_add_flag(GameState RESTRICTED_PTR state, const u32 flag);
/**
* @brief Removes a boolean flag from the game flags.
*
* ```
* game_remove_flag(state, GameFlag::PAUSED);
* ```
*
* @param state Current game state
* @param flag The flag to remove
*/
void game_remove_flag(GameState RESTRICTED_PTR state, const u32 flag);
/**
* @brief Checks whether game state is paused or not.
*
* ```
* if (game_is_paused(state)) {
* think_while_paused();
* return;
* }
* ```
*
* @param state Current game state
* @return u8 Whether or not the game is paused
*/
u8 game_is_paused(const GameState RESTRICTED_PTR state);
/**
* @brief Checks whether the game is in debug mode.
*
* ```
* if (game_is_debug(state)) {
* draw_debug_gui();
* }
* ```
*
* @param state Current game state
* @return u8 Whether or not the game is in debug mode
*/
u8 game_is_debug(const GameState RESTRICTED_PTR state);
/**
* @brief Checks whether the game should produce extra console output.
*
* ```
* if (game_is_verbose(state)) {
* printf(debug_information);
* }
* ```
*
* @param state Current game state
* @return u8 Whether or not the game is verbose
*/
u8 game_is_verbose(const GameState RESTRICTED_PTR state);
/**
* @brief Checks whether or not the game should exit.
*
* ```
* int main() {
* GameState *state = (Gamestate *)malloc(sizeof(GameState));
*
* while (!game_should_exit(state)) {
* game_logic(state);
* }
*
* free(state);
*
* return 0;
* }
* ```
*
* @param state Current game state
* @return u8 Whether or not the game should exit.
*/
u8 game_should_exit(const GameState RESTRICTED_PTR state);
/**
* @brief Whether or not is the game fullscreen.
*
* ```
* if (game_is_fullscreen(state) && !IsWindowFullscreen()) {
* ToggleFullscreen();
* }
* ```
*
* @param state Current game state
* @return u8 Whether or not the game is fullscreen.
*/
u8 game_is_fullscreen(const GameState RESTRICTED_PTR state);
#ifdef __cplusplus
}
#endif
#endif