ec

package
v0.1.38 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: LGPL-2.1 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEC = fmt.Errorf("%w: ec", exception.ErrTiny) // EC错误
)
View Source
var With _Option

Functions

func BindEventComponentDestroySelf

func BindEventComponentDestroySelf(auto iAutoEventComponentDestroySelf, subscriber EventComponentDestroySelf, priority ...int32) event.Hook

func BindEventComponentMgrAddComponents

func BindEventComponentMgrAddComponents(auto iAutoEventComponentMgrAddComponents, subscriber EventComponentMgrAddComponents, priority ...int32) event.Hook

func BindEventComponentMgrFirstAccessComponent

func BindEventComponentMgrFirstAccessComponent(auto iAutoEventComponentMgrFirstAccessComponent, subscriber EventComponentMgrFirstAccessComponent, priority ...int32) event.Hook

func BindEventComponentMgrRemoveComponent

func BindEventComponentMgrRemoveComponent(auto iAutoEventComponentMgrRemoveComponent, subscriber EventComponentMgrRemoveComponent, priority ...int32) event.Hook

func BindEventEntityDestroySelf

func BindEventEntityDestroySelf(auto iAutoEventEntityDestroySelf, subscriber EventEntityDestroySelf, priority ...int32) event.Hook

func BindEventTreeNodeAddChild

func BindEventTreeNodeAddChild(auto iAutoEventTreeNodeAddChild, subscriber EventTreeNodeAddChild, priority ...int32) event.Hook

func BindEventTreeNodeEnterParent

func BindEventTreeNodeEnterParent(auto iAutoEventTreeNodeEnterParent, subscriber EventTreeNodeEnterParent, priority ...int32) event.Hook

func BindEventTreeNodeLeaveParent

func BindEventTreeNodeLeaveParent(auto iAutoEventTreeNodeLeaveParent, subscriber EventTreeNodeLeaveParent, priority ...int32) event.Hook

func BindEventTreeNodeRemoveChild

func BindEventTreeNodeRemoveChild(auto iAutoEventTreeNodeRemoveChild, subscriber EventTreeNodeRemoveChild, priority ...int32) event.Hook

func UnsafeComponent deprecated

func UnsafeComponent(comp Component) _UnsafeComponent

Deprecated: UnsafeComponent 访问组件内部函数

func UnsafeEntity deprecated

func UnsafeEntity(entity Entity) _UnsafeEntity

Deprecated: UnsafeEntity 访问实体内部函数

Types

type Component

type Component interface {
	gctx.CurrentContextProvider
	fmt.Stringer

	// GetId 获取组件Id
	GetId() uid.Id
	// GetName 获取组件名称
	GetName() string
	// GetEntity 获取组件依附的实体
	GetEntity() Entity
	// GetState 获取组件状态
	GetState() ComponentState
	// GetReflected 获取反射值
	GetReflected() reflect.Value
	// DestroySelf 销毁自身
	DestroySelf()
	// contains filtered or unexported methods
}

Component 组件接口

type ComponentBehavior

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

ComponentBehavior 组件行为,需要在开发新组件时,匿名嵌入至组件结构体中

func (*ComponentBehavior) DestroySelf

func (comp *ComponentBehavior) DestroySelf()

DestroySelf 销毁自身

func (*ComponentBehavior) GetConcurrentContext

func (comp *ComponentBehavior) GetConcurrentContext() iface.Cache

GetConcurrentContext 获取多线程安全的上下文

func (*ComponentBehavior) GetCurrentContext

func (comp *ComponentBehavior) GetCurrentContext() iface.Cache

GetCurrentContext 获取当前上下文

func (*ComponentBehavior) GetEntity

func (comp *ComponentBehavior) GetEntity() Entity

GetEntity 获取组件依附的实体

func (*ComponentBehavior) GetId

func (comp *ComponentBehavior) GetId() uid.Id

GetId 获取组件Id

func (*ComponentBehavior) GetName

func (comp *ComponentBehavior) GetName() string

GetName 获取组件名称

func (*ComponentBehavior) GetReflected

