Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertAnyValue[T any](v any, ok bool) (T, bool)
- func LogWithUpstream(brain IBrain, logg *zap.Logger) *zap.Logger
- func MapValue[T any](m Memory, key string) (T, bool)
- func Print(node INode, brain IBrain)
- type AbortMode
- type BaseProperties
- type Blackboard
- func (b *Blackboard) AddObserver(key string, observer Observer)
- func (b *Blackboard) Del(key string)
- func (b *Blackboard) Get(key string) (any, bool)
- func (b *Blackboard) GetDuration(key string) (time.Duration, bool)
- func (b *Blackboard) NodeExt(nodeID string) Memory
- func (b *Blackboard) NodeMemory(nodeID string) *NodeMemory
- func (b *Blackboard) RemoveObserver(key string, observer Observer)
- func (b *Blackboard) Set(key string, val any)
- func (b *Blackboard) Start()
- func (b *Blackboard) Stop()
- func (b *Blackboard) ThreadID() int
- func (b *Blackboard) TreeMemory(rootID string) Memory
- type BrainContextKey
- type Composite
- func (c *Composite) AbortLowerPriorityChildrenForChild(brain IBrain, childAbortBy INode)
- func (c *Composite) AddChild(child INode)
- func (c *Composite) AddChildren(children []INode)
- func (c *Composite) Children() []INode
- func (c *Composite) Finish(brain IBrain, succeeded bool)
- func (c *Composite) SetRoot(brain IBrain, root IRoot)
- type Container
- type Decorator
- func (d *Decorator) CanDynamicDecorate() bool
- func (d *Decorator) CompositeAncestorFinished(brain IBrain, composite IComposite)
- func (d *Decorator) Decorate(decorated INode)
- func (d *Decorator) Decorated(brain IBrain) INode
- func (d *Decorator) Finish(brain IBrain, succeeded bool)
- func (d *Decorator) InitNodeWorker(worker INodeWorker) error
- func (d *Decorator) OnAbort(brain IBrain)
- func (d *Decorator) SetRoot(brain IBrain, root IRoot)
- type DelegateMeta
- type DynamicBehaviorMode
- type EventType
- type FinishEvent
- type FinishMode
- type IBlackboard
- type IBlackboardInternal
- type IBrain
- type IBrainInternal
- type IComposite
- type IContainer
- type IContainerWorker
- type IDecorator
- type IDecoratorWorker
- type INode
- type INodeWorker
- type IObservingProperties
- type IObservingWorker
- type IRoot
- type LogOption
- type Memory
- type Node
- func (n *Node) Abort(brain IBrain)
- func (n *Node) CanMountTo() bool
- func (n *Node) Category() string
- func (n *Node) CompositeAncestorFinished(brain IBrain, composite IComposite)
- func (n *Node) CopyTo(target *Node)
- func (n *Node) Delegator() config.DelegatorCfg
- func (n *Node) DynamicMount(brain IBrain, parent IContainer)
- func (n *Node) Finish(brain IBrain, succeeded bool)
- func (n *Node) HasDelegatorOrScript() bool
- func (n *Node) ID() string
- func (n *Node) Init(cfg *config.NodeCfg) error
- func (n *Node) InitNodeWorker(worker INodeWorker) error
- func (n *Node) IsAborting(brain IBrain) bool
- func (n *Node) IsActive(brain IBrain) bool
- func (n *Node) IsInactive(brain IBrain) bool
- func (n *Node) Log(brain IBrain, ops ...LogOption) *zap.Logger
- func (n *Node) Memory(brain IBrain) *NodeMemory
- func (n *Node) Name() string
- func (n *Node) NodeWorker() INodeWorker
- func (n *Node) NodeWorkerAsNode() INode
- func (n *Node) OnAbort(brain IBrain)
- func (n *Node) OnCompositeAncestorFinished(brain IBrain, composite IComposite)
- func (n *Node) OnStart(brain IBrain)
- func (n *Node) OnString(brain IBrain) string
- func (n *Node) OnUpdate(brain IBrain, eventType EventType, delta time.Duration) Result
- func (n *Node) Parent(brain IBrain) IContainer
- func (n *Node) Path(brain IBrain) string
- func (n *Node) Properties() any
- func (n *Node) PropertiesClassProvider() any
- func (n *Node) RawCfg() *config.NodeCfg
- func (n *Node) Root(brain IBrain) IRoot
- func (n *Node) SetParent(parent IContainer)
- func (n *Node) SetRoot(brain IBrain, root IRoot)
- func (n *Node) SetUpstream(brain IBrain, upstream INode)
- func (n *Node) Start(brain IBrain)
- func (n *Node) State(brain IBrain) NodeState
- func (n *Node) String(brain IBrain) string
- func (n *Node) Title() string
- func (n *Node) Update(brain IBrain, eventType EventType, delta time.Duration) Result
- type NodeMemory
- type NodeState
- type Observer
- type ObservingDecorator
- func (o *ObservingDecorator) AbortMode() AbortMode
- func (o *ObservingDecorator) ConditionMet(brain IBrain, args ...any) bool
- func (o *ObservingDecorator) Evaluate(brain IBrain, args ...any)
- func (o *ObservingDecorator) InitNodeWorker(worker INodeWorker) error
- func (o *ObservingDecorator) OnAbort(brain IBrain)
- func (o *ObservingDecorator) OnChildFinished(brain IBrain, child INode, succeeded bool)
- func (o *ObservingDecorator) OnCompositeAncestorFinished(brain IBrain, composite IComposite)
- func (o *ObservingDecorator) OnStart(brain IBrain)
- func (o *ObservingDecorator) PropertiesClassProvider() any
- func (o *ObservingDecorator) StartObserving(brain IBrain)
- func (o *ObservingDecorator) StopObserving(brain IBrain)
- type ObservingProperties
- type OpType
- type Operator
- type ParallelMemory
- type Result
- type Root
- func (r *Root) CanMountTo() bool
- func (r *Root) Finish(brain IBrain, succeeded bool)
- func (r *Root) Interval() time.Duration
- func (r *Root) IsSubTree(brain IBrain) bool
- func (r *Root) OnAbort(brain IBrain)
- func (r *Root) OnChildFinished(brain IBrain, child INode, succeeded bool)
- func (r *Root) OnStart(brain IBrain)
- func (r *Root) PropertiesClassProvider() any
- func (r *Root) SafeAbort(brain IBrain, abortChan chan *FinishEvent)
- func (r *Root) SafeStart(brain IBrain, force bool)
- func (r *Root) SetRoot(brain IBrain, root IRoot)
- func (r *Root) Start(brain IBrain)
- type Task
Constants ¶
const ( CategoryComposite = "composite" // 组合节点 CategoryDecorator = "decorator" // 组合节点 CategoryTask = "task" // 组合节点 )
节点类别
const ( NodeNameRoot = "Root" NodeNameSubtree = "Subtree" NodeNameDynamicSubtree = "DynamicSubtree" )
节点名称
const DefaultInterval = time.Millisecond * 50 // 行为树默认更新间隔
Variables ¶
var ErrBlackboardAlreadyStarted = stderr.New("blackboard already started")
var ErrBlackboardAlreadyStopped = stderr.New("blackboard already stopped")
var ErrConvertGenericType = errors.New("convert generic type error")
Functions ¶
func ConvertAnyValue ¶
ConvertAnyValue [T any] 转换 any 类型的值为传入的范型,一般配合map使用
@param v 值 @param ok 值是否有效 @return T @return bool
func LogWithUpstream ¶ added in v1.1.2
Types ¶
type Blackboard ¶
type Blackboard struct {
// contains filtered or unexported fields
}
Blackboard
@implement IBlackboard @implement IBlackboardInternal get和set为线程安全,其他方法均为非线程安全,请在树自己的线程内调用 黑板的[生命周期调用,监听添加移除,监听函数的执行]必须派发到AI独立线程 黑板的kv读写可以在任意线程 黑板为树形结构,实例化时可指定父黑板,将继承父黑板的KV.父黑板,一般来说是AI集群的共享黑板。想实现AI间通信时这将很有用.
func NewBlackboard ¶
func NewBlackboard(threadID int, parent *Blackboard) *Blackboard
NewBlackboard 实例化一个黑板
@param threadID AI工作线程ID @param parent 父黑板,一般来说是AI集群的共享黑板 @return *Blackboard
func (*Blackboard) AddObserver ¶
func (b *Blackboard) AddObserver(key string, observer Observer)
AddObserver
@implement IBlackboardInternal.AddObserver @receiver b @param key @param observer
func (*Blackboard) Del ¶
func (b *Blackboard) Del(key string)
Del
@implement IBlackboard.Del @receiver b @param key
func (*Blackboard) Get ¶
func (b *Blackboard) Get(key string) (any, bool)
Get
@implement IBlackboard.Get @receiver b @param key @return any @return bool
func (*Blackboard) GetDuration ¶
func (b *Blackboard) GetDuration(key string) (time.Duration, bool)
GetDuration
@implement IBlackboard.GetDuration @receiver b @param key @return time.Duration @return bool
func (*Blackboard) NodeExt ¶
func (b *Blackboard) NodeExt(nodeID string) Memory
NodeExt
@implement IBlackboardInternal.NodeExt @receiver b @param nodeID @return Memory
func (*Blackboard) NodeMemory ¶
func (b *Blackboard) NodeMemory(nodeID string) *NodeMemory
NodeMemory
@implement IBlackboardInternal.NodeMemory @receiver b @param nodeID @return *NodeMemory
func (*Blackboard) RemoveObserver ¶
func (b *Blackboard) RemoveObserver(key string, observer Observer)
RemoveObserver
@implement IBlackboardInternal.RemoveObserver @receiver b @param key @param observer
func (*Blackboard) Set ¶
func (b *Blackboard) Set(key string, val any)
Set
@implement IBlackboard.Set @receiver b @param key @param val
func (*Blackboard) Start ¶
func (b *Blackboard) Start()
Start
@implement IBlackboardInternal.Start @receiver b
func (*Blackboard) Stop ¶
func (b *Blackboard) Stop()
Stop
@implement IBlackboardInternal.Stop @receiver b
func (*Blackboard) ThreadID ¶
func (b *Blackboard) ThreadID() int
func (*Blackboard) TreeMemory ¶
func (b *Blackboard) TreeMemory(rootID string) Memory
TreeMemory
@implement IBlackboardInternal.TreeMemory @receiver b @param rootID @return Memory
type BrainContextKey ¶ added in v1.1.2
type BrainContextKey string
type Composite ¶
type Composite struct { Container // contains filtered or unexported fields }
Composite 复合节点基类
@implement IComposite
func (*Composite) AbortLowerPriorityChildrenForChild ¶
AbortLowerPriorityChildrenForChild panic实现不可继承,子类须自行实现 IComposite.AbortLowerPriorityChildrenForChild
@receiver c @param childAbortBy
func (*Composite) AddChildren ¶
type Container ¶
type Container struct { Node IContainerWorker }
Container 容器基类
@implement IContainer @implement IContainerWorker
func (*Container) ChildFinished ¶
ChildFinished
@implement IContainer.ChildFinished @receiver c @param brain @param child @param succeeded
func (*Container) InitNodeWorker ¶
func (c *Container) InitNodeWorker(worker INodeWorker) error
InitNodeWorker
@override Node.InitNodeWorker @receiver c @param worker
type Decorator ¶
type Decorator struct { Container IDecoratorWorker // contains filtered or unexported fields }
Decorator 装饰器基类
@implement IDecorator
func (*Decorator) CanDynamicDecorate ¶
CanDynamicDecorate
@implement IDecoratorWorker.CanDynamicDecorate @receiver d @return bool
func (*Decorator) CompositeAncestorFinished ¶
func (d *Decorator) CompositeAncestorFinished(brain IBrain, composite IComposite)
CompositeAncestorFinished
@override Node.CompositeAncestorFinished @receiver n @param brain @param composite
func (*Decorator) InitNodeWorker ¶
func (d *Decorator) InitNodeWorker(worker INodeWorker) error
InitNodeWorker
@override Node.InitNodeWorker @receiver c @param worker
type DelegateMeta ¶
type DynamicBehaviorMode ¶ added in v1.0.3
type DynamicBehaviorMode int
DynamicBehaviorMode 动态子树中断模式,描述的是装饰器动态挂载子树时若旧子树正在运行应该如何处理
const ( DynamicBehaviorModeRestart DynamicBehaviorMode = iota // 动态挂载子树时,若正在运行则重启装饰器 DynamicBehaviorModeContinue // 动态挂载子树时,不做任何行为,即不中断正在运行的子树 DynamicBehaviorModeAbort // 态挂载子树时,若正在运行则中断装饰器 )
type FinishEvent ¶ added in v1.0.3
type FinishMode ¶
type FinishMode int
FinishMode 平行节点的完成模式
const ( FinishModeOne FinishMode = iota // 只要有一个子节点完成就完成 FinishModeAll // 全部子节点完成才完成 )
type IBlackboard ¶
type IBlackboard interface { // Get 获取Value,可链式传给 ConvertAnyValue[T]来转换类型 // @receiver b // @param key // @return any // @return bool Get(key string) (any, bool) // GetDuration 获取 time.Duration 类型的值,支持 int64 | string | time.Duration. string 格式参考 time.ParseDuration // @receiver b // @param key // @return time.Duration // @return bool GetDuration(key string) (time.Duration, bool) // Set 设置KV(用户域) // 线程安全 // @receiver b // @param key // @param val Set(key string, val any) // Del 删除KV // 线程安全 // @receiver b // @param key Del(key string) }
IBlackboard 黑板,AI行为树实例的记忆
type IBlackboardInternal ¶
type IBlackboardInternal interface { IBlackboard // ThreadID 获取线程ID // @return int ThreadID() int // Start 启动,将会开始监听kv // 私有,框架内部使用 // 非线程安全 // @receiver b Start() // Stop 停止,将会停止监听kv // 私有,框架内部使用 // 非线程安全 // @receiver b Stop() AddObserver(key string, observer Observer) RemoveObserver(key string, observer Observer) // TreeMemory 树数据 // @param rootID // @return Memory TreeMemory(rootID string) Memory // NodeExt 节点的数据(扩展) // @param nodeID // @return Memory NodeExt(nodeID string) Memory // NodeMemory 节点的数据(固定) // @param nodeID // @return *NodeMemory NodeMemory(nodeID string) *NodeMemory }
IBlackboardInternal 框架内或自定义节点时使用的黑板,从 IBlackboard 转化来
含有私有API,业务层请勿调用,避免引发不可预期的后果
type IBrain ¶
type IBrain interface { // FinishChan 树运行结束的信道 // @return <-chan FinishChan() <-chan *FinishEvent SetFinishChan(finishChan chan *FinishEvent) // Blackboard 获取黑板 // @return IBlackboard Blackboard() IBlackboard // GetDelegate 获取委托 // @param name // @return delegate // @return ok GetDelegate(name string) (delegate any, ok bool) // Go 在 IBrain 的独立线程里执行任务 // @param task Go(task func()) // RunningTree 正在执行的树 // @return IRoot RunningTree() IRoot // Running 是否有正在执行的树 // // 非线程安全 // @return bool Running() bool // Abort 终止正在运行的行为树 // 线程安全 // // @param abortChan Abort(abortChan chan *FinishEvent) // Run 异步启动 // // @param tag // @param force 是否强制终止正在运行的树 Run(tag string, force bool) // DynamicDecorate 给正在运行的树动态挂载子树 // // 非线程安全,调用方自己保证 // // @receiver b // @param containerTag 动态子树容器的tag // @param subtreeTag 子树的tag // @return error DynamicDecorate(containerTag string, subtreeTag string) error Cron(interval time.Duration, randomDeviation time.Duration, task func()) *timingwheel.Timer After(interval time.Duration, randomDeviation time.Duration, task func()) *timingwheel.Timer }
IBrain 大脑=行为树+记忆+委托对象集合. 也可以理解为上下文
type IBrainInternal ¶ added in v1.0.2
type IBrainInternal interface { // OnNodeUpdate 供节点回调执行委托 // @receiver b // @param target // @param method // @param brain // @param eventType // @param delta // @return bcore.Result OnNodeUpdate(target string, method string, brain IBrain, eventType EventType, delta time.Duration) Result // GetDelegates 获取委托map拷贝 // @receiver b // @return map[string]any GetDelegates() map[string]any RWFinishChan() chan *FinishEvent SetRunningTree(root IRoot) Context() context.Context SetContext(ctx context.Context) }
IBrainInternal 框架内部使用的 Brain
type IComposite ¶
type IComposite interface { IContainer AddChild(child INode) AddChildren(children []INode) Children() []INode // AbortLowerPriorityChildrenForChild 中断低优先级分支 // 子类必须覆写 // @param childAbortBy 发起中断请求的子节点 AbortLowerPriorityChildrenForChild(brain IBrain, childAbortBy INode) }
IComposite 复合节点
type IContainer ¶
type IContainer interface { INode // ChildFinished 收到子节点停止结束的调用 // IContainer 的子节点须在 INode.Finish 中调用 父节点的 ChildFinished 以通知父节点,父节点再根据自己的控制逻辑决定是否回溯 // 停止链路请参看 Abort // @param child // @param succeeded ChildFinished(brain IBrain, child INode, succeeded bool) }
IContainer 容器:可以挂载子节点的节点
type IContainerWorker ¶
type IContainerWorker interface { // OnChildFinished IContainer.ChildFinished 的回调 // @param child // @param succeeded OnChildFinished(brain IBrain, child INode, succeeded bool) }
IContainerWorker Container 的回调,Container 的子类必须实现该接口
type IDecorator ¶
type IDecorator interface { INode // Decorate 装饰子节点 // @param decorated Decorate(decorated INode) // Decorated 获取被装饰节点 // @receiver d // @return INode Decorated(brain IBrain) INode IDecoratorWorker }
IDecorator 装饰器,修饰子节点
type IDecoratorWorker ¶
type IDecoratorWorker interface { // CanDynamicDecorate 能否动态更换子节点 // @return bool CanDynamicDecorate() bool }
type INode ¶
type INode interface { // InitNodeWorker 设置回调接口,应该委托给继承树中的叶子子类实现 // @param worker InitNodeWorker(worker INodeWorker) error // NodeWorker 获取回调委托(子类对象) // @return INodeWorker NodeWorker() INodeWorker // NodeWorkerAsNode 获取子类对象 // // @return INode NodeWorkerAsNode() INode // Init 根据配置加载节点实例 // @param cfg Init(cfg *config.NodeCfg) error // Memory 节点数据 // @receiver n // @param brain // @return *NodeMemory Memory(brain IBrain) *NodeMemory ID() string Title() string Category() string Properties() any Name() string RawCfg() *config.NodeCfg Delegator() config.DelegatorCfg // HasDelegatorOrScript 是否存在委托方法或脚本 // @return bool HasDelegatorOrScript() bool State(brain IBrain) NodeState IsActive(brain IBrain) bool IsInactive(brain IBrain) bool IsAborting(brain IBrain) bool // Root 获取root // 注意由于行为数是单例,如果当前节点是root(子树root),只应该从黑板设置和获取root // @return IRoot Root(brain IBrain) IRoot // SetRoot 设置根节点 // 注意由于行为数是单例,这里只能设置当前所在子树的root. // @param root SetRoot(brain IBrain, root IRoot) SetUpstream(brain IBrain, upstream INode) // Start 开始执行 非线程安全,上层须自行封装线程安全的方法 // @param brain Start(brain IBrain) // Abort 中断(终止)执行 非线程安全,上层须自行封装线程安全的方法 // 一般来说只应该由 IDecorator 调用 // 一般来说,中断链路为: // 节点A Abort-> A INodeWorker.OnAbort-> 子节点B Abort (其他所有子结点同理)-> B INodeWorker.OnAbort-> B Finish-> A IContainer.ChildFinished-> <所有子节点都完成了?true:> A Finish-> 继续按上诉链路回溯上一层 // @param brain Abort(brain IBrain) // Finish 完成执行 // 这里是真正的停止,会将执行结果 Result 回溯给父节点 // 注意: Finish 应该是你的最后一个调用,在调用 Finish 后不要再修改任何状态或调用任何东西,否则将产生不可预知的后果 // 一般来说,停止链路为: // 节点B Finish-> 父节点A IContainer.ChildFinished-> <所有子节点都完成了?true:> A Finish-> 继续按上诉链路回溯上一层 // @param brain // @param succeeded Finish(brain IBrain, succeeded bool) // CompositeAncestorFinished 最近的 IComposite 类型的祖先节点关闭时调用 // 由于直接父节点可能是装饰节点,所以这里特指“最近的 IComposite 类型的祖先节点” // @param brain // @param composite CompositeAncestorFinished(brain IBrain, composite IComposite) String(brain IBrain) string Path(brain IBrain) string // Parent 获取父节点 // @return IContainer Parent(brain IBrain) IContainer // SetParent 设置父节点/或者静态挂载.注意不要设置成父节点的父类对象了(若拿到的是父类对象,应该调用 NodeWorker 来获取具体的子类对象). // @param parent SetParent(parent IContainer) // DynamicMount 将自己作为子树动态挂载到 parent // @param brain // @param parent DynamicMount(brain IBrain, parent IContainer) Log(brain IBrain, ops ...LogOption) *zap.Logger }
INode 节点
继承自 Node 的自定义节点须实现 INodeWorker 一般来说,继承自 Node 的子类不应覆写该接口
type INodeWorker ¶
type INodeWorker interface { // OnStart Node.Start 的回调 // @param brain OnStart(brain IBrain) // OnAbort Node.Abort 的回调 // @param brain OnAbort(brain IBrain) // PropertiesClassProvider 提供用于解析 Node.properties 的类的零值. Node.Init 的回调 // @param properties PropertiesClassProvider() any // OnCompositeAncestorFinished Node.CompositeAncestorFinished 的回调 // 目前仅用来给装饰器移除监察函数 // @param brain // @param composite OnCompositeAncestorFinished(brain IBrain, composite IComposite) // CanMountTo 是否可以挂载到目标容器节点上,会被 Node.Parent 和 Node.SetParent 回调 // @return bool CanMountTo() bool // OnString Node.String 的回调 // @param brain // @return string OnString(brain IBrain) string }
INodeWorker Node 中会回调的方法,应该委托给继承树中的叶子子类实现
继承 Node 须覆写该接口
type IObservingProperties ¶
type IObservingProperties interface {
GetAbortMode() AbortMode
}
IObservingProperties 观察者装饰器属性
type IObservingWorker ¶
type IObservingWorker interface { // StartObserving 开始监听 // @param brain StartObserving(brain IBrain) // StopObserving 停止监听 // @param brain StopObserving(brain IBrain) // ConditionMet 计算条件是否满足 // @param brain // @param args... 透传参数,由 ObservingDecorator.Evaluate 传递过来 // @return bool ConditionMet(brain IBrain, args ...any) bool }
IObservingWorker ObservingDecorator 的回调,ObservingDecorator 的子类必须实现该接口
type IRoot ¶
type IRoot interface { IDecorator // IsSubTree 是否父节点 // @param brain // @return bool IsSubTree(brain IBrain) bool // Interval 该树默认刷新间隔时间 // @return time.Duration Interval() time.Duration // SafeStart 启动行为树. // // 线程安全 // @receiver r // @param brain // SafeStart 启动行为树. // // @param brain // @param force 是否强制启动.若root是激活状态,true则先终止再启动,false则原tree继续运行只报错不重启. SafeStart(brain IBrain, force bool) // SafeAbort 终止行为树 // // 线程安全 // @param brain // @param abortChan SafeAbort(brain IBrain, abortChan chan *FinishEvent) }
type Node ¶
type Node struct { INodeWorker // contains filtered or unexported fields }
Node 节点基类
@implement INode @implement INodeWorker
func (*Node) CanMountTo ¶ added in v1.0.7
CanMountTo
@implement INodeWorker.CanMountTo @receiver n @return bool
func (*Node) CompositeAncestorFinished ¶
func (n *Node) CompositeAncestorFinished(brain IBrain, composite IComposite)
CompositeAncestorFinished
@implement INode.CompositeAncestorFinished @receiver n @param brain @param composite
func (*Node) CopyTo ¶ added in v1.0.7
CopyTo 拷贝所有成员到 target @implement INode.CopyTo
@receiver n @param target 新的零值 Node
func (*Node) Delegator ¶
func (n *Node) Delegator() config.DelegatorCfg
func (*Node) DynamicMount ¶
func (n *Node) DynamicMount(brain IBrain, parent IContainer)
DynamicMount
@implement INode.DynamicMount @receiver n @param brain @param parent
func (*Node) HasDelegatorOrScript ¶ added in v1.0.2
func (*Node) InitNodeWorker ¶
func (n *Node) InitNodeWorker(worker INodeWorker) error
InitNodeWorker
@implement INode.InitNodeWorker @receiver n @param worker
func (*Node) IsAborting ¶
func (*Node) IsInactive ¶
func (*Node) Memory ¶
func (n *Node) Memory(brain IBrain) *NodeMemory
Memory 节点数据
@implement INode.Memory @receiver n @param brain @return *NodeMemory
func (*Node) NodeWorker ¶
func (n *Node) NodeWorker() INodeWorker
NodeWorker
@implement INode.NodeWorker @receiver n @return INodeWorker
func (*Node) NodeWorkerAsNode ¶ added in v1.0.6
NodeWorkerAsNode
@implement INode.NodeWorkerAsNode
@receiver n @return INode
func (*Node) OnCompositeAncestorFinished ¶
func (n *Node) OnCompositeAncestorFinished(brain IBrain, composite IComposite)
OnCompositeAncestorFinished
@implement INodeWorker.OnCompositeAncestorFinished @receiver n @param brain @param composite
func (*Node) Parent ¶
func (n *Node) Parent(brain IBrain) IContainer
Parent
@implement INode.Parent() @receiver n @return IContainer
func (*Node) Properties ¶
func (*Node) PropertiesClassProvider ¶
PropertiesClassProvider
@implement INodeWorker.PropertiesClassProvider @receiver n @return any
func (*Node) SetParent ¶
func (n *Node) SetParent(parent IContainer)
SetParent
@implement INode.SetParent @receiver n @param parent
func (*Node) SetUpstream ¶ added in v1.1.2
type NodeMemory ¶
type NodeMemory struct { Ext Memory // 扩展数据,给框架之外的自定义节点使用 State NodeState // 节点状态 MountParent IContainer // 动态挂载的父节点,仅 Root 有效 DynamicChild INode // 动态挂载的子节点 RequestDynamicChild INode // 请求挂载的子节点,延迟到旧的分支执行完成后才真正挂载到 DynamicChild DynamicRoot IRoot // 动态子树的根节点 Observing bool // 是否监听中,仅 ObservingDecorator 及其派生类有效 // 根据节点类型意义不同: // 1.非随机组合节点:当前运行中的子节点索引; // 2.随机组合节点:完成了几个子节点; // 3.循环装饰器:当前为第几次循环 CurrIndex int ChildrenOrder []int // 孩子节点排序索引 Parallel *ParallelMemory // 并发节点的数据 CronTask *timingwheel.Timer // 定时任务 DefaultObserver Observer // 默认监听函数 Cooling bool // 是否cd中 LimitReached bool // 是否达到限制 DecoratedDone bool // 被装饰节点是否完成 DecoratedSuccess bool // 被装饰节点是否成功 Elapsed time.Duration // 启动后流逝的时间 Restarting bool // 是否正在重启,是 State 为 NodeStateAborting 时的一个细分状态 }
NodeMemory 节点数据
func NewNodeMemory ¶
func NewNodeMemory() *NodeMemory
type ObservingDecorator ¶
type ObservingDecorator struct { Decorator IObservingWorker }
ObservingDecorator 观察者装饰器,实现了对条件的监听,和条件变化时的各种中断模式
节点处于启用状态且条件不再被满足: Stops.NONE: 无 Stops.SELF: 中断当前节点 Stops.LOWER_PRIORITY: 无 Stops.BOTH: 中断当前节点 节点处于停用状态且条件被满足时: Stops.NONE: 无 Stops.SELF: 无 Stops.LOWER_PRIORITY: 关闭当前启用的分支,启动此分支 Stops.BOTH: 关闭当前启用的分支,启动此分支
func (*ObservingDecorator) AbortMode ¶
func (o *ObservingDecorator) AbortMode() AbortMode
AbortMode 中断模式
@receiver o @return AbortMode
func (*ObservingDecorator) ConditionMet ¶
func (o *ObservingDecorator) ConditionMet(brain IBrain, args ...any) bool
ConditionMet panic
@receiver o @param brain @param args @return bool
func (*ObservingDecorator) Evaluate ¶
func (o *ObservingDecorator) Evaluate(brain IBrain, args ...any)
Evaluate 根据节点状态和条件满足来评估后续中断流程
@receiver o @param brain @param args... 透传参数,原样传递给 ConditionMet
func (*ObservingDecorator) InitNodeWorker ¶
func (o *ObservingDecorator) InitNodeWorker(worker INodeWorker) error
InitNodeWorker
@override Node.InitNodeWorker @receiver c @param worker
func (*ObservingDecorator) OnAbort ¶ added in v1.0.6
func (o *ObservingDecorator) OnAbort(brain IBrain)
OnAbort
@override Node.OnAbort @receiver n @param brain
func (*ObservingDecorator) OnChildFinished ¶
func (o *ObservingDecorator) OnChildFinished(brain IBrain, child INode, succeeded bool)
OnChildFinished
@override Container.OnChildFinished @receiver r @param brain @param child @param succeeded
func (*ObservingDecorator) OnCompositeAncestorFinished ¶
func (o *ObservingDecorator) OnCompositeAncestorFinished(brain IBrain, composite IComposite)
OnCompositeAncestorFinished
@override Node.OnCompositeAncestorFinished @receiver n @param brain @param composite
func (*ObservingDecorator) OnStart ¶
func (o *ObservingDecorator) OnStart(brain IBrain)
OnStart
@override Node.OnStart @receiver n @param brain
func (*ObservingDecorator) PropertiesClassProvider ¶
func (o *ObservingDecorator) PropertiesClassProvider() any
PropertiesClassProvider
@implement INodeWorker.PropertiesClassProvider @receiver n @return any
func (*ObservingDecorator) StartObserving ¶
func (o *ObservingDecorator) StartObserving(brain IBrain)
StartObserving
@implement IObservingWorker.StartObserving @receiver o @param brain
func (*ObservingDecorator) StopObserving ¶
func (o *ObservingDecorator) StopObserving(brain IBrain)
StopObserving
@implement IObservingWorker.StopObserving @receiver o @param brain
type ObservingProperties ¶
type ObservingProperties struct {
AbortMode AbortMode `json:"abortMode"`
}
ObservingProperties 观察者装饰器属性
func (*ObservingProperties) GetAbortMode ¶
func (o *ObservingProperties) GetAbortMode() AbortMode
type ParallelMemory ¶
type ParallelMemory struct { RunningCount int // 运行中的子节点数量 SucceededCount int // 成功的子节点数量 FailedCount int // 失败的子节点数量 ChildrenSucceeded map[string]bool // 子节点是否成功 Succeeded bool // 自己是否成功 ChildrenAborted bool // 是否中断子节点 }
ParallelMemory 并发节点的数据
type Root ¶
type Root struct {
Decorator
}
func (*Root) CanMountTo ¶ added in v1.0.7
CanMountTo
@override Node.CanMountTo @receiver r @return bool
func (*Root) Finish ¶ added in v1.0.3
Finish
@override Node.Finish @receiver d @param brain @param succeeded
func (*Root) OnChildFinished ¶
OnChildFinished
@override Container.OnChildFinished @receiver r @param brain @param child @param succeeded
func (*Root) PropertiesClassProvider ¶
PropertiesClassProvider
@implement INodeWorker.PropertiesClassProvider @receiver n @return any
func (*Root) SafeAbort ¶ added in v1.0.7
func (r *Root) SafeAbort(brain IBrain, abortChan chan *FinishEvent)
SafeAbort
@implement IRoot.SafeAbort @receiver r @param brain @param abortChan
func (*Root) SafeStart ¶ added in v1.0.7
SafeStart
@implement IRoot.SafeStart @receiver r @param brain