Open mahonnaise opened 9 years ago
@mahonnaise thanks for the feedback! I read through the post that you linked at it was a good read. I'll admit that I had a bit of tunnel vision when designing this - it fits our use case well, but I agree that it isn't a true FSM. While it won't be right away, I'd definitely like to address this. If you don't mind, could I tag you when there's a PR ready?
If you have to guard against doing illegal transitions, you'll need another finite-state machine implementation (e.g. a switch) to do this. The current FSM implementation creates the very problem FSMs are meant to solve.
Doing the transitions directly is also, let's say, unorthodox.
Usually, you just throw events at the FSM and it transitions in response if it feels like it. E.g. in a platform game, if the player's character is already in the jumping state, pressing the jump button once more won't do anything (unless there is a doubleJumping state the FSM could transition to).
https://en.wikipedia.org/wiki/Finite-state_machine
Also check what Robert Nystrom (the author of
pub
anddartfmt
) wrote about this topic in his spare time:http://gameprogrammingpatterns.com/state.html