func (comp *ComponentBehavior) GetReflected() reflect.Value

GetReflected 获取反射值

func (*ComponentBehavior) GetState

func (comp *ComponentBehavior) GetState() ComponentState

GetState 获取组件状态

func (*ComponentBehavior) ManagedHooks

func (comp *ComponentBehavior) ManagedHooks(hooks ...event.Hook)

ManagedHooks 托管hook,在组件销毁时自动解绑定

func (*ComponentBehavior) String

func (comp *ComponentBehavior) String() string

String implements fmt.Stringer

type ComponentState

type ComponentState int8

ComponentState 组件状态

const (
	ComponentState_Birth  ComponentState = iota // 出生
	ComponentState_Attach                       // 附着
	ComponentState_Awake                        // 唤醒
	ComponentState_Start                        // 开始
	ComponentState_Alive                        // 活跃
	ComponentState_Detach                       // 脱离
	ComponentState_Shut                         // 结束
	ComponentState_Death                        // 死亡
)

func (ComponentState) String

func (i ComponentState) String() string

type ConcurrentEntity

type ConcurrentEntity interface {
	gctx.ConcurrentContextProvider
	fmt.Stringer

	// GetId 获取实体Id
	GetId() uid.Id
	// GetPrototype 获取实体原型
	GetPrototype() string
}

ConcurrentEntity 多线程安全的实体接口

type Entity

type Entity interface {
	gctx.CurrentContextProvider
	reinterpret.CompositeProvider
	fmt.Stringer

	// GetId 获取实体Id
	GetId() uid.Id
	// GetPrototype 获取实体原型
	GetPrototype() string
	// GetState 获取实体状态
	GetState() EntityState
	// GetReflected 获取反射值
	GetReflected() reflect.Value
	// GetMeta 获取Meta信息
	GetMeta() meta.Meta
	// DestroySelf 销毁自身
	DestroySelf()
	// contains filtered or unexported methods
}

Entity 实体接口

func NewEntity

func NewEntity(settings ...option.Setting[EntityOptions]) Entity

NewEntity 创建实体

func UnsafeNewEntity deprecated

func UnsafeNewEntity(options EntityOptions) Entity

Deprecated: UnsafeNewEntity 内部创建实体

type EntityBehavior

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

EntityBehavior 实体行为,在需要扩展实体能力时,匿名嵌入至实体结构体中

func (*EntityBehavior) AddComponent

func (entity *EntityBehavior) AddComponent(name string, components ...Component) error

AddComponent 添加组件,因为同个名称可以指向多个组件,所以名称指向的组件已存在时,不会返回错误

func (*EntityBehavior) ContainsComponent

func (entity *EntityBehavior) ContainsComponent(name string) bool

ContainsComponent 组件是否存在

func (*EntityBehavior) ContainsComponentById

func (entity *EntityBehavior) ContainsComponentById(id uid.Id) bool

ContainsComponentById 使用组件Id检测组件是否存在

func (*EntityBehavior) CountComponents

func (entity *EntityBehavior) CountComponents() int

CountComponents 统计所有组件数量

func (*EntityBehavior) DestroySelf

func (entity *EntityBehavior) DestroySelf()

DestroySelf 销毁自身

func (*EntityBehavior) EventComponentMgrAddComponents

func (entity *EntityBehavior) EventComponentMgrAddComponents() event.IEvent

EventComponentMgrAddComponents 事件:实体的组件管理器添加组件

func (*EntityBehavior) EventComponentMgrFirstAccessComponent

func (entity *EntityBehavior) EventComponentMgrFirstAccessComponent() event.IEvent

EventComponentMgrFirstAccessComponent 事件:实体的组件管理器首次访问组件

func (*EntityBehavior) EventComponentMgrRemoveComponent

func (entity *EntityBehavior) EventComponentMgrRemoveComponent() event.IEvent

EventComponentMgrRemoveComponent 事件:实体的组件管理器删除组件

func (*EntityBehavior) EventTreeNodeAddChild

func (entity *EntityBehavior) EventTreeNodeAddChild() event.IEvent

