Drag[en]gine Script Module DragonScript 1.35
Loading...
Searching...
No Matches
Dragengine.StateMachineSystem.SMContext Class Reference

State machine context. More...

Inheritance diagram for Dragengine.StateMachineSystem.SMContext:

Public Member Functions

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

Public Attributes

Dictionary pConditions
Console pConsole
SMState pCurrentState
Array pDelayedEvents
Object pEventParameter
String pLoggingName
bool pLogTransitions
StateMachine pStateMachine

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

◆ addActionsFromContext()

void Dragengine.StateMachineSystem.SMContext.addActionsFromContext ( SMContext context)

Add actions from another context.

Version
1.35

References forEachCondition().

Referenced by writeToFile().

◆ addConditionsFromContext()

void Dragengine.StateMachineSystem.SMContext.addConditionsFromContext ( SMContext context)

Add conditions from another context.

Version
1.35

Referenced by getLogStateChanges(), and writeToFile().

◆ forEachAction()

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

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

References pStateMachine.

Referenced by runEvent().

◆ forEachCondition()

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

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

Referenced by addActionsFromContext().

◆ getAction()

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

Action for name or null if absent.

References setStateMachine().

Referenced by setLogActions().

◆ getCondition()

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

Condition for name or null if absent.

References pCurrentState.

Referenced by removeAction().

◆ getConditionCount()

int Dragengine.StateMachineSystem.SMContext.getConditionCount ( )

Count of conditions.

References pConditions, and pStateMachine.

Referenced by setAction().

◆ getConsole()

Console Dragengine.StateMachineSystem.SMContext.getConsole ( )

Console or null if not wishing to log anything.

References pConditions.

Referenced by writeToFile().

◆ getCurrentState()

SMState Dragengine.StateMachineSystem.SMContext.getCurrentState ( )

Current state or null if in transition.

References pConditions, and setCondition().

Referenced by writeToFile().

◆ getEventParameter()

Object Dragengine.StateMachineSystem.SMContext.getEventParameter ( )

Event parameter or null.

Version
1.26

References hasAction().

Referenced by writeToFile().

◆ getLogActions()

bool Dragengine.StateMachineSystem.SMContext.getLogActions ( )

Log actions.

Version
1.26

Referenced by writeToFile().

◆ getLoggingName()

String Dragengine.StateMachineSystem.SMContext.getLoggingName ( )

Logging name to tell apart logs.

References pConditions, and removeCondition().

Referenced by writeToFile().

◆ getLogStateChanges()

bool Dragengine.StateMachineSystem.SMContext.getLogStateChanges ( )

Log state machine state changes.

References addConditionsFromContext().

Referenced by writeToFile().

◆ getLogTransitions()

bool Dragengine.StateMachineSystem.SMContext.getLogTransitions ( )

Log state machine steps.

References pConditions.

Referenced by writeToFile().

◆ getStateMachine()

StateMachine Dragengine.StateMachineSystem.SMContext.getStateMachine ( )

State machine.

Referenced by removeCondition().

◆ hasAction()

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

Action is present.

Referenced by getEventParameter().

◆ hasCondition()

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

Condition is present.

References pConsole, pLoggingName, and pLogTransitions.

Referenced by removeAllActions().

◆ 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.

References pConditions, pCurrentState, pLoggingName, and pStateMachine.

◆ 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.

◆ readFromFile()

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

Read state from file.

Referenced by writeToFile().

◆ removeAction()

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

Remove action.

References getCondition().

Referenced by writeToFile().

◆ removeAllActions()

void Dragengine.StateMachineSystem.SMContext.removeAllActions ( )

Remove all actions.

References hasCondition(), and pConditions.

Referenced by writeToFile().

◆ removeAllConditions()

void Dragengine.StateMachineSystem.SMContext.removeAllConditions ( )

Remove all conditions.

Referenced by setLoggingName().

◆ removeCondition()

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

Remove condition.

References getStateMachine(), and pStateMachine.

Referenced by getLoggingName().

◆ runEvent() [1/2]

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

Run event on state machine.

References forEachAction().

Referenced by writeToFile().

◆ runEvent() [2/2]

void Dragengine.StateMachineSystem.SMContext.runEvent ( String event,
Object parameter )

Run event on state machine with parameter.

References setAction().

◆ setAction() [1/2]

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

Set action for name using block.

References getConditionCount(), and pConditions.

◆ setAction() [2/2]

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

Set action for name.

Referenced by runEvent(), and writeToFile().

◆ setCondition() [1/2]

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

Set condition for name using block.

◆ setCondition() [2/2]

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

Set condition for name.

References pCurrentState.

Referenced by getCurrentState(), and setCurrentState().

◆ setConsole()

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

Set console or null if not wishing to log anything.

Referenced by writeToFile().

◆ 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.

References setCondition().

Referenced by writeToFile().

◆ setLogActions()

void Dragengine.StateMachineSystem.SMContext.setLogActions ( bool logActions)

Set actions.

References getAction().

Referenced by writeToFile().

◆ setLoggingName()

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

Set logging name to tell apart logs.

References removeAllConditions().

Referenced by writeToFile().

◆ setLogStateChanges()

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

Set log state machine state changes.

References pConditions.

Referenced by writeToFile().

◆ setLogTransitions()

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

Set log state machine steps.

Referenced by writeToFile().

◆ setStateMachine()

void Dragengine.StateMachineSystem.SMContext.setStateMachine ( StateMachine stateMachine)

Set state machine and reset state.

Version
1.26

Sets the state machine then calls reset(). If you change the state machine during runtime you have to make sure it is also set before readFromFile() is called otherwise an exception can be thrown.

Referenced by getAction().

◆ writeToFile()

Member Data Documentation

◆ pConditions

Dictionary Dragengine.StateMachineSystem.SMContext.pConditions

◆ pConsole

Console Dragengine.StateMachineSystem.SMContext.pConsole

Referenced by hasCondition(), and writeToFile().

◆ pCurrentState

SMState Dragengine.StateMachineSystem.SMContext.pCurrentState

◆ pDelayedEvents

Array Dragengine.StateMachineSystem.SMContext.pDelayedEvents

Referenced by writeToFile().

◆ pEventParameter

Object Dragengine.StateMachineSystem.SMContext.pEventParameter

Referenced by writeToFile().

◆ pLoggingName

String Dragengine.StateMachineSystem.SMContext.pLoggingName

Referenced by hasCondition(), new(), and writeToFile().

◆ pLogTransitions

bool Dragengine.StateMachineSystem.SMContext.pLogTransitions

Referenced by hasCondition(), and writeToFile().

◆ pStateMachine

StateMachine Dragengine.StateMachineSystem.SMContext.pStateMachine

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