Class ScyllaPushdownStateMachine<TContext>
A pushdown automaton extension of ScyllaStateMachine<TContext>: states can be pushed over the current state and popped again later, resuming the underlying state exactly where it was suspended. Useful for interruptible behavior such as "investigate, then return to patrol" without re-entering the patrol state.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public class ScyllaPushdownStateMachine<TContext> : ScyllaStateMachine<TContext>
Type Parameters
| Name | Description |
|---|---|
| TContext | The shared context type passed to every state callback. |
Remarks
PushState(IScyllaState<TContext>) suspends the current state WITHOUT running its exit
callback and enters the pushed state. PopState() exits the current
state and resumes the state beneath it WITHOUT running its enter callback and
WITHOUT consulting its CanEnter(TContext) guard (it
was never exited). States implementing
IScyllaPausableState<TContext> additionally receive
OnPause/OnResume callbacks.
The inherited TransitionTo(IScyllaState<TContext>, bool) replaces the current (top) state with full exit/enter semantics and leaves the stack untouched. Global transitions registered via AddGlobalTransition(IScyllaTransition<TContext>) work unchanged and likewise replace only the top state.
StateChanged is raised for pushes and pops with the suspended/resumed states as arguments, in addition to the regular transition events.
Constructors
ScyllaPushdownStateMachine(TContext)
Creates a new pushdown state machine operating on the given context.
Declaration
public ScyllaPushdownStateMachine(TContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| TContext | context | The shared context passed to every state callback. |
Properties
StackDepth
Gets the number of suspended states currently on the stack beneath the current state. Zero when nothing has been pushed.
Declaration
public int StackDepth { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
ClearStack()
Exits and removes every suspended state from the stack, top-down, without touching the current state and without raising StateChanged. The stacked states were entered, so their exit callbacks are owed.
Declaration
public void ClearStack()
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when called from inside an enter, exit, pause, or resume callback. |
PopState()
Pops the current state, exiting it, and resumes the state beneath it. The
resumed state's CanEnter(TContext) guard is NOT
consulted and its enter callback is NOT run (it was never exited); if it
implements IScyllaPausableState<TContext> it receives
OnResume.
Declaration
public bool PopState()
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when called from inside an enter, exit, pause, or resume callback. |
PushState(IScyllaState<TContext>)
Pushes a state over the current state. The current state is suspended (paused if it implements IScyllaPausableState<TContext>, never exited) and the pushed state is entered. The pushed state's CanEnter(TContext) guard is consulted first.
Declaration
public bool PushState(IScyllaState<TContext> nextState)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaState<TContext> | nextState | The state to push and enter. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| InvalidOperationException | Thrown when called from inside an enter, exit, pause, or resume callback. |
Stop()
Stops the machine: exits the current state with the base semantics (including the final StateChanged event), then unwinds the stack top-down, exiting every suspended state without additional events, and clears the stack. Safe to call when the machine is not running.
Declaration
public override void Stop()