EventTreeNodeAddChild 事件:实体节点添加子实体

func (*EntityBehavior) EventTreeNodeEnterParent

func (entity *EntityBehavior) EventTreeNodeEnterParent() event.IEvent

EventTreeNodeEnterParent 事件:实体加入父实体节点

func (*EntityBehavior) EventTreeNodeLeaveParent

func (entity *EntityBehavior) EventTreeNodeLeaveParent() event.IEvent

EventTreeNodeLeaveParent 事件:实体离开父实体节点

func (*EntityBehavior) EventTreeNodeRemoveChild

func (entity *EntityBehavior) EventTreeNodeRemoveChild() event.IEvent

EventTreeNodeRemoveChild 事件:实体节点删除子实体

func (*EntityBehavior) FilterComponents

func (entity *EntityBehavior) FilterComponents(fun generic.Func1[Component, bool]) []Component

FilterComponents 过滤并获取组件

func (*EntityBehavior) GetComponent

func (entity *EntityBehavior) GetComponent(name string) Component

GetComponent 使用名称查询组件,同个名称指向多个组件时,返回首个组件

func (*EntityBehavior) GetComponentById

func (entity *EntityBehavior) GetComponentById(id uid.Id) Component

GetComponentById 使用组件Id查询组件

func (*EntityBehavior) GetComponents

func (entity *EntityBehavior) GetComponents() []Component

GetComponents 获取所有组件

func (*EntityBehavior) GetCompositeFaceCache

func (entity *EntityBehavior) GetCompositeFaceCache() iface.Cache

GetCompositeFaceCache 支持重新解释类型

func (*EntityBehavior) GetConcurrentContext

func (entity *EntityBehavior) GetConcurrentContext() iface.Cache

GetConcurrentContext 解析线程安全的上下文

func (*EntityBehavior) GetCurrentContext

func (entity *EntityBehavior) GetCurrentContext() iface.Cache

GetCurrentContext 获取当前上下文

func (*EntityBehavior) GetId

func (entity *EntityBehavior) GetId() uid.Id

GetId 获取实体Id

func (*EntityBehavior) GetMeta

func (entity *EntityBehavior) GetMeta() meta.Meta

GetMeta 获取Meta信息

func (*EntityBehavior) GetPrototype

func (entity *EntityBehavior) GetPrototype() string

GetPrototype 获取实体原型

func (*EntityBehavior) GetReflected

func (entity *EntityBehavior) GetReflected() reflect.Value

GetReflected 获取反射值

func (*EntityBehavior) GetState

func (entity *EntityBehavior) GetState() EntityState

GetState 获取实体状态

func (*EntityBehavior) GetTreeNodeParent

func (entity *EntityBehavior) GetTreeNodeParent() (Entity, bool)

GetTreeNodeParent 获取在实体树中的父实体

func (*EntityBehavior) GetTreeNodeState

func (entity *EntityBehavior) GetTreeNodeState() TreeNodeState

GetTreeNodeState 获取实体树节点状态

func (*EntityBehavior) ManagedHooks

func (entity *EntityBehavior) ManagedHooks(hooks ...event.Hook)

ManagedHooks 托管hook,在实体销毁时自动解绑定

func (*EntityBehavior) RangeComponents

func (entity *EntityBehavior) RangeComponents(fun generic.Func1[Component, bool])

RangeComponents 遍历所有组件

func (*EntityBehavior) RemoveComponent

func (entity *EntityBehavior) RemoveComponent(name string)

RemoveComponent 使用名称删除组件,将会删除同个名称指向的多个组件

func (*EntityBehavior) RemoveComponentById

func (entity *EntityBehavior) RemoveComponentById(id uid.Id)

RemoveComponentById 使用组件Id删除组件

func (*EntityBehavior) ReversedRangeComponents

func (entity *EntityBehavior) ReversedRangeComponents(fun generic.Func1[Component, bool])

ReversedRangeComponents 反向遍历所有组件

func (*EntityBehavior) String

func (entity *EntityBehavior) String() string

