fencer/core/src/state.h

28 lines
777 B
C

#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, enter_fn, exit_fn, update_fn)\
static inline const State* _StateName() {\
TC_FN_TYPECHECK(void, enter_fn, void*);\
TC_FN_TYPECHECK(void, exit_fn, void*);\
TC_FN_TYPECHECK(const State*, update_fn, void*, float);\
static const State instance = {\
.enter = (void(*const)(void*)) enter_fn,\
.exit = (void(*const)(void*)) exit_fn,\
.update = (const State*(*const)(void*, float)) update_fn,\
};\
return &instance;\
}
#endif // !_fencer_state_h