Can we have multiple instances of the same Fsm?
heLomaN opened this issue · 7 comments
Since declare typedef F const * state_ptr_const_t;
in class Fsm, we cannot get more than one instance for a specific Fsm. Is there any way to avoid this?
As you state correctly, Fsm and states are all static instances of template types. This means that it's not possible to have more than one instance for as specific Fsm.
It might be possible with some template metaprogramming magic, and I remember doing some experiments with this, but it became pretty complicated, so I dropped it (as one main goal of tinyfsm is to keep it simple).
Here's how you can have multiple state machines of the same type, declaring a template state machine: examples/api/multiple_switch.cpp.
I was going to use this library for doing fsm for like thousands of AI bots... this no longer seems viable if I there's not a way to instantiate a Fsm object for each bot. (Novice c++ learner so not positive if there's a workaround).
hm nvermind i'll just be using https://www.boost.org/doc/libs/1_64_0/libs/msm since it matches more closely what I was needing in terms of functionality.
Same problem. I wanted to use this library for a websocket server - websockets as state machines.
I came across Boost.SML.
@digint Can I ask why is it this way, instead of FSM being class that you can create multiple instances of?
Man this bit me this week. I need multiple instances of the same machine. There really needs to be an example of how to do that. Even for the basic case it took me a second to figure out that I have to use namespaces to avoid issues due to unreleated FSMs. Now I want n FSMs of type B and I just get crashes. Fun