#ifndef _fencer_state_h #define _fencer_state_h #include "typeclass_helpers.h" typedef struct State State; struct State { void (*const enter)(void* data); void (*const exit)(void* data); const State* (*const update)(void* data, float dt); }; #define DefineState(_StateName, _DataType, enter_fn, update_fn, exit_fn)\ static inline const State* _StateName() {\ TC_FN_TYPECHECK(void, enter_fn, _DataType*);\ TC_FN_TYPECHECK(const State*, update_fn, _DataType*, float);\ TC_FN_TYPECHECK(void, exit_fn, _DataType*);\ static const State instance = {\ .enter = (void(*const)(void*)) enter_fn,\ .update = (const State*(*const)(void*, float)) update_fn,\ .exit = (void(*const)(void*)) exit_fn,\ };\ return &instance;\ } #endif // !_fencer_state_h