Documentation ¶
Index ¶
- type DefaultStateMachine
- func (sm *DefaultStateMachine[E]) ChangeState(newState State[E])
- func (sm *DefaultStateMachine[E]) HandleMessage(message interface{}) bool
- func (sm *DefaultStateMachine[E]) IsInState(state State[E]) bool
- func (sm *DefaultStateMachine[E]) RevertToPreviousState() bool
- func (sm *DefaultStateMachine[E]) SetInitialState(state State[E])
- func (sm *DefaultStateMachine[E]) Update()
- type EmptyState
- type State
- type StateMachine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultStateMachine ¶
type DefaultStateMachine[E any] struct { Owner E //状态机拥有者 CurrentState State[E] //当前状态 PreviousState State[E] //之前状态 GlobalState State[E] //全局状态,每个State Update都会调用 }
DefaultStateMachine 默认状态机管理器 另外可实现堆栈状态机,可依次返回之前状态 ,如菜单列表
func (*DefaultStateMachine[E]) ChangeState ¶
func (sm *DefaultStateMachine[E]) ChangeState(newState State[E])
func (*DefaultStateMachine[E]) HandleMessage ¶
func (sm *DefaultStateMachine[E]) HandleMessage(message interface{}) bool
func (*DefaultStateMachine[E]) IsInState ¶
func (sm *DefaultStateMachine[E]) IsInState(state State[E]) bool
func (*DefaultStateMachine[E]) RevertToPreviousState ¶
func (sm *DefaultStateMachine[E]) RevertToPreviousState() bool
func (*DefaultStateMachine[E]) SetInitialState ¶
func (sm *DefaultStateMachine[E]) SetInitialState(state State[E])
type EmptyState ¶
type EmptyState[E any] struct { }
EmptyState 空状态,默认实现所有方法
func (*EmptyState[E]) Enter ¶
func (state *EmptyState[E]) Enter(entity E)
func (*EmptyState[E]) Exit ¶
func (state *EmptyState[E]) Exit(entity E)
func (*EmptyState[E]) HandleMessage ¶
func (state *EmptyState[E]) HandleMessage(entity E, message interface{}) bool
func (*EmptyState[E]) Update ¶
func (state *EmptyState[E]) Update(entity E)
type State ¶
type State[E any] interface { Enter(entity E) //状态进入 Update(entity E) //正常定时监测更新 Exit(entity E) //状态退出 HandleMessage(entity E, message interface{}) bool //向当前的状态或全局状态发送消息 }
State 状态
type StateMachine ¶
type StateMachine[E any] interface { Update() //定时监测更新状态 ChangeState(state State[E]) //执行状态转移 RevertToPreviousState() bool //返回到之前状态 true 成功 SetInitialState(state State[E]) //设置初始状态 IsInState(state State[E]) bool //当前状态是否在给定的状态 HandleMessage(message interface{}) bool //处理消息 }
StateMachine 处理实体状态移动或者处理接收到的消息
Click to show internal directories.
Click to hide internal directories.