GameEngine is now a state machine so I can push its design further and keep it solid.

This commit is contained in:
Zed A. Shaw 2024-09-12 00:34:41 -04:00
parent 1c89afaee2
commit 9e6c05eccd
5 changed files with 56 additions and 56 deletions

View file

@ -5,15 +5,19 @@
#define FSM_EV(S, F) case S: F(); break
#define FSM_STATE(S, F, E) case S: F(E); break
#define FSM_STATE_LOG(C, S, F, E) case C::S: fmt::println(">> " #C " " #S ":" #F " event={}, state={}", int(E), int(_state)); F(E); fmt::println("<< " #C " state={}", int(_state)); break
template<typename S, typename E>
class DeadSimpleFSM {
protected:
// BUG: don't put this in your class because state() won't work
S _state = S::START;
public:
virtual void event(E event) = 0;
void state(S next_state) {
// fmt::println("STATE {}->{}", int(_state), int(next_state));
_state = next_state;
}