actor

package
v0.0.0-...-677ea5f Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	//检测事件是否有效
	CheckEvent func(actor IActor, event IEvent) bool
)

Functions

func BindActorName

func BindActorName(typ TActor, name string)

func BindComponent

func BindComponent(typ TComponent, name string)

func BindEvent

func BindEvent(typ TEvent, name string, new func() interface{})

func ExistObject

func ExistObject() error

func NewSpace

func NewSpace() *space

func NotExistObject

func NotExistObject() error

func NotExistObjectFactory

func NotExistObjectFactory() error

func NotExistObjectGroup

func NotExistObjectGroup() error

func NotExistObjectGroupTag

func NotExistObjectGroupTag() error

func RecycleEvents

func RecycleEvents(events ...IEvent)

Types

type FEventSetter

type FEventSetter func(event IEvent)

@Description: 设置对象事件 @param event

type FInt64

type FInt64 func(v int64)

type FObjectAction

type FObjectAction func(tid int64, obj IActor, data interface{}, complete utils.Action)

@Description: 对象行为函数 @param tid 链路id @param obj 对象 @param data 数据 @param complete 行为执行完成回调

type FObjectEvent

type FObjectEvent func(tid int64, obj IActor, event IEvent)

@Description: 对象事件监听函数 @param tid @param obj @param event

type FObjectFac

type FObjectFac func(tid int64, obj IActor, data interface{})

@Description: 对象工厂函数,用于组装对象 @param tid 链路id @param obj 对象 @param data 数据

type FObjectTick

type FObjectTick func(tid int64, obj IActor, data interface{}, ms int64)

@Description: 对象事件心跳处理 @param tid 链路id @param obj 对象 @param data 数据 @param ms 心跳间隔

type FSpaceAction

type FSpaceAction func(tid int64, spc ISpace, data interface{}, complete utils.Action)

@Description: 空间行为 @param tid 链路id @param data 数据

type IActor

type IActor interface {
	utils.IWorker
	// @Description: 所在空间
	// @return ISpace
	Space() ISpace

	// @Description: 对象id
	// @return int64
	Id() int64

	// @Description: 对象类型
	// @return TActor
	Type() TActor

	// @Description: 添加数据组件
	// @param data
	AddComponent(data ...IComponent)

	// @Description: 移除数据组件
	// @param typ
	RemoveComponent(typ TComponent)

	// @Description: 是否有数据组件
	// @param typ
	// @return ok
	HasComponent(typ TComponent) (ok bool)

	// @Description: 获取数据
	// @param typ 数据类型
	// @return IComponent 数据
	// @return bool 是否有该数据
	GetComponent(typ TComponent) (IComponent, bool)

	// @Description: 绑定事件监听器
	// @param typ 事件类型
	// @param listener 事件监听器
	BindEvent(typ TEvent, listener FObjectEvent)

	// @Description: 派发事件
	// @param tid 链路id
	// @param complete 所有监听器处理完成,可用于回收事件等
	// @param event
	DispatchEvents(tid int64, event ...IEvent)

	// @Description: 添加心跳
	// @param tid 链路id
	// @param data 心跳需要的数据
	// @param tick 心跳处理函数
	// @return int64 心跳处理id,用于移除
	AddTick(tid int64, data interface{}, tick FObjectTick) int64

	// @Description: 移除心跳处理函数
	// @param id 添加心跳时返回的id
	RemoveTick(id int64)

	// @Description: 启动对象协程
	Start()

	//停止对象协程
	Dispose()
	// contains filtered or unexported methods
}

@Description: 对象 所有方法必需在该对象的协程内执行 使用ISpace的相关方法传递执行,

type IComponent

type IComponent interface {
	Type() TComponent
}

@Description: 对象数据接口

type IEvent

type IEvent interface {
	Type() TEvent
}

@Description: 对象事件接口

func SpawnEvent

func SpawnEvent(typ TEvent) IEvent

type ISpace

type ISpace interface {
	utils.IWorker
	// @Description: 空间数据,并发安全
	// @return utils.IComponent
	Data() utils.IData

	// @Description: 绑定对象的工厂函数, 需要调用Object的Start方法启动对象协程
	// @param typ 类型
	// @param fac 工厂函数
	BindActorFac(typ TActor, fac FObjectFac)

	// @Description: 空间协程生成对象
	// @param tid 链路id
	// @param objectId 对象id
	// @param typ 对象类型
	// @param data 构建对象需要的数据
	// @param tags 对象的标签
	SpawnObject(tid int64, objectId int64, typ TActor, data interface{}, tags ...string)

	// @Description: 空间协程回收对象
	// @param tid 链路id
	// @param objectId 对象id
	RecycleObject(tid, objectId int64)

	// @Description: 空间协程判断是否有对象
	// @param objectId
	// @return bool
	HasObject(objectId int64) bool

	// @Description: 空间协程指定对象执行行为
	// @param tid 链路id
	// @param objectId 对象id
	// @param data 行为需要的数据
	// @param action 行为回调
	// @param complete 在对象协程执行的回调
	ActionObject(tid, objectId int64, data interface{}, action FObjectAction, complete utils.Action)

	// @Description: 空间协程添加对象标签
	// @param objectId 对象id
	// @param tags 标签
	// @return error 对象id不存在返回_NotExistObject
	AddObjectTags(objectId int64, tags ...string) error

	// @Description: 空间协程移除对象标签
	// @param objectId 对象id
	// @param tags 标签
	// @return error 对象id不存在返回_NotExistObject
	RemoveObjectTags(objectId int64, tags ...string) error

	// @Description: 空间协程批量添加标签对象
	// @param tid 链路id
	// @param tag 标签
	// @param objectIds 对象id
	AddTagObjects(tid int64, tag string, objectIds ...int64)

	// @Description: 空间协程批量移除标签对象
	// @param tid 链路id
	// @param tag 标签
	// @param objectIds 对象id
	RemoveTagObjects(tid int64, tag string, objectIds ...int64)

	// @Description: 空间协程指定标签的所有对象执行行为
	// @param tid 链路id
	// @param data 行为所需数据
	// @param action 行为回调
	// @param complete 新协程执行完成回调
	// @param tags 标签
	ActionTagObjects(tid int64, data interface{}, action FObjectAction, complete utils.Action, tags ...string)

	// @Description: 空间协程获取对象的标签
	// @param objectId 对象id
	// @return []string 对象的标签
	// @return bool 是否有指定对象id
	GetObjectTags(objectId int64) ([]string, bool)

	// @Description: 启动协程
	// @param complete
	// @param tickDur
	Start(complete utils.Action, tickDur time.Duration)
	// contains filtered or unexported methods
}

@Description: 管理对象的空间 内部一个协程管理对象及标签,调用Unsafe开头的方法必需在Action的FSpaceAction参数中执行,否则会有数据竞争 每个对象内部数据都由一个单独协程处理

type TActor

type TActor uint16

func (TActor) String

func (t TActor) String() string

type TComponent

type TComponent uint16

func (TComponent) String

func (t TComponent) String() string

type TEvent

type TEvent uint16

func (TEvent) String

func (t TEvent) String() string

Jump to

Keyboard shortcuts

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