-
Notifications
You must be signed in to change notification settings - Fork 1
FiniteStateMachine transitionTo()
Transitions the state machine to a specified state.
void transitionTo(FiniteStateMachine<TContext>::State& state, bool immediate = false);-
state: The state to transition to. -
immediate: Indicates whether the transition should happen immediately or in the next update cycle.
The immediate parameter controls whether the transition occurs instantly or waits for the next update() call.
The current state's exit logic and the next state's enter logic are queued as part of the transition.
NOTE: if used within a callback function, multiple calls of transitionTo will result in only the last function call being the next state to transition to.
fsm.transitionTo(state1); // queues state1, to be executed in the next update cycle
fsm.transitionTo(state1, true); // immediately transitions to state1, without the need to queue and wait for the next update cycle
// if used within a callback, it's best to only use a single call of 'transitionTo()'
static void update(FooContext* const ctx)
{
...
ctx->fsm->transitionTo(FooContext::state1); // transitions to state1
...
}
// Multiple transitions controlled by a conditional statement is fine.
static void update(FooContext* const ctx)
{
...
if (boolFlag)
{
ctx->fsm->transitionTo(FooContext::state1); // transitions to state1 if boolFlag is true
}
else
{
ctx->fsm->transitionTo(FooContext::state2); // transitions to state2 if boolFlag is false
}
...
}
// Consecutive transitions will result to only the last transition being applied, so it's best avoid this case.
static void update(FooContext* const ctx)
{
...
ctx->fsm->transitionTo(FooContext::state1); // state 1 will be overridden with state2 in the next line
ctx->fsm->transitionTo(FooContext::state2); // state 2 is now the next state to transition
...
}Common Types
→ StateStatus (enum)
→ StateCallback (alias)
Finite State Machine (FSM)
→ State
→ ctor()
→ isInState()
→ transitionTo()
→ update()
Hierarchical State Machine (HSM)
→ State
→ ctor()
→ isInState()
→ transitionTo()
→ update()
State Base
→ ctor()
→ is()
→ enter()
→ update()
→ exit()
State Machine Handler
→ ctor()
→ getNextState()
→ getActiveState()
→ isInState()
→ setNextState()
→ queueTransition()
→ beginTransitionQueue()
→ endTransitionQueue()
→ execute()