Main game loop and states.
This module offers a global game structure that contain a state. It is designed to help switching game states and inhibit some of the functions when necessary.
In contrast to popular engines, states are not stacked and only one is used at a time. Switching states mean that the current state will run until next frame and will be closed afterwards.
The main loop use a constant frame rate mechanism based on the screen refresh rate if supported, otherwise it use a default frame rate of 60hz. In any case, the frame rate is capped in the main loop and the elapsed time is measured accordingly to update the game at constant speed no matter the refresh rate is present.
Since only one game must be present at a time, a global
game variable is
available for convenience to not carrying it everywhere.
Current inhibit flags set, see inhibit for more information.
Current state running.
Optional next state to be changed in next frame loop.
state for the next frame.
The state will only be effective after the next call to game_update.
quick is set to true, the state is changed immediately and the
current state code should immediately return.
void game_switch(struct state *state, bool quick)
Handle the event
ev into the current state.
void game_handle(const union event *ev)
Update the current state with
ticks since last frame.
void game_update(unsigned int ticks)
Draw the current state.
Destroy both next and current state if any.
Even if you don't use game_loop you should call this function because it will close state resources.
If you call this function from a state itself, you must return immediately because the state will be finalized immediately.