Documentation ¶
Index ¶
- func DefaultSharedBlackboard() *bcore.Blackboard
- func GlobalHandlerPool() *handle.HandlerPool
- func InitSystem(opts ...Option)
- func NewBrain(blackboard bcore.IBlackboard, delegates map[string]any, ...) bcore.IBrain
- func RegisterDelegatorType(name string, target any) error
- func SetGlobalTreeRegistry(registry *TreeRegistry)
- func SharedBlackboard(key string) *bcore.Blackboard
- type Brain
- func (b *Brain) Abort(abortChan chan *bcore.FinishEvent)
- func (b *Brain) After(interval time.Duration, randomDeviation time.Duration, task func()) *timingwheel.Timer
- func (b *Brain) Blackboard() bcore.IBlackboard
- func (b *Brain) Context() context.Context
- func (b *Brain) Cron(interval time.Duration, randomDeviation time.Duration, task func()) *timingwheel.Timer
- func (b *Brain) DynamicDecorate(containerTag string, subtreeTag string) error
- func (b *Brain) FinishChan() <-chan *bcore.FinishEvent
- func (b *Brain) GetDelegate(name string) (delegate any, ok bool)
- func (b *Brain) GetDelegates() map[string]any
- func (b *Brain) Go(task func())
- func (b *Brain) ID() int
- func (b *Brain) OnNodeUpdate(target string, method string, brain bcore.IBrain, eventType bcore.EventType, ...) bcore.Result
- func (b *Brain) RWFinishChan() chan *bcore.FinishEvent
- func (b *Brain) RegisterDelegate(name string, delegate any)
- func (b *Brain) Run(tag string, force bool)
- func (b *Brain) Running() bool
- func (b *Brain) RunningTree() bcore.IRoot
- func (b *Brain) SetContext(ctx context.Context)
- func (b *Brain) SetDelegates(delegates map[string]any)
- func (b *Brain) SetFinishChan(finishChan chan *bcore.FinishEvent)
- func (b *Brain) SetRunningTree(root bcore.IRoot)
- type ClassLoader
- func (l *ClassLoader) Clone(node bcore.INode) (bcore.INode, error)
- func (l *ClassLoader) Contains(name string) bool
- func (l *ClassLoader) New(name string, cfg *config.NodeCfg) (bcore.INode, error)
- func (l *ClassLoader) Register(node bcore.INode)
- func (l *ClassLoader) RegisterWithName(name string, node bcore.INode)
- type ExecutorFun
- type InitialOption
- type Option
- func WithCustomNodes(nodes []bcore.INode) Option
- func WithLogDevelopment(development bool) Option
- func WithLogLevel(level zapcore.Level) Option
- func WithScriptPoolApiLib(api map[string]any) Option
- func WithScriptPoolMaxSize(size int) Option
- func WithScriptPoolMinSize(size int) Option
- func WithThreadPool(pool *ants.Pool) Option
- func WithTimerInterval(interval time.Duration) Option
- func WithTimerNumSlots(slots int) Option
- func WithTimerPoolSize(size int) Option
- type Tree
- type TreeRegistry
- func (r *TreeRegistry) CloneAndReg(src *Tree) (*Tree, error)
- func (r *TreeRegistry) GetNotParentTreeWithoutClone(tag string) *Tree
- func (r *TreeRegistry) Load(cfg *config.TreeCfg) error
- func (r *TreeRegistry) LoadFromJson(cfgJson []byte) error
- func (r *TreeRegistry) LoadFromJsons(cfgJson [][]byte) error
- func (r *TreeRegistry) LoadFromPaths(paths []string) error
- func (r *TreeRegistry) MountAll() error
- func (r *TreeRegistry) Remove(tag string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultSharedBlackboard ¶
func DefaultSharedBlackboard() *bcore.Blackboard
DefaultSharedBlackboard 获取全局默认共享黑板单例
@return *Blackboard
func GlobalHandlerPool ¶
func GlobalHandlerPool() *handle.HandlerPool
GlobalHandlerPool 全局反射代理缓存池
@return *handle.HandlerPool
func InitSystem ¶
func InitSystem(opts ...Option)
InitSystem 系统初始化
要使用该库必须先初始化 @param option @panic 若发生异常将主动panic
func NewBrain ¶
func NewBrain(blackboard bcore.IBlackboard, delegates map[string]any, finishChan chan *bcore.FinishEvent) bcore.IBrain
NewBrain bcore.IBrain 实例
@param blackboard @param delegates 要注册的委托对象 @return bcore.IBrain
func SetGlobalTreeRegistry ¶ added in v1.0.7
func SetGlobalTreeRegistry(registry *TreeRegistry)
func SharedBlackboard ¶
func SharedBlackboard(key string) *bcore.Blackboard
SharedBlackboard 获取全局共享黑板单例,若不存在会创建一个
@param key 指定key @return *Blackboard
Types ¶
type Brain ¶
type Brain struct {
// contains filtered or unexported fields
}
func (*Brain) Abort ¶ added in v1.0.7
func (b *Brain) Abort(abortChan chan *bcore.FinishEvent)
Abort @implement bcore.IBrain .Abort
@receiver b @param abortChan
func (*Brain) After ¶ added in v1.1.3
func (b *Brain) After(interval time.Duration, randomDeviation time.Duration, task func()) *timingwheel.Timer
After wrap timingwheel.TimingWheel .AfterFunc
@param interval 间隔 @param randomDeviation 随机方差范围 interval = interval + randomDeviation*[-0.5,0.5) @param task @param opts
func (*Brain) Blackboard ¶
func (b *Brain) Blackboard() bcore.IBlackboard
func (*Brain) Cron ¶ added in v1.1.3
func (b *Brain) Cron(interval time.Duration, randomDeviation time.Duration, task func()) *timingwheel.Timer
Cron wrap timingwheel.TimingWheel .Cron
@param interval 间隔 @param randomDeviation 随机方差范围,interval=interval+randomDeviation*[-0.5,0.5) @param task @param opts
func (*Brain) DynamicDecorate ¶ added in v1.0.7
DynamicDecorate 给正在运行的树动态挂载子树.暂时只支持主树上的动态容器
非线程安全,调用方自己保证
@receiver b @param containerTag 动态子树容器的tag @param subtreeTag 子树的tag @return error
func (*Brain) FinishChan ¶ added in v1.0.3
func (b *Brain) FinishChan() <-chan *bcore.FinishEvent
func (*Brain) GetDelegate ¶ added in v1.0.2
func (*Brain) GetDelegates ¶ added in v1.0.2
GetDelegates 获取委托map拷贝
@receiver b @return map[string]any
func (*Brain) OnNodeUpdate ¶ added in v1.0.2
func (b *Brain) OnNodeUpdate(target string, method string, brain bcore.IBrain, eventType bcore.EventType, delta time.Duration) bcore.Result
OnNodeUpdate 供节点回调执行委托 会在 Brain 的独立线程里运行
@receiver b @param target @param method @param brain @param eventType @param delta @return bcore.Result
func (*Brain) RWFinishChan ¶ added in v1.0.3
func (b *Brain) RWFinishChan() chan *bcore.FinishEvent
func (*Brain) RunningTree ¶ added in v1.0.3
func (*Brain) SetContext ¶ added in v1.1.2
func (*Brain) SetFinishChan ¶ added in v1.0.3
func (b *Brain) SetFinishChan(finishChan chan *bcore.FinishEvent)
func (*Brain) SetRunningTree ¶ added in v1.0.3
type ClassLoader ¶
type ClassLoader struct {
// contains filtered or unexported fields
}
ClassLoader 节点类加加载器 作用 1.缓存节点类2.使用时找到缓存类并实例化出来
func GlobalClassLoader ¶
func GlobalClassLoader() *ClassLoader
GlobalClassLoader 全局类加载器
@return *ClassLoader
func NewClassLoader ¶
func NewClassLoader() *ClassLoader
func (*ClassLoader) Clone ¶ added in v1.0.7
Clone 克隆一个节点
@receiver l @param node @return bcore.INode @return error
func (*ClassLoader) Contains ¶
func (l *ClassLoader) Contains(name string) bool
Contains 检查注册器中是否包含指定节点类
@receiver l @param name @return bool
func (*ClassLoader) New ¶
New 根据 name 实例化节点
@receiver l @param name @param cfg @return INode @return error
func (*ClassLoader) Register ¶
func (l *ClassLoader) Register(node bcore.INode)
Register 注册节点类,注册名为节点的struct名称
@receiver l @param node
func (*ClassLoader) RegisterWithName ¶
func (l *ClassLoader) RegisterWithName(name string, node bcore.INode)
RegisterWithName 根据名字注册节点类
@receiver rsm @param name 可以为空,为空时使用节点的struct名称 @param c
type ExecutorFun ¶
ExecutorFun 委托方法签名例
type InitialOption ¶
type InitialOption struct { ThreadPool *ants.Pool // 线程池 为空则使用默认 TimerPoolSize int // 时间轮池子容量 为0则使用默认 TimerInterval time.Duration // 时间轮帧间隔 为0则使用默认 TimerNumSlots int // 时间槽数量 时间轮第一层总时长=interval*numSlots 为0则使用默认 LogLevel zapcore.Level // 日志级别 LogDevelopment bool // 日志模式是否开发模式 CustomNodeClass []bcore.INode // 用于注册自定义节点类 ScriptPoolMinSize int // 脚本引擎池子最小容量 ScriptPoolMaxSize int // 脚本引擎池子最大容量 ScriptPoolApiLib map[string]any // 需注入到脚本引擎池的api库,最好仅注入一些公共的无状态函数或参数,避免状态副作用 }
type Option ¶
type Option func(option *InitialOption)
func WithCustomNodes ¶
func WithLogDevelopment ¶
func WithLogLevel ¶
func WithScriptPoolApiLib ¶ added in v1.0.2
func WithScriptPoolMaxSize ¶ added in v1.0.2
func WithScriptPoolMinSize ¶ added in v1.0.2
func WithThreadPool ¶
func WithThreadPool(pool *ants.Pool) Option
func WithTimerInterval ¶
func WithTimerNumSlots ¶
func WithTimerPoolSize ¶
type TreeRegistry ¶
type TreeRegistry struct { TreesByID map[string]*Tree // 所有树,索引为 IRoot.ID TreesByTag map[string][]*Tree // 所有树,索引为 IRoot.Tag }
TreeRegistry 行为树注册器
func GlobalTreeRegistry ¶
func GlobalTreeRegistry() *TreeRegistry
func NewTreeRegistry ¶
func NewTreeRegistry() *TreeRegistry
func (*TreeRegistry) CloneAndReg ¶ added in v1.0.9
func (r *TreeRegistry) CloneAndReg(src *Tree) (*Tree, error)
CloneAndReg 拷贝树并注册
@receiver r @param src @return error
func (*TreeRegistry) GetNotParentTreeWithoutClone ¶ added in v1.0.7
func (r *TreeRegistry) GetNotParentTreeWithoutClone(tag string) *Tree
GetNotParentTreeWithoutClone 获取一个还未分配静态父节点的树,多用于获取该tag的主树.
@receiver r @param tag @return *Tree
func (*TreeRegistry) Load ¶
func (r *TreeRegistry) Load(cfg *config.TreeCfg) error
Load 加载树,加载前请务必:1.停止使用该树运行的AI 2.移除该树旧版及其关联树(该树的静态子树和动态子树)
@receiver r @param cfg @return *Tree @return error
func (*TreeRegistry) LoadFromJson ¶
func (r *TreeRegistry) LoadFromJson(cfgJson []byte) error
func (*TreeRegistry) LoadFromJsons ¶
func (r *TreeRegistry) LoadFromJsons(cfgJson [][]byte) error
func (*TreeRegistry) LoadFromPaths ¶
func (r *TreeRegistry) LoadFromPaths(paths []string) error
func (*TreeRegistry) MountAll ¶ added in v1.0.7
func (r *TreeRegistry) MountAll() error
MountAll 遍历所有未挂载子树的子树容器,挂载子树
@receiver r @return error
func (*TreeRegistry) Remove ¶ added in v1.0.7
func (r *TreeRegistry) Remove(tag string)
Remove 根据tag移除树,移除前请务必:1.停止使用该树运行的AI 2.同时移除关联树(该树的静态子树和动态子树)
@receiver r @param tag