27#ifndef STATE_MACHINE_H
28#define STATE_MACHINE_H
109#define STATE_INFO_UPDATE_FN_ONLY(fn) {.on_init = noop, .on_update = fn, .on_exit = noop}
110#define STATE_INFO_INIT_UPDATE_FN(init_fn, update_fn) {.on_init = init_fn, .on_update = update_fn, .on_exit = noop}
111#define STATE_MACHINE_DEFINE(infos, num) \
113 .state_infos = &infos[0], \
115 .registered = false, \
void(* StateCallback)(void)
State machine callback function pointer type.
void state_machine_remove(StateMachine *state_machine)
Remove a statemachine's update function.
void state_machine_register(StateMachine *state_machine)
Register a statemachine to run it's update function once per frame.
void noop(void)
no operation
void state_machine_change_state(StateMachine *state_machine, int new_state)
Calls the current state's on_exit, the new state's on_init, and sets the active update fn.
void state_machine_update(void)
Update registered state machines' update functions.
StateInfo * state_infos
Array of StateCallbacks , one entry per state.
bool registered
Flag to determine if statemachine is already running it's active_update function.
int state
The current state of the state machine, the offset into state_infos.
unsigned int num_infos
Number of elements in the state_infos array.
StateCallback active_update
Pointer to the active update function in state_infos