String implements fmt.Stringer

type EntityOptions

type EntityOptions struct {
	CompositeFace      iface.Face[Entity]     // 扩展者,在扩展实体自身能力时使用
	Prototype          string                 // 实体原型名称
	PersistId          uid.Id                 // 实体持久化Id
	AwakeOnFirstAccess bool                   // 开启组件被首次访问时,检测并调用Awake()
	Meta               meta.Meta              // Meta信息
	ManagedPoolObject  pool.ManagedPoolObject // 托管对象池
}

EntityOptions 创建实体的所有选项

type EntityState

type EntityState int8

EntityState 实体状态

const (
	EntityState_Birth EntityState = iota // 出生
	EntityState_Enter                    // 进入容器
	EntityState_Awake                    // 唤醒
	EntityState_Start                    // 开始
	EntityState_Alive                    // 活跃
	EntityState_Leave                    // 离开容器
	EntityState_Shut                     // 结束
	EntityState_Death                    // 死亡
)

func (EntityState) String

func (i EntityState) String() string

type EventComponentDestroySelf

type EventComponentDestroySelf interface {
	OnComponentDestroySelf(comp Component)
}

EventComponentDestroySelf 事件:组件销毁自身 +event-gen:export=0

type EventComponentDestroySelfHandler

type EventComponentDestroySelfHandler func(comp Component)

func HandleEventComponentDestroySelf

func HandleEventComponentDestroySelf(fun func(comp Component)) EventComponentDestroySelfHandler

func (EventComponentDestroySelfHandler) OnComponentDestroySelf

func (h EventComponentDestroySelfHandler) OnComponentDestroySelf(comp Component)

type EventComponentMgrAddComponents

type EventComponentMgrAddComponents interface {
	OnComponentMgrAddComponents(entity Entity, components []Component)
}

EventComponentMgrAddComponents 事件:实体的组件管理器添加组件 +event-gen:export=0

type EventComponentMgrAddComponentsHandler

type EventComponentMgrAddComponentsHandler func(entity Entity, components []Component)

func HandleEventComponentMgrAddComponents

func HandleEventComponentMgrAddComponents(fun func(entity Entity, components []Component)) EventComponentMgrAddComponentsHandler

func (EventComponentMgrAddComponentsHandler) OnComponentMgrAddComponents

func (h EventComponentMgrAddComponentsHandler) OnComponentMgrAddComponents(entity Entity, components []Component)

type EventComponentMgrFirstAccessComponent

type EventComponentMgrFirstAccessComponent interface {
	OnComponentMgrFirstAccessComponent(entity Entity, component Component)
}

EventComponentMgrFirstAccessComponent 事件:实体的组件管理器首次访问组件 +event-gen:export=0

type EventComponentMgrFirstAccessComponentHandler

type EventComponentMgrFirstAccessComponentHandler func(entity Entity, component Component)

func HandleEventComponentMgrFirstAccessComponent

func HandleEventComponentMgrFirstAccessComponent(fun func(entity Entity, component Component)) EventComponentMgrFirstAccessComponentHandler

func (EventComponentMgrFirstAccessComponentHandler) OnComponentMgrFirstAccessComponent

func (h EventComponentMgrFirstAccessComponentHandler) OnComponentMgrFirstAccessComponent(entity Entity, component Component)

type EventComponentMgrRemoveComponent

type EventComponentMgrRemoveComponent interface {
	OnComponentMgrRemoveComponent(entity Entity, component Component)
}

EventComponentMgrRemoveComponent 事件:实体的组件管理器删除组件 +event-gen:export=0

type EventComponentMgrRemoveComponentHandler

type EventComponentMgrRemoveComponentHandler func(entity Entity, component Component)

func HandleEventComponentMgrRemoveComponent

func HandleEventComponentMgrRemoveComponent(fun func(entity Entity, component Component)) EventComponentMgrRemoveComponentHandler

func (EventComponentMgrRemoveComponentHandler) OnComponentMgrRemoveComponent

func (h EventComponentMgrRemoveComponentHandler) OnComponentMgrRemoveComponent(entity Entity, component Component)

type EventEntityDestroySelf

type EventEntityDestroySelf interface {
	OnEntityDestroySelf(entity Entity)
}

EventEntityDestroySelf 事件:实体销毁自身 +event-gen:export=0

type EventEntityDestroySelfHandler

type EventEntityDestroySelfHandler func(entity Entity)

func HandleEventEntityDestroySelf

func HandleEventEntityDestroySelf(fun func(entity Entity)) EventEntityDestroySelfHandler

func (EventEntityDestroySelfHandler) OnEntityDestroySelf

func (h EventEntityDestroySelfHandler) OnEntityDestroySelf(entity Entity)

type EventTreeNodeAddChild

type EventTreeNodeAddChild interface {
	OnTreeNodeAddChild(parent, child Entity)
}

EventTreeNodeAddChild 事件:实体节点添加子实体 +event-gen:export=0

type EventTreeNodeAddChildHandler

type EventTreeNodeAddChildHandler func(parent, child Entity)

func HandleEventTreeNodeAddChild

func HandleEventTreeNodeAddChild(fun func(parent, child Entity)) EventTreeNodeAddChildHandler

func (EventTreeNodeAddChildHandler) OnTreeNodeAddChild

func (h EventTreeNodeAddChildHandler) OnTreeNodeAddChild(parent, child Entity)

type EventTreeNodeEnterParent

type EventTreeNodeEnterParent interface {
	OnTreeNodeEnterParent(child, parent Entity)
}

EventTreeNodeEnterParent 事件:实体加入父实体节点 +event-gen:export=0

type EventTreeNodeEnterParentHandler

type EventTreeNodeEnterParentHandler func(child, parent Entity)

func HandleEventTreeNodeEnterParent

func HandleEventTreeNodeEnterParent(fun func(child, parent Entity)) EventTreeNodeEnterParentHandler

func (EventTreeNodeEnterParentHandler) OnTreeNodeEnterParent

func (h EventTreeNodeEnterParentHandler) OnTreeNodeEnterParent(child, parent Entity)

type EventTreeNodeLeaveParent

type EventTreeNodeLeaveParent interface {
	OnTreeNodeLeaveParent(child, parent Entity)
}

EventTreeNodeLeaveParent 事件:实体离开父实体节点 +event-gen:export=0

type EventTreeNodeLeaveParentHandler

type EventTreeNodeLeaveParentHandler func(child, parent Entity)

func HandleEventTreeNodeLeaveParent

func HandleEventTreeNodeLeaveParent(fun func(child, parent Entity)) EventTreeNodeLeaveParentHandler

func (EventTreeNodeLeaveParentHandler) OnTreeNodeLeaveParent

func (h EventTreeNodeLeaveParentHandler) OnTreeNodeLeaveParent(child, parent Entity)

type EventTreeNodeRemoveChild

type EventTreeNodeRemoveChild interface {
	OnTreeNodeRemoveChild(parent, child Entity)
}

EventTreeNodeRemoveChild 事件:实体节点删除子实体 +event-gen:export=0

type EventTreeNodeRemoveChildHandler

type EventTreeNodeRemoveChildHandler func(parent, child Entity)

func HandleEventTreeNodeRemoveChild

func HandleEventTreeNodeRemoveChild(fun func(parent, child Entity)) EventTreeNodeRemoveChildHandler

func (EventTreeNodeRemoveChildHandler) OnTreeNodeRemoveChild

func (h EventTreeNodeRemoveChildHandler) OnTreeNodeRemoveChild(parent, child Entity)

type TreeNodeState

type TreeNodeState int8

TreeNodeState 实体树节点状态

const (
	TreeNodeState_Freedom   TreeNodeState = iota // 自由实体
	TreeNodeState_Attaching                      // 正在加入实体树
	TreeNodeState_Attached                       // 在实体树中
	TreeNodeState_Detaching                      // 正在脱离实体树
)

func (TreeNodeState) String

func (i TreeNodeState) String() string

Jump to

Keyboard shortcuts

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