Documentation ¶
Overview ¶
Package aistate implements a minimalistic state machine.
Index ¶
- type State
- type StateMachine
- func (s *StateMachine) AddAnySelector(to func() State, predicate func() bool)
- func (s *StateMachine) AddAnyTransition(to State, predicate func() bool)
- func (s *StateMachine) AddSelector(from State, to func() State, predicate func() bool)
- func (s *StateMachine) AddTransition(from, to State, predicate func() bool)
- func (s *StateMachine) GetTransition() *Transition
- func (s *StateMachine) RevertToPreviousState()
- func (s *StateMachine) SetState(state State)
- func (s *StateMachine) Tick(delta uint64)
- type StateType
- type Transition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type State ¶
type State interface { Type() StateType // Returns the ID of the current state Tick(delta uint64) // Advances the state and provides the 'delta' time elapsed. OnEnter() // Hooks executed when transitioning to this state OnExit() // Hooks executed when transitioning from this state }
State defines an interface for a current state.
type StateMachine ¶
StateMachine implements a simple state machine.
func (*StateMachine) AddAnySelector ¶
func (s *StateMachine) AddAnySelector(to func() State, predicate func() bool)
AddAnySelector adds a new transition that does not depend on a prior state, but only on the return value of 'predicate' and returns a state returned by to().
func (*StateMachine) AddAnyTransition ¶
func (s *StateMachine) AddAnyTransition(to State, predicate func() bool)
AddAnyTransition adds a new transition that does not depend on a prior state, but only on the return value of 'predicate'.
func (*StateMachine) AddSelector ¶
func (s *StateMachine) AddSelector(from State, to func() State, predicate func() bool)
AddSelector adds a new transition from a state to another returned by to() when predicate returns true.
func (*StateMachine) AddTransition ¶
func (s *StateMachine) AddTransition(from, to State, predicate func() bool)
AddTransition adds a new transition from a state to another when predicate returns true.
func (*StateMachine) GetTransition ¶
func (s *StateMachine) GetTransition() *Transition
GetTransition returns the next valid transition.
func (*StateMachine) RevertToPreviousState ¶
func (s *StateMachine) RevertToPreviousState()
RevertToPreviousState sets the current state of the state machine to its previous state.
func (*StateMachine) SetState ¶
func (s *StateMachine) SetState(state State)
SetState sets the current state of the state machine.
func (*StateMachine) Tick ¶
func (s *StateMachine) Tick(delta uint64)
Tick advances the state machine by 'delta' (time elapsed since last tick).
type Transition ¶
type Transition struct {
// contains filtered or unexported fields
}
Transition represents a transition to a specific state. TODO: Consider two different transition types, one with to as a function and one with to as a specific state (if performance is impacted by to being a function)