behavior

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 20 Imported by: 0

README

behavior

golang event driver behavior tree features:

  • 事件驱动
  • 共享实例的行为数:所有节点无状态,状态由黑板管理

Documentation

Index

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

func NewBrain

func NewBrain(blackboard bcore.IBlackboard, delegates map[string]any) bcore.IBrain

func RegisterDelegatorType

func RegisterDelegatorType(name string, target any) error

RegisterDelegatorType 注册代理类的反射信息

@param name
@param target

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) OnExecute

func (b *Brain) OnExecute(target string, method string, args ...any) ([]any, error)

func (*Brain) RegisterDelegate

func (b *Brain) RegisterDelegate(name string, delegate any)

RegisterDelegate 注册委托对象

@receiver b
@param name
@param delegate

func (*Brain) SetDelegates

func (b *Brain) SetDelegates(delegates map[string]any)

SetDelegates 注册委托对象

@receiver b
@param delegates

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

func (l *ClassLoader) New(name string, cfg *config.NodeCfg) (bcore.INode, error)

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

type ExecutorFun = func(eventType bcore.EventType, delta time.Duration) bcore.Result

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 // 用于注册自定义节点类
}

type NodeRegistry

type NodeRegistry struct {
	// contains filtered or unexported fields
}

NodeRegistry 节点注册器

用于加载行为树前保存节点实例

func NewNodeRegistry

func NewNodeRegistry() *NodeRegistry

func (*NodeRegistry) Register

func (n *NodeRegistry) Register(node bcore.INode)

type Option

type Option func(option *InitialOption)

func WithCustomNodes

func WithCustomNodes(nodes []bcore.INode) Option

func WithLogDevelopment

func WithLogDevelopment(development bool) Option

func WithLogLevel

func WithLogLevel(level zapcore.Level) Option

func WithThreadPool

func WithThreadPool(pool *ants.Pool) Option

func WithTimerInterval

func WithTimerInterval(interval time.Duration) Option

func WithTimerNumSlots

func WithTimerNumSlots(slots int) Option

func WithTimerPoolSize

func WithTimerPoolSize(size int) Option

type Tree

type Tree struct {
	Root            bcore.IRoot
	Ver             string
	Tag             string
	HaveSubtree     bool
	DynamicSubtrees map[string]task.IDynamicSubtree // 所有动态子树容器
}

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) (*Tree, error)

func (*TreeRegistry) LoadFromJson

func (r *TreeRegistry) LoadFromJson(cfgJson string) (*Tree, error)

func (*TreeRegistry) LoadFromJsons

func (r *TreeRegistry) LoadFromJsons(cfgJson []string) error

func (*TreeRegistry) LoadFromPaths

func (r *TreeRegistry) LoadFromPaths(paths []string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL