Finite state machines
Creating a finite state machine (FSM) for modeling logic will resemble the animation state machines we've created previously, except that transitioning to a new state within the state machine is handled automatically through the evaluation of transitions. Once one evaluator returns true, the state machine will transition to the new state and invoke the associated state's action.
States
States within an FSM are responsible for associating an action with the state. We create a state by passing an action and naming the state for debug convenience:
FiniteState.lua
:
require "Action"; require "FiniteState"; require "FiniteStateTransition"; FiniteState = {}; function FiniteState.new(name, action) local state = {}; -- The FiniteState's data members. state.name_ = name; state.action_ = action; return state; end
Transitions
Transitions encapsulate the state to be transitioned to as well as the evaluator that determines whether the transition should...