Giter Club home page Giter Club logo

hfsm's Introduction

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

hfsm's People

Contributors

andrew-gresyk avatar

Watchers

Steven avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.