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 SharedBlackboard(key string) *bcore.Blackboard
- type Brain
- func (b *Brain) Blackboard() bcore.IBlackboard
- func (b *Brain) FinishChan() <-chan *bcore.FinishEvent
- func (b *Brain) ForceRun(root bcore.IRoot)
- 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) 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) Running() bool
- func (b *Brain) RunningTree() bcore.IRoot
- 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
- 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
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 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) Blackboard ¶
func (b *Brain) Blackboard() bcore.IBlackboard
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) 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) 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 Tree ¶
type Tree struct { Root bcore.IRoot Ver string Tag string HaveSubtree bool DynamicSubtrees map[string]task.IDynamicSubtree // 所有动态子树容器,key为tag }
type TreeRegistry ¶
type TreeRegistry struct { TreesByID map[string]*Tree // 所有树,索引为ID TreesByTag map[string]*Tree // 所有树,索引为Tag // contains filtered or unexported fields }
TreeRegistry 行为树注册器
func GlobalTreeRegistry ¶
func GlobalTreeRegistry() *TreeRegistry
func NewTreeRegistry ¶
func NewTreeRegistry() *TreeRegistry
func (*TreeRegistry) Load ¶
func (r *TreeRegistry) Load(cfg *config.TreeCfg) error
Load
@receiver r @param cfg @return *Tree @return error
func (*TreeRegistry) LoadFromJson ¶
func (r *TreeRegistry) LoadFromJson(cfgJson string) error
func (*TreeRegistry) LoadFromJsons ¶
func (r *TreeRegistry) LoadFromJsons(cfgJson []string) error
func (*TreeRegistry) LoadFromPaths ¶
func (r *TreeRegistry) LoadFromPaths(paths []string) error
func (*TreeRegistry) MountSubtree ¶ added in v1.0.3
func (r *TreeRegistry) MountSubtree() error
MountSubtree 遍历所有未挂载子树的子树容器,挂载子树
@receiver r @return error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.