#obel #behavior-tree #obel-engine #graphics

obel_statechart

Provides statechart plugin to implement complex game logics eg, behavior tree

4 releases

new 0.0.6 Jan 30, 2025
0.0.5 Jan 27, 2025
0.0.2 Jan 27, 2025
0.0.1 Jan 26, 2025

#979 in Game dev

Download history 253/week @ 2025-01-22

253 downloads per month

MIT/Apache

6KB

Obel Statechart

License Crates.io Downloads Docs Discord

You can think of statechart(SC) as kind of event-driven behavior tree (BT). But actually SC is more powerful and has more benefits than traditional BT.

This impls of SC is ported from well-known statechart JS implementation - XState. For more details on statechart, please refer to the xstate docs.

Statechart implemented by ECS

Statechart Component

A Statechart (SC) is an advanced form of event-driven Behavior Tree (BT) that offers enhanced capabilities and flexibility. This implementation is based on XState, a popular JavaScript statechart library. For comprehensive documentation, visit the XState documentation.

ECS Implementation

Components

The Statechart Component (SCCmpt) is composed of four main components:

  1. Context Component

    • Implements a Rust enum-based JSON-like data structure
    • Provides CRUD operations for state management
  2. State Node Component

    • Uses a cache-friendly double-linked array list structure
    • Optimized for efficient state transitions between nodes
  3. Incoming Mailbox Component

    • Functions as a queue for received events
    • Manages event reception and processing
  4. Outgoing Mailbox Component

    • Serves as a queue for events to be sent
    • Handles event distribution

System Architecture

1. Incoming Mailbox System

Functionality:

  • Processes events sequentially
  • Executes event handler functions
  • Manages state node transitions

Concurrency Features:

  • Multi-threaded execution utilized with all cpu cores
  • Automatic components load balancing to prevent thread starvation
  • Dedicated system group for sequential runs of systems

2. Outgoing Mailbox System

  • Derived events are stored in the outgoing mailbox component
  • System collects and routes events to appropriate incoming mailboxes
  • Target entities receive events via their incoming mailbox components
  • Incoming mailbox system processes new events

No runtime deps