Skip to content
This repository was archived by the owner on Nov 16, 2025. It is now read-only.

HierarchicalStateMachine ctor()

ged edited this page Sep 10, 2024 · 3 revisions

Definition

Initializes a HierarchicalStateMachine<TContext> instance that has a specified context and a flag indicating whether to handle deep transitions.

template<class TContext>
HierarchicalStateMachine(TContext* context, bool handleDeepTransition = false)

Type Parameters

  • TContext: The type of the context, which holds data or behavior relevant to the state machine.

Parameters

  • context: The context associated with this state machine.
  • handleDeepTransition: Indicates whether to handle deep transitions.

Remarks

If handleDeepTransition is true, transitions from lower-level states to higher-level states will cause the state to exit and re-enter, instead of just reusing the existing state.

Deep transition execution can be viewed here for more details.

Usage

// primitive context
int foo1 = 5;
HierarchicalStateMachine<int> foo1SM(&foo1);

float foo2 = 1.0f;
HierarchicalStateMachine<float> foo2SM(&foo2, true); // can handle deep transitions

// user-defined context
struct FooStructContext; // implementation omitted for brevity
auto fooContext1 = FooStructContext();
auto fooContext1SM = HierarchicalStateMachine<FooStructContext>(&fooContext1);

class FooClassContext; // implementation omitted for brevity
auto fooContext2 = FooClassContext();
auto fooContext2SM = HierarchicalStateMachine<FooClassContext>(&fooContext2, true); // can handle deep transitions

Clone this wiki locally