C++ State Machines
beza1e1.tuxen.de
C++ State Machines
1–10 of 29 posts
Re: C++ State Machines
#2Re: C++ State Machines
#3As with most Boost libraries, you're in for some serious headache if you decide to use them (or is it just me?) but it's very rewarding in the end.
Re: C++ State Machines
#4If you're not willing to develop all the boilerplate code to encode your states, transitions, etc. Boost has two libraries to offer : Boost Statechart and Meta State Machine. One of my favorite question on Stack Overflow compares both: https://stackoverflow.com/questions/4275602/boost-statechart... . As with most Boost libraries, you're in for some serious headache if you decide to use them (or is it just me?) but it…
https://boost-experimental.github.io/sml/
Unfortunately I haven't seen any compelling real world usage of any of these libraries, and the documentation for SML leaves a lot to be desired.
Re: C++ State Machines
#5Well another OO way would be to add a state member to the Heroine class and create a state class for every possible state (X,Y,Z). Each state can then be responsible for interpreting the input and transitioning to the next appropriate state (if any)
Re: C++ State Machines
#6Well another OO way would be to add a state member to the Heroine class and create a state class for every possible state (X,Y,Z). Each state can then be responsible for interpreting the input and transitioning to the next appropriate state (if any)
How do you manage combinatorial explosion as states increase?
Re: C++ State Machines
#7Well another OO way would be to add a state member to the Heroine class and create a state class for every possible state (X,Y,Z). Each state can then be responsible for interpreting the input and transitioning to the next appropriate state (if any)
How do you manage combinatorial explosion as states increase?
HSM have been there for a while, being proposed in '84 (!) by David Harel under the name 'statecharts'
Re: C++ State Machines
#8Re: C++ State Machines
#9If you're not willing to develop all the boilerplate code to encode your states, transitions, etc. Boost has two libraries to offer : Boost Statechart and Meta State Machine. One of my favorite question on Stack Overflow compares both: https://stackoverflow.com/questions/4275602/boost-statechart... . As with most Boost libraries, you're in for some serious headache if you decide to use them (or is it just me?) but it…
Boost.SML (which is experimental) has garnered a lot of attention lately as a modern take on C++ state machines that can replace both of the options you raised. https://boost-experimental.github.io/sml/ Unfortunately I haven't seen any compelling real world usage of any of these libraries, and the documentation for SML leaves a lot to be desired.
I agree the documentation is not great though, you kind of have to go over the example code and try to figure things out on your own.
Using embedded data for keeping state (e.g. counters, etc; see https://boost-experimental.github.io/sml/examples/index.html...) along with injecting std::functions to use as actions is pretty powerful.
Here's a basic example I wrote some months ago showing a hierarchical machine (https://gist.github.com/indiosmo/08ab24181770125d5a2448d27f6...).
Also please note my usage is pretty basic as I usually have the same machine ported to C# and Python so I tend to use the smallest subset of functionality supported by all the libraries in each language.
Re: C++ State Machines
#10It's a shame that Mathworks is essentially the only game in town though, and their software licenses are fairly expensive.