Otter  0.9.88
2d Game Development Framework based on SFML.Net
 All Classes Namespaces Functions Variables Enumerations Properties
Otter.StateMachine< TState > Class Template Reference

State machine that uses a specific type. This is really meant for using an enum as your list of states. If an enum is used, the state machine will automatically populate the states using methods in the parent Entity that match the name of the enum values. More...

Inherits Otter.Component.

Public Member Functions

 StateMachine ()
 Create a new StateMachine. More...
 
void PopulateMethodsFromEntity (Entity e)
 Finds methods that match the enum state in the Entity. This happens in the Added() method of the component if AutoPopulate is set to true. More...
 
void PopulateMethodsFromEntity ()
 Finds methods that match the enum state in the Entity. This happens in the Added() method of the component if AutoPopulate is set to true. If no Entity is specified, get the methods from the Entity that owns this component. More...
 
void ChangeState (TState state)
 Change the state. Exit will be called on the current state followed by Enter on the new state. If the state machine is currently updating then the state change will not occur until after the update has completed. More...
 
void PushState (TState state)
 Push a state onto a stack of states. The state machine will always run the top of the stack. More...
 
void PopState ()
 Pop the top state on the stack (if there is a stack.) More...
 
override void Update ()
 Update the State Machine. More...
 
void AddTransition (TState fromState, TState toState, Action function)
 Add a transition callback for when going from one state to another. More...
 
void AddState (TState key, Action onEnter, Action onUpdate, Action onExit)
 Add a state with three Actions. More...
 
void AddState (TState key, Action onUpdate)
 Add a state with just an update Action. More...
 
void AddState (TState key, State value)
 Add a state. More...
 
void AddState (TState key, Entity e=null)
 Add a state using reflection to retrieve the approriate methods on the Entity. For example, a key with a value of "Idle" will retrieve the methods "EnterIdle" "UpdateIdle" and "ExitIdle" automatically. More...
 
- Public Member Functions inherited from Otter.Component
virtual void Added ()
 Called when the Component is added to the Entity. More...
 
virtual void Removed ()
 Called when the Component is removed from the Entity. More...
 
void RemoveSelf ()
 Removes the Component from its parent Entity. More...
 
virtual void UpdateFirst ()
 Called during the UpdateFirst on the parent Entity. More...
 
virtual void Render ()
 Called during the Render on the parent Entity. More...
 
virtual void UpdateLast ()
 Called during the UpdateLast on the parent Entity. More...
 
GetComponent< T > ()
 Gets the first Component of type T from this Component's Entity. More...
 
List< T > GetComponents< T > ()
 Gets a list of Components of type T from this Component's Entity. More...
 

Public Attributes

bool AutoPopulate = true
 Determines if the StateMachine will autopopulate its states based off of the values of the Enum. More...
 
- Public Attributes inherited from Otter.Component
Entity Entity
 The parent Entity of the Component. More...
 
bool RenderAfterEntity = true
 Determines if the Component should render after the Entity has rendered. More...
 
bool Visible = true
 Determines if the Component will render. More...
 
float Timer = 0
 How long the Component has been alive (added to an Entity and updated.) More...
 

Properties

TState CurrentState [get, set]
 The current state. More...
 
- Properties inherited from Otter.Component
Scene Scene [get]
 The Scene that the parent Entity is in. More...
 
Collider Collider [get]
 The first Collider of the parent Entity. More...
 
Graphic Graphic [get]
 The first Graphic of the parent Entity. More...
 
List< GraphicGraphics [get]
 The list of Graphics from the parent Entity. More...
 
List< ColliderColliders [get]
 The list of Colliders from the parent Entity. More...
 

Detailed Description

State machine that uses a specific type. This is really meant for using an enum as your list of states. If an enum is used, the state machine will automatically populate the states using methods in the parent Entity that match the name of the enum values.

Say you have an enum named State, and it has the value "Walking" When the state machine is added to the Entity, it will match any methods named: EnterWalking UpdateWalking ExitWalking And use those to build the states. This saves a lot of boilerplate set up code.

Template Parameters
TStateAn enum of states.

Constructor & Destructor Documentation

Otter.StateMachine< TState >.StateMachine ( )

Create a new StateMachine.

Member Function Documentation

void Otter.StateMachine< TState >.AddState ( TState  key,
Action  onEnter,
Action  onUpdate,
Action  onExit 
)

Add a state with three Actions.

Parameters
keyThe key to reference the State with.
onEnterThe method to call when entering this state.
onUpdateThe method to call when updating this state.
onExitThe method to call when exiting this state.
void Otter.StateMachine< TState >.AddState ( TState  key,
Action  onUpdate 
)

Add a state with just an update Action.

Parameters
keyThe key to reference the State with.
onUpdateThe method to call when updating this state.
void Otter.StateMachine< TState >.AddState ( TState  key,
State  value 
)

Add a state.

Parameters
keyThe key to reference the State with.
valueThe State to add.
void Otter.StateMachine< TState >.AddState ( TState  key,
Entity  e = null 
)

Add a state using reflection to retrieve the approriate methods on the Entity. For example, a key with a value of "Idle" will retrieve the methods "EnterIdle" "UpdateIdle" and "ExitIdle" automatically.

Parameters
keyThe key to reference the State with.
void Otter.StateMachine< TState >.AddTransition ( TState  fromState,
TState  toState,
Action  function 
)

Add a transition callback for when going from one state to another.

Parameters
fromStateThe State that is ending.
toStateThe State that is starting.
functionThe Action to run when the machine goes from the fromState to the toState.
void Otter.StateMachine< TState >.ChangeState ( TState  state)

Change the state. Exit will be called on the current state followed by Enter on the new state. If the state machine is currently updating then the state change will not occur until after the update has completed.

Parameters
stateThe state to change to.
void Otter.StateMachine< TState >.PopState ( )

Pop the top state on the stack (if there is a stack.)

void Otter.StateMachine< TState >.PopulateMethodsFromEntity ( Entity  e)

Finds methods that match the enum state in the Entity. This happens in the Added() method of the component if AutoPopulate is set to true.

Parameters
eThe Entity to get methods from.
void Otter.StateMachine< TState >.PopulateMethodsFromEntity ( )

Finds methods that match the enum state in the Entity. This happens in the Added() method of the component if AutoPopulate is set to true. If no Entity is specified, get the methods from the Entity that owns this component.

void Otter.StateMachine< TState >.PushState ( TState  state)

Push a state onto a stack of states. The state machine will always run the top of the stack.

Parameters
stateThe state to push.
override void Otter.StateMachine< TState >.Update ( )
virtual

Update the State Machine.

Reimplemented from Otter.Component.

Member Data Documentation

bool Otter.StateMachine< TState >.AutoPopulate = true

Determines if the StateMachine will autopopulate its states based off of the values of the Enum.

Property Documentation

TState Otter.StateMachine< TState >.CurrentState
getset

The current state.


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