Skip to content

Latest commit

 

History

History
119 lines (89 loc) · 3.49 KB

README.md

File metadata and controls

119 lines (89 loc) · 3.49 KB

Standard License: MIT Build status Build Status

HFSM (Hierarchical Finite State Machine) Framework

Header-only heriarchical FSM framework in C++14, completely static (no dynamic allocations), built with variadic templates.

Compiler Support

DEPRECATED, FURTHER DEVELOPMENT CONTINUES IN HFSM2

Compiler Support

  • Visual Studio 14.u3, 15.7
  • GCC 4.9, 5.4, 6.3, 7.3, 8.0
  • Clang 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0

Basic Usage

// 1. Include HFSM header:
#include <hfsm/machine_single.hpp>

// 2. Define interface class between the FSM and its owner
//    (also ok to use the owner object itself):
struct Context { /* ... */ };

// 3. (Optional) Typedef hfsm::Machine for convenience:
using M = hfsm::Machine<OwnerClass>;

// 4. Define states:
struct MyState1 : M::Bare {
    // 5. Override some of the following state functions:
    void enter(Context& _);
    void update(Context& _);
    void transition(Control& c, Context& _);
    void leave(Context& _);
};

struct MyState2 : M::Bare { /* .. */ };
struct MySubState1 : M::Bare { /* .. */ };
struct MySubState2 : M::Bare { /* .. */ };

struct MyState3 : M::Bare { /* .. */ };
struct MyOrthogonalState1 : M::Bare { /* .. */ };
struct MyOrthogonalState2 : M::Bare { /* .. */ };

// 6. Declare state machine structure:
using MyFSM = M::PeerRoot<
    MyState1,
    M::Composite<MyState2,
        MySubState1,
        MySubState2,
    >,
    M::Orthogonal<MyState3,
        MyOrthogonalState1,
        MyOrthogonalState2,
    >
>;

int main() {
    // 7. Create context and state machine instances:
    Context context;
    MyFSM fsm(context);

    // 8. Kick off periodic updates:
    bool running = true;
    while (running)
        fsm.update();

    return 0;
}

Feature Highlights

  • Permissive MIT License
  • Written in widely-supported modern(ish) C++ 14
  • 100% NoUML-compliant
  • Not hamstrung by restrictive event reaction-based approach, but supports powerful event handling
  • Hierarchical, with composite (sub-machine) and orthogonal regions
  • Header-only
  • Fully static, no dynamic allocations
  • Uses inline-friendly compile-time pylymorphism, no virtual methods were harmed
  • Type-safe transitions: FSM.changeTo<TargetState>()
  • Gamedev-friendly, supports explicit State::update()
  • Scaleable, supports state re-use via state injections
  • Debug-assisted, includes automatic structure and activity visualization API with #define HFSM_ENABLE_STRUCTURE_REPORT
  • Convenient, minimal boilerplate

Documentation

See Wiki for Tutorial and docs.


Get Updates


Special Thanks