tinyfsm icon indicating copy to clipboard operation
tinyfsm copied to clipboard

Can we have multiple instances of the same Fsm?

Open heLomaN opened this issue 6 years ago • 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?

heLomaN avatar Oct 25 '17 02:10 heLomaN

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).

digint avatar Oct 25 '17 09:10 digint

Here's how you can have multiple state machines of the same type, declaring a template state machine: examples/api/multiple_switch.cpp.

digint avatar Apr 27 '18 17:04 digint

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).

pgruenbacher avatar Jul 02 '18 20:07 pgruenbacher

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.

pgruenbacher avatar Jul 03 '18 19:07 pgruenbacher

Same problem. I wanted to use this library for a websocket server - websockets as state machines. I came across Boost.SML.

01e9 avatar Sep 28 '18 09:09 01e9

@digint Can I ask why is it this way, instead of FSM being class that you can create multiple instances of?

martinerk0 avatar Jun 03 '23 09:06 martinerk0

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

ekigwana avatar Dec 18 '23 22:12 ekigwana