HFSM2 Documentation

repository·master·Indexed 20 days ago

https://github.com/andrew-gresyk/hfsm2

A high-performance, header-only Hierarchical Finite State Machine framework for C++11. Optimized for game development and embedded systems, it utilizes compile-time polymorphism and variadic templates to avoid dynamic memory allocation and virtual methods. Features include type-safe transitions, composite and orthogonal regions, and support for utility theory and dynamic planning.

Tokens
473
Snippets
0
Records
4
Agent score
20%

What's inside HFSM2

  1. Overview of HFSM2

    master

    HFSM2 is a high-performance, header-only Hierarchical Finite State Machine (HFSM) framework written in C++11. It is designed for environments where performance and predictability are critical, such as game development and embedded systems.

    Key characteristics include:

    • Fully Static Structure: The FSM structure is defined at compile-time using variadic templates, ensuring no dynamic allocations occur during runtime.
    • Zero Virtual Methods: It uses inline-friendly compile-time polymorphism instead of virtual methods to maintain high performance.
    • Type-Safe Transitions: Transitions can be triggered using FSM.changeTo<TargetState>(), supporting optional payloads.
    • Hierarchical Support: Supports composite (sub-machine) regions and orthogonal regions.
    • Advanced AI Features: Includes support for dynamic planning, utility theory (max score and ranked weighted random), and event-based workflows via State::react().
  2. Quick Start with HFSM2

    master

    To begin using HFSM2, you can follow these two primary guides provided in the project wiki:

    1. Minimal Example: For a basic introduction to the syntax and structure.
    2. Extended Tutorial: For a deeper dive into implementing more complex state machines.

    Since the library is header-only, you can integrate it into your C++ project by including the relevant headers.

  3. Configure HFSM2 via Macros

    master

    HFSM2 allows for flexible configuration and feature toggling using preprocessor macros. You can enable or disable specific functionalities using the HFSM2_ENABLE_* pattern.

    For example, to enable automatic structure and activity visualization for debugging, use:

    #define HFSM_ENABLE_STRUCTURE_REPORT