Drag[en]gine Script Module DragonScript  1.21
Dragengine.StateMachineSystem.SMContext Class Reference

State machine context. More...

Inheritance diagram for Dragengine.StateMachineSystem.SMContext:

Public Member Functions

void forEachAction (Block ablock)
 Visit actions using block with parameters String (name and SMAction (action). More...
 
void forEachCondition (Block ablock)
 Visit conditions using block with parameters String (name and SMCondition (condition). More...
 
SMAction getAction (String name)
 Action for name or null if absent. More...
 
int getActionCount ()
 Count of actions. More...
 
SMCondition getCondition (String name)
 Condition for name or null if absent. More...
 
int getConditionCount ()
 Count of conditions. More...
 
Console getConsole ()
 Console or null if not wishing to log anything. More...
 
SMState getCurrentState ()
 Current state or null if in transition. More...
 
String getLoggingName ()
 Logging name to tell apart logs. More...
 
bool getLogStateChanges ()
 Log state machine state changes. More...
 
bool getLogTransitions ()
 Log state machine steps. More...
 
StateMachine getStateMachine ()
 State machine. More...
 
bool hasAction (String name)
 Action is present. More...
 
bool hasCondition (String name)
 Condition is present. More...
 
SMContext new (SMContext context)
 Create copy of state machine context. More...
 
SMContext new (SMContext context, StateMachine stateMachine)
 Create copy of state machine context but using a different state machine. More...
 
SMContext new (StateMachine stateMachine)
 Create state machine context. More...
 
void readFromFile (PersistencyEnvironment env, FileReader reader)
 Read state from file. More...
 
void removeAction (String name)
 Remove action. More...
 
void removeAllActions ()
 Remove all actions. More...
 
void removeAllConditions ()
 Remove all conditions. More...
 
void removeCondition (String name)
 Remove condition. More...
 
void reset ()
 Reset to initial state. More...
 
void runEvent (String event)
 Run event on state machine. More...
 
void setAction (String name, Block action)
 Set action for name using block. More...
 
void setCondition (String name, Block condition)
 Set condition for name using block. More...
 
void setConsole (Console console)
 Set console or null if not wishing to log anything. More...
 
void setCurrentState (SMState state)
 Set current state or null if in transition. More...
 
void setCurrentStateByID (String id)
 Set current state by identifier or null if in transition. More...
 
void setLoggingName (String name)
 Set logging name to tell apart logs. More...
 
void setLogStateChanges (bool logStateChanges)
 Set log state machine state changes. More...
 
void setLogTransitions (bool logSteps)
 Set log state machine steps. More...
 
void writeToFile (PersistencyEnvironment env, FileWriter writer)
 Write state to file. More...
 

Protected Member Functions

void onCurrentStateChanged ()
 Hook method called if setCurrentState() is called. More...
 

Detailed Description

State machine context.

Used to run a state machine instance. The state machine itself is shared across contexts while the individual state is stored in the context. Context has to provide the SMAction instances for the state machine states to call. Subclass the context to provide the required data for your SMAction subclasses to work properly.

After creating the context the initial state is the current state. No enter actions are run on the initial state since during that time no actions and conditions are present yet.

The context can be written to and restored from file readers. This class saves only the current state identifier. Subclass has to save its own states by overwriting readFromFile() and writeToFile().

Member Function Documentation

◆ forEachAction()

void Dragengine.StateMachineSystem.SMContext.forEachAction ( Block  ablock)

Visit actions using block with parameters String (name and SMAction (action).

◆ forEachCondition()

void Dragengine.StateMachineSystem.SMContext.forEachCondition ( Block  ablock)

Visit conditions using block with parameters String (name and SMCondition (condition).

◆ getAction()

SMAction Dragengine.StateMachineSystem.SMContext.getAction ( String  name)

Action for name or null if absent.

◆ getActionCount()

int Dragengine.StateMachineSystem.SMContext.getActionCount ( )

Count of actions.

◆ getCondition()

SMCondition Dragengine.StateMachineSystem.SMContext.getCondition ( String  name)

Condition for name or null if absent.

◆ getConditionCount()

int Dragengine.StateMachineSystem.SMContext.getConditionCount ( )

Count of conditions.

◆ getConsole()

Console Dragengine.StateMachineSystem.SMContext.getConsole ( )

Console or null if not wishing to log anything.

◆ getCurrentState()

SMState Dragengine.StateMachineSystem.SMContext.getCurrentState ( )

Current state or null if in transition.

◆ getLoggingName()

String Dragengine.StateMachineSystem.SMContext.getLoggingName ( )

Logging name to tell apart logs.

◆ getLogStateChanges()

bool Dragengine.StateMachineSystem.SMContext.getLogStateChanges ( )

Log state machine state changes.

◆ getLogTransitions()

bool Dragengine.StateMachineSystem.SMContext.getLogTransitions ( )

Log state machine steps.

◆ getStateMachine()

StateMachine Dragengine.StateMachineSystem.SMContext.getStateMachine ( )

State machine.

◆ hasAction()

bool Dragengine.StateMachineSystem.SMContext.hasAction ( String  name)

Action is present.

◆ hasCondition()

bool Dragengine.StateMachineSystem.SMContext.hasCondition ( String  name)

Condition is present.

◆ new() [1/3]

SMContext Dragengine.StateMachineSystem.SMContext.new ( SMContext  context)

Create copy of state machine context.

Actions are copied as shallow copy. If you need a deep set all actions anew. The state of the context is the same as without creating a copy.

◆ new() [2/3]

SMContext Dragengine.StateMachineSystem.SMContext.new ( SMContext  context,
StateMachine  stateMachine 
)

Create copy of state machine context but using a different state machine.

Actions are copied as shallow copy. If you need a deep set all actions anew. The state of the context is the same as without creating a copy.

This method is useful to use an initialized base context with a fallback state machine. Whenever a new context is required the base context is copied. This avoids the need to assign actions and conditions since they are copied from the base context.

◆ new() [3/3]

SMContext Dragengine.StateMachineSystem.SMContext.new ( StateMachine  stateMachine)

Create state machine context.

◆ onCurrentStateChanged()

void Dragengine.StateMachineSystem.SMContext.onCurrentStateChanged ( )
protected

Hook method called if setCurrentState() is called.

Allows subclasses to react to current state changes. This might be required for certain SMAction to reset states if states change.

◆ readFromFile()

void Dragengine.StateMachineSystem.SMContext.readFromFile ( PersistencyEnvironment  env,
FileReader  reader 
)

Read state from file.

◆ removeAction()

void Dragengine.StateMachineSystem.SMContext.removeAction ( String  name)

Remove action.

◆ removeAllActions()

void Dragengine.StateMachineSystem.SMContext.removeAllActions ( )

Remove all actions.

◆ removeAllConditions()

void Dragengine.StateMachineSystem.SMContext.removeAllConditions ( )

Remove all conditions.

◆ removeCondition()

void Dragengine.StateMachineSystem.SMContext.removeCondition ( String  name)

Remove condition.

◆ reset()

void Dragengine.StateMachineSystem.SMContext.reset ( )

Reset to initial state.

Sets the state machine root state as current state.

◆ runEvent()

void Dragengine.StateMachineSystem.SMContext.runEvent ( String  event)

Run event on state machine.

◆ setAction()

void Dragengine.StateMachineSystem.SMContext.setAction ( String  name,
Block  action 
)

Set action for name using block.

◆ setCondition()

void Dragengine.StateMachineSystem.SMContext.setCondition ( String  name,
Block  condition 
)

Set condition for name using block.

◆ setConsole()

void Dragengine.StateMachineSystem.SMContext.setConsole ( Console  console)

Set console or null if not wishing to log anything.

◆ setCurrentState()

void Dragengine.StateMachineSystem.SMContext.setCurrentState ( SMState  state)

Set current state or null if in transition.

If a state is already present the exit actions are run before switching. If state is not null entering actions are run after switching.

Calls onCurrentStateChanged() after all changes are done.

◆ setCurrentStateByID()

void Dragengine.StateMachineSystem.SMContext.setCurrentStateByID ( String  id)

Set current state by identifier or null if in transition.

If a state is already present the exit actions are run before switching. If state is not null entering actions are run after switching.

Calls onCurrentStateChanged() after all changes are done.

◆ setLoggingName()

void Dragengine.StateMachineSystem.SMContext.setLoggingName ( String  name)

Set logging name to tell apart logs.

◆ setLogStateChanges()

void Dragengine.StateMachineSystem.SMContext.setLogStateChanges ( bool  logStateChanges)

Set log state machine state changes.

◆ setLogTransitions()

void Dragengine.StateMachineSystem.SMContext.setLogTransitions ( bool  logSteps)

Set log state machine steps.

◆ writeToFile()

void Dragengine.StateMachineSystem.SMContext.writeToFile ( PersistencyEnvironment  env,
FileWriter  writer 
)

Write state to file.


The documentation for this class was generated from the following file: