Documentation ¶
Overview ¶
Package runtime 运行时环境提供的一些接口与函数。
- 运行时上下文(Context)
- 实体管理器(EntityMgr)
- EC树(ECTree)
- 帧(Frame)
Index ¶
- Variables
- func BindEventECTreeAddChild(auto iAutoEventECTreeAddChild, subscriber EventECTreeAddChild, ...) event.Hook
- func BindEventECTreeRemoveChild(auto iAutoEventECTreeRemoveChild, subscriber EventECTreeRemoveChild, ...) event.Hook
- func BindEventEntityMgrAddEntity(auto iAutoEventEntityMgrAddEntity, subscriber EventEntityMgrAddEntity, ...) event.Hook
- func BindEventEntityMgrEntityAddComponents(auto iAutoEventEntityMgrEntityAddComponents, ...) event.Hook
- func BindEventEntityMgrEntityFirstAccessComponent(auto iAutoEventEntityMgrEntityFirstAccessComponent, ...) event.Hook
- func BindEventEntityMgrEntityRemoveComponent(auto iAutoEventEntityMgrEntityRemoveComponent, ...) event.Hook
- func BindEventEntityMgrRemoveEntity(auto iAutoEventEntityMgrRemoveEntity, subscriber EventEntityMgrRemoveEntity, ...) event.Hook
- func BindEventEntityMgrRemovingEntity(auto iAutoEventEntityMgrRemovingEntity, ...) event.Hook
- func GetComposite[T any](ctx Context) T
- func UnsafeContext(ctx Context) _UnsafeContextdeprecated
- func UnsafeECTree(ecTree ECTree) _UnsafeECTreedeprecated
- func UnsafeFrame(frame Frame) _UnsafeFramedeprecated
- type AsyncRet
- type Callee
- type Caller
- type ConcurrentContext
- type ConcurrentContextProvider
- type Context
- type ContextBehavior
- func (ctx *ContextBehavior) ActivateEvent(event event.IEventCtrl, recursion event.EventRecursion)
- func (ctx *ContextBehavior) Call(fun generic.FuncVar0[any, Ret], va ...any) AsyncRet
- func (ctx *ContextBehavior) CallDelegate(fun generic.DelegateFuncVar0[any, Ret], va ...any) AsyncRet
- func (ctx *ContextBehavior) CallVoid(fun generic.ActionVar0[any], va ...any) AsyncRet
- func (ctx *ContextBehavior) CallVoidDelegate(fun generic.DelegateActionVar0[any], va ...any) AsyncRet
- func (ctx *ContextBehavior) CollectGC(gc container.GC)
- func (ctx *ContextBehavior) GetConcurrentContext() iface.Cache
- func (ctx *ContextBehavior) GetContext() iface.Cache
- func (ctx *ContextBehavior) GetCurrentContext() iface.Cache
- func (ctx *ContextBehavior) GetECTree() ECTree
- func (ctx *ContextBehavior) GetEntityMgr() EntityMgr
- func (ctx *ContextBehavior) GetFaceAnyAllocator() container.Allocator[iface.FaceAny]
- func (ctx *ContextBehavior) GetFrame() Frame
- func (ctx *ContextBehavior) GetHookAllocator() container.Allocator[event.Hook]
- func (ctx *ContextBehavior) GetId() uid.Id
- func (ctx *ContextBehavior) GetName() string
- func (ctx *ContextBehavior) GetPluginBundle() plugin.PluginBundle
- func (ctx *ContextBehavior) String() string
- type ContextOptions
- type CurrentContextProvider
- type ECTree
- type EntityMgr
- type EventECTreeAddChild
- type EventECTreeRemoveChild
- type EventEntityMgrAddEntity
- type EventEntityMgrEntityAddComponents
- type EventEntityMgrEntityFirstAccessComponent
- type EventEntityMgrEntityRemoveComponent
- type EventEntityMgrRemoveEntity
- type EventEntityMgrRemovingEntity
- type Frame
- type FrameOptions
- type Option
- type Ret
- type RunningHandler
- type RunningState
Constants ¶
This section is empty.
Variables ¶
var ( ErrContext = fmt.Errorf("%w: runtime-context", exception.ErrGolaxy) // 运行时上下文错误 ErrECTree = fmt.Errorf("%w: ec-tree", ErrContext) // EC树错误 ErrEntityMgr = fmt.Errorf("%w: entity-mgr", ErrContext) // 实体管理器错误 ErrFrame = fmt.Errorf("%w: frame", ErrContext) // 帧错误 )
var (
ErrAsyncRetClosed = concurrent.ErrAsyncRetClosed
)
var (
MakeRet = concurrent.MakeRet // 创建调用结果
)
Functions ¶
func BindEventECTreeAddChild ¶
func BindEventECTreeAddChild(auto iAutoEventECTreeAddChild, subscriber EventECTreeAddChild, priority ...int32) event.Hook
func BindEventECTreeRemoveChild ¶
func BindEventECTreeRemoveChild(auto iAutoEventECTreeRemoveChild, subscriber EventECTreeRemoveChild, priority ...int32) event.Hook
func BindEventEntityMgrAddEntity ¶
func BindEventEntityMgrAddEntity(auto iAutoEventEntityMgrAddEntity, subscriber EventEntityMgrAddEntity, priority ...int32) event.Hook
func BindEventEntityMgrEntityAddComponents ¶
func BindEventEntityMgrEntityAddComponents(auto iAutoEventEntityMgrEntityAddComponents, subscriber EventEntityMgrEntityAddComponents, priority ...int32) event.Hook
func BindEventEntityMgrEntityFirstAccessComponent ¶
func BindEventEntityMgrEntityFirstAccessComponent(auto iAutoEventEntityMgrEntityFirstAccessComponent, subscriber EventEntityMgrEntityFirstAccessComponent, priority ...int32) event.Hook
func BindEventEntityMgrEntityRemoveComponent ¶
func BindEventEntityMgrEntityRemoveComponent(auto iAutoEventEntityMgrEntityRemoveComponent, subscriber EventEntityMgrEntityRemoveComponent, priority ...int32) event.Hook
func BindEventEntityMgrRemoveEntity ¶
func BindEventEntityMgrRemoveEntity(auto iAutoEventEntityMgrRemoveEntity, subscriber EventEntityMgrRemoveEntity, priority ...int32) event.Hook
func BindEventEntityMgrRemovingEntity ¶
func BindEventEntityMgrRemovingEntity(auto iAutoEventEntityMgrRemovingEntity, subscriber EventEntityMgrRemovingEntity, priority ...int32) event.Hook
func UnsafeContext
deprecated
func UnsafeContext(ctx Context) _UnsafeContext
Deprecated: UnsafeContext 访问运行时上下文内部方法
func UnsafeECTree
deprecated
func UnsafeECTree(ecTree ECTree) _UnsafeECTree
Deprecated: UnsafeECTree 访问EC树内部方法
func UnsafeFrame
deprecated
func UnsafeFrame(frame Frame) _UnsafeFrame
Deprecated: UnsafeFrame 访问帧内部方法
Types ¶
type AsyncRet ¶
type AsyncRet = concurrent.AsyncRet // 异步调用结果
type Callee ¶
type Callee = concurrent.Callee // 异步调用接受者
type Caller ¶
type Caller = concurrent.Caller // 异步调用发起者
type ConcurrentContext ¶
type ConcurrentContext interface { concurrent.ConcurrentContextProvider concurrent.Context concurrent.Caller // GetName 获取名称 GetName() string // GetId 获取运行时Id GetId() uid.Id }
ConcurrentContext 多线程安全的运行时上下文接口
func Concurrent ¶
func Concurrent(ctxProvider ConcurrentContextProvider) ConcurrentContext
Concurrent 获取多线程安全的运行时上下文
type ConcurrentContextProvider ¶
type ConcurrentContextProvider = concurrent.ConcurrentContextProvider // 多线程安全的上下文提供者
type Context ¶
type Context interface { concurrent.CurrentContextProvider concurrent.ConcurrentContextProvider concurrent.Context concurrent.Caller plugin.PluginProvider container.GCCollector fmt.Stringer // GetName 获取名称 GetName() string // GetId 获取运行时Id GetId() uid.Id // GetFrame 获取帧 GetFrame() Frame // GetEntityMgr 获取实体管理器 GetEntityMgr() EntityMgr // GetECTree 获取主EC树 GetECTree() ECTree // GetFaceAnyAllocator 获取FaceAny内存分配器 GetFaceAnyAllocator() container.Allocator[iface.FaceAny] // GetHookAllocator 获取Hook内存分配器 GetHookAllocator() container.Allocator[event.Hook] // ActivateEvent 启用事件 ActivateEvent(event event.IEventCtrl, recursion event.EventRecursion) // contains filtered or unexported methods }
Context 运行时上下文接口
func NewContext ¶
NewContext 创建运行时上下文
func UnsafeNewContext
deprecated
func UnsafeNewContext(servCtx service.Context, options ContextOptions) Context
Deprecated: UnsafeNewContext 内部创建运行时上下文
type ContextBehavior ¶
type ContextBehavior struct { concurrent.ContextBehavior // contains filtered or unexported fields }
ContextBehavior 运行时上下文行为,在需要扩展运行时上下文能力时,匿名嵌入至运行时上下文结构体中
func (*ContextBehavior) ActivateEvent ¶
func (ctx *ContextBehavior) ActivateEvent(event event.IEventCtrl, recursion event.EventRecursion)
ActivateEvent 启用事件
func (*ContextBehavior) Call ¶
Call 异步调用函数,有返回值。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallDelegate ¶
func (ctx *ContextBehavior) CallDelegate(fun generic.DelegateFuncVar0[any, Ret], va ...any) AsyncRet
CallDelegate 异步调用委托,有返回值。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallVoid ¶
func (ctx *ContextBehavior) CallVoid(fun generic.ActionVar0[any], va ...any) AsyncRet
CallVoid 异步调用函数,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallVoidDelegate ¶
func (ctx *ContextBehavior) CallVoidDelegate(fun generic.DelegateActionVar0[any], va ...any) AsyncRet
CallVoidDelegate 异步调用委托,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CollectGC ¶
func (ctx *ContextBehavior) CollectGC(gc container.GC)
CollectGC 收集GC
func (*ContextBehavior) GetConcurrentContext ¶
func (ctx *ContextBehavior) GetConcurrentContext() iface.Cache
GetConcurrentContext 获取多线程安全的上下文
func (*ContextBehavior) GetContext ¶
func (ctx *ContextBehavior) GetContext() iface.Cache
GetContext 获取上下文
func (*ContextBehavior) GetCurrentContext ¶
func (ctx *ContextBehavior) GetCurrentContext() iface.Cache
GetCurrentContext 获取当前上下文
func (*ContextBehavior) GetEntityMgr ¶
func (ctx *ContextBehavior) GetEntityMgr() EntityMgr
GetEntityMgr 获取实体管理器
func (*ContextBehavior) GetFaceAnyAllocator ¶
func (ctx *ContextBehavior) GetFaceAnyAllocator() container.Allocator[iface.FaceAny]
GetFaceAnyAllocator 获取FaceAny内存分配器
func (*ContextBehavior) GetHookAllocator ¶
func (ctx *ContextBehavior) GetHookAllocator() container.Allocator[event.Hook]
GetHookAllocator 获取Hook内存分配器
func (*ContextBehavior) GetPluginBundle ¶
func (ctx *ContextBehavior) GetPluginBundle() plugin.PluginBundle
GetPluginBundle 获取插件包
func (*ContextBehavior) String ¶
func (ctx *ContextBehavior) String() string
String implements fmt.Stringer
type ContextOptions ¶
type ContextOptions struct { CompositeFace iface.Face[Context] // 扩展者,需要扩展运行时上下文自身能力时需要使用 Context context.Context // 父Context AutoRecover bool // 是否开启panic时自动恢复 ReportError chan error // panic时错误写入的error channel Name string // 运行时名称 PersistId uid.Id // 运行时持久化Id PluginBundle plugin.PluginBundle // 插件包 RunningHandler RunningHandler // 运行状态变化处理器 FaceAnyAllocator container.Allocator[iface.FaceAny] // 自定义FaceAny内存分配器,用于提高性能 HookAllocator container.Allocator[event.Hook] // 自定义Hook内存分配器,用于提高性能 }
ContextOptions 创建运行时上下文的所有选项
type CurrentContextProvider ¶
type CurrentContextProvider = concurrent.CurrentContextProvider // 当前上下文提供者
type ECTree ¶
type ECTree interface { concurrent.CurrentContextProvider // AddChild 实体加入父实体。切换父实体时,先调用RemoveChild()离开旧父实体,再调用AddChild()加入新父实体 AddChild(parentId, childId uid.Id) error // RemoveChild 实体离开父实体,会销毁所有子实体 RemoveChild(childId uid.Id) // RangeChildren 遍历子实体 RangeChildren(parentId uid.Id, fun generic.Func1[ec.Entity, bool]) // ReverseRangeChildren 反向遍历子实体 ReverseRangeChildren(parentId uid.Id, fun generic.Func1[ec.Entity, bool]) // CountChildren 获取子实体数量 CountChildren(parentId uid.Id) int // GetParent 获取子实体的父实体 GetParent(childId uid.Id) (ec.Entity, bool) // contains filtered or unexported methods }
ECTree EC树接口
type EntityMgr ¶
type EntityMgr interface { concurrent.CurrentContextProvider // GetEntity 查询实体 GetEntity(id uid.Id) (ec.Entity, bool) // RangeEntities 遍历所有实体 RangeEntities(fun generic.Func1[ec.Entity, bool]) // ReverseRangeEntities 反向遍历所有实体 ReverseRangeEntities(fun generic.Func1[ec.Entity, bool]) // CountEntities 获取实体数量 CountEntities() int // AddEntity 添加实体 AddEntity(entity ec.Entity, scope ec.Scope) error // RemoveEntity 删除实体 RemoveEntity(id uid.Id) // contains filtered or unexported methods }
EntityMgr 实体管理器接口
type EventECTreeAddChild ¶
EventECTreeAddChild [EmitUnExport] 事件:EC树中子实体加入父实体
type EventECTreeRemoveChild ¶
EventECTreeRemoveChild [EmitUnExport] 事件:EC树中子实体离开父实体
type EventEntityMgrAddEntity ¶
type EventEntityMgrAddEntity interface {
OnEntityMgrAddEntity(entityMgr EntityMgr, entity ec.Entity)
}
EventEntityMgrAddEntity [EmitUnExport] 事件:实体管理器添加实体
type EventEntityMgrEntityAddComponents ¶
type EventEntityMgrEntityAddComponents interface {
OnEntityMgrEntityAddComponents(entityMgr EntityMgr, entity ec.Entity, components []ec.Component)
}
EventEntityMgrEntityAddComponents [EmitUnExport] 事件:实体管理器中的实体添加组件
type EventEntityMgrEntityFirstAccessComponent ¶
type EventEntityMgrEntityFirstAccessComponent interface {
OnEntityMgrEntityFirstAccessComponent(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
}
EventEntityMgrEntityFirstAccessComponent [EmitUnExport] 事件:实体管理器中的实体首次访问组件
type EventEntityMgrEntityRemoveComponent ¶
type EventEntityMgrEntityRemoveComponent interface {
OnEntityMgrEntityRemoveComponent(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
}
EventEntityMgrEntityRemoveComponent [EmitUnExport] 事件:实体管理器中的实体删除组件
type EventEntityMgrRemoveEntity ¶
type EventEntityMgrRemoveEntity interface {
OnEntityMgrRemoveEntity(entityMgr EntityMgr, entity ec.Entity)
}
EventEntityMgrRemoveEntity [EmitUnExport] 事件:实体管理器删除实体
type EventEntityMgrRemovingEntity ¶
type EventEntityMgrRemovingEntity interface {
OnEntityMgrRemovingEntity(entityMgr EntityMgr, entity ec.Entity)
}
EventEntityMgrRemovingEntity [EmitUnExport] 事件:实体管理器开始删除实体
type Frame ¶
type Frame interface { // GetTargetFPS 获取目标FPS GetTargetFPS() float32 // GetCurFPS 获取当前FPS GetCurFPS() float32 // GetTotalFrames 获取运行帧数上限 GetTotalFrames() uint64 // GetCurFrames 获取当前帧数 GetCurFrames() uint64 // GetBlink 获取是否是瞬时运行 GetBlink() bool // GetRunningBeginTime 获取运行开始时间 GetRunningBeginTime() time.Time // GetRunningElapseTime 获取运行持续时间 GetRunningElapseTime() time.Duration // GetLoopBeginTime 获取当前帧循环开始时间(包含异步调用) GetLoopBeginTime() time.Time // GetLastLoopElapseTime 获取上一帧循环耗时(包含异步调用) GetLastLoopElapseTime() time.Duration // GetUpdateBeginTime 获取当前帧更新开始时间 GetUpdateBeginTime() time.Time // GetLastUpdateElapseTime 获取上一次帧更新耗时 GetLastUpdateElapseTime() time.Duration // contains filtered or unexported methods }
Frame 帧,在运行时初始化时可以设置帧,用于设置运行时帧更新方式,在逻辑运行过程中可以在运行时上下文中获取帧信息
type FrameOptions ¶
type FrameOptions struct { TargetFPS float32 // 目标FPS TotalFrames uint64 // 运行帧数上限 Blink bool // 是否是瞬时运行 }
FrameOptions 帧的所有选项
type Option ¶
type Option struct { Context _ContextOption // 运行时上下文的选项设置器 Frame _FrameOption // 帧的选项设置器 }
Option 所有选项设置器
type Ret ¶
type Ret = concurrent.Ret // 调用结果
type RunningHandler ¶
type RunningHandler = generic.DelegateAction2[Context, RunningState] // 运行状态变化处理器
type RunningState ¶
type RunningState int32
RunningState 运行状态
const ( RunningState_Birth RunningState = iota // 出生 RunningState_Starting // 开始启动 RunningState_Started // 已启动 RunningState_FrameLoopBegin // 帧循环开始 RunningState_FrameUpdateBegin // 帧更新开始 RunningState_FrameUpdateEnd // 帧更新结束 RunningState_FrameLoopEnd // 帧循环结束 RunningState_RunCallBegin // Call开始执行 RunningState_RunCallEnd // Call结束执行 RunningState_RunGCBegin // GC开始执行 RunningState_RunGCEnd // GC结束执行 RunningState_Terminating // 开始停止 RunningState_Terminated // 已停止 )
func (RunningState) String ¶
func (i RunningState) String() string
Source Files ¶
- concurrentcontext.go
- context.go
- context_caller.go
- context_conversions.go
- context_current.go
- context_gc.go
- context_options.go
- context_plugin.go
- doc.go
- ectree.go
- ectree_event.go
- ectree_event_code.go
- entitymgr.go
- entitymgr_event.go
- entitymgr_event_code.go
- errors.go
- frame.go
- frame_options.go
- options.go
- runningstate.go
- runningstate_string.go
- unsafe_context.go
- unsafe_ectree.go
- unsafe_frame.go