Documentation ¶
Overview ¶
Package runtime 运行时环境提供的一些接口与函数。
- 运行时上下文(Context)
- 实体管理器(EntityMgr)
- 实体树(EntityTree)
- 帧(Frame)
Index ¶
- Variables
- 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 BindEventEntityTreeAddNode(auto iAutoEventEntityTreeAddNode, subscriber EventEntityTreeAddNode, ...) event.Hook
- func BindEventEntityTreeRemoveNode(auto iAutoEventEntityTreeRemoveNode, subscriber EventEntityTreeRemoveNode, ...) event.Hook
- func UnsafeContext(ctx Context) _UnsafeContextdeprecated
- func UnsafeFrame(frame Frame) _UnsafeFramedeprecated
- 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, async.Ret], va ...any) async.AsyncRet
- func (ctx *ContextBehavior) CallDelegate(fun generic.DelegateFuncVar0[any, async.Ret], va ...any) async.AsyncRet
- func (ctx *ContextBehavior) CallVoid(fun generic.ActionVar0[any], va ...any) async.AsyncRet
- func (ctx *ContextBehavior) CallVoidDelegate(fun generic.DelegateActionVar0[any], va ...any) async.AsyncRet
- func (ctx *ContextBehavior) CollectGC(gc GC)
- func (ctx *ContextBehavior) GetCompositeFaceCache() iface.Cache
- func (ctx *ContextBehavior) GetConcurrentContext() iface.Cache
- func (ctx *ContextBehavior) GetCurrentContext() iface.Cache
- func (ctx *ContextBehavior) GetEntityMgr() EntityMgr
- func (ctx *ContextBehavior) GetEntityTree() EntityTree
- func (ctx *ContextBehavior) GetFrame() Frame
- func (ctx *ContextBehavior) GetId() uid.Id
- func (ctx *ContextBehavior) GetName() string
- func (ctx *ContextBehavior) GetPluginBundle() plugin.PluginBundle
- func (ctx *ContextBehavior) GetReflected() reflect.Value
- func (ctx *ContextBehavior) ManagedHooks(hooks ...event.Hook)
- func (ctx *ContextBehavior) String() string
- type ContextOptions
- type CurrentContextProvider
- type EntityMgr
- type EntityTree
- type EventEntityMgrAddEntity
- type EventEntityMgrAddEntityHandler
- type EventEntityMgrEntityAddComponents
- type EventEntityMgrEntityAddComponentsHandler
- type EventEntityMgrEntityFirstAccessComponent
- type EventEntityMgrEntityFirstAccessComponentHandler
- type EventEntityMgrEntityRemoveComponent
- type EventEntityMgrEntityRemoveComponentHandler
- type EventEntityMgrRemoveEntity
- type EventEntityMgrRemoveEntityHandler
- type EventEntityTreeAddNode
- type EventEntityTreeAddNodeHandler
- type EventEntityTreeRemoveNode
- type EventEntityTreeRemoveNodeHandler
- type Frame
- type FrameOptions
- type GC
- type GCCollector
- type RunningHandler
- type RunningState
Constants ¶
This section is empty.
Variables ¶
var ( ErrContext = fmt.Errorf("%w: runtime-context", exception.ErrCore) // 运行时上下文错误 ErrEntityTree = fmt.Errorf("%w: entity-tree", ErrContext) // 实体树错误 ErrEntityMgr = fmt.Errorf("%w: entity-mgr", ErrContext) // 实体管理器错误 ErrFrame = fmt.Errorf("%w: frame", ErrContext) // 帧错误 )
var With _Option
Functions ¶
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 BindEventEntityTreeAddNode ¶ added in v0.2.58
func BindEventEntityTreeAddNode(auto iAutoEventEntityTreeAddNode, subscriber EventEntityTreeAddNode, priority ...int32) event.Hook
func BindEventEntityTreeRemoveNode ¶ added in v0.2.58
func BindEventEntityTreeRemoveNode(auto iAutoEventEntityTreeRemoveNode, subscriber EventEntityTreeRemoveNode, priority ...int32) event.Hook
func UnsafeContext
deprecated
func UnsafeContext(ctx Context) _UnsafeContext
Deprecated: UnsafeContext 访问运行时上下文内部方法
func UnsafeFrame
deprecated
func UnsafeFrame(frame Frame) _UnsafeFrame
Deprecated: UnsafeFrame 访问帧内部方法
Types ¶
type ConcurrentContext ¶
type ConcurrentContext interface { gctx.ConcurrentContextProvider gctx.Context async.Caller fmt.Stringer // GetName 获取名称 GetName() string // GetId 获取运行时Id GetId() uid.Id }
ConcurrentContext 多线程安全的运行时上下文接口
func Concurrent ¶
func Concurrent(provider gctx.ConcurrentContextProvider) ConcurrentContext
Concurrent 获取多线程安全的运行时上下文
type ConcurrentContextProvider ¶
type ConcurrentContextProvider = gctx.ConcurrentContextProvider
ConcurrentContextProvider 多线程安全的上下文提供者
type Context ¶
type Context interface { gctx.CurrentContextProvider gctx.Context async.Caller reinterpret.CompositeProvider plugin.PluginProvider GCCollector fmt.Stringer // GetName 获取名称 GetName() string // GetId 获取运行时Id GetId() uid.Id // GetReflected 获取反射值 GetReflected() reflect.Value // GetFrame 获取帧 GetFrame() Frame // GetEntityMgr 获取实体管理器 GetEntityMgr() EntityMgr // GetEntityTree 获取实体树 GetEntityTree() EntityTree // ActivateEvent 启用事件 ActivateEvent(event event.IEventCtrl, recursion event.EventRecursion) // ManagedHooks 托管hook,在运行时停止时自动解绑定 ManagedHooks(hooks ...event.Hook) // 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 { gctx.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, async.Ret], va ...any) async.AsyncRet
CallDelegate 异步调用委托,有返回值。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallVoid ¶
func (ctx *ContextBehavior) CallVoid(fun generic.ActionVar0[any], va ...any) async.AsyncRet
CallVoid 异步调用函数,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallVoidDelegate ¶
func (ctx *ContextBehavior) CallVoidDelegate(fun generic.DelegateActionVar0[any], va ...any) async.AsyncRet
CallVoidDelegate 异步调用委托,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) GetCompositeFaceCache ¶ added in v0.2.34
func (ctx *ContextBehavior) GetCompositeFaceCache() iface.Cache
GetCompositeFaceCache 支持重新解释类型
func (*ContextBehavior) GetConcurrentContext ¶
func (ctx *ContextBehavior) GetConcurrentContext() iface.Cache
GetConcurrentContext 获取多线程安全的上下文
func (*ContextBehavior) GetCurrentContext ¶
func (ctx *ContextBehavior) GetCurrentContext() iface.Cache
GetCurrentContext 获取当前上下文
func (*ContextBehavior) GetEntityMgr ¶
func (ctx *ContextBehavior) GetEntityMgr() EntityMgr
GetEntityMgr 获取实体管理器
func (*ContextBehavior) GetEntityTree ¶ added in v0.2.58
func (ctx *ContextBehavior) GetEntityTree() EntityTree
GetEntityTree 获取主实体树
func (*ContextBehavior) GetPluginBundle ¶
func (ctx *ContextBehavior) GetPluginBundle() plugin.PluginBundle
GetPluginBundle 获取插件包
func (*ContextBehavior) GetReflected ¶ added in v0.2.58
func (ctx *ContextBehavior) GetReflected() reflect.Value
GetReflected 获取反射值
func (*ContextBehavior) ManagedHooks ¶ added in v0.2.28
func (ctx *ContextBehavior) ManagedHooks(hooks ...event.Hook)
ManagedHooks 托管hook,在运行时停止时自动解绑定
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 // 运行状态变化处理器 }
ContextOptions 创建运行时上下文的所有选项
type CurrentContextProvider ¶
type CurrentContextProvider = gctx.CurrentContextProvider
CurrentContextProvider 当前上下文提供者
type EntityMgr ¶
type EntityMgr interface { gctx.CurrentContextProvider // AddEntity 添加实体 AddEntity(entity ec.Entity) error // RemoveEntity 删除实体 RemoveEntity(id uid.Id) // GetEntity 查询实体 GetEntity(id uid.Id) (ec.Entity, bool) // ContainsEntity 实体是否存在 ContainsEntity(id uid.Id) bool // RangeEntities 遍历所有实体 RangeEntities(fun generic.Func1[ec.Entity, bool]) // ReversedRangeEntities 反向遍历所有实体 ReversedRangeEntities(fun generic.Func1[ec.Entity, bool]) // FilterEntities 过滤并获取实体 FilterEntities(fun generic.Func1[ec.Entity, bool]) []ec.Entity // GetEntities 获取所有实体 GetEntities() []ec.Entity // CountEntities 获取实体数量 CountEntities() int // contains filtered or unexported methods }
EntityMgr 实体管理器接口
type EntityTree ¶ added in v0.2.58
type EntityTree interface { gctx.CurrentContextProvider // AddNode 新增实体节点,会向实体管理器添加实体 AddNode(entity ec.Entity, parentId uid.Id) error // PruningNode 实体树节点剪枝 PruningNode(entityId uid.Id) // RangeChildren 遍历子实体 RangeChildren(entityId uid.Id, fun generic.Func1[ec.Entity, bool]) // ReversedRangeChildren 反向遍历子实体 ReversedRangeChildren(entityId uid.Id, fun generic.Func1[ec.Entity, bool]) // FilterChildren 过滤并获取子实体 FilterChildren(entityId uid.Id, fun generic.Func1[ec.Entity, bool]) []ec.Entity // GetChildren 获取所有子实体 GetChildren(entityId uid.Id) []ec.Entity // CountChildren 获取子实体数量 CountChildren(entityId uid.Id) int // IsTop 是否是顶层节点 IsTop(entityId uid.Id) bool // ChangeParent 修改父实体 ChangeParent(entityId, parentId uid.Id) error // GetParent 获取父实体 GetParent(entityId uid.Id) (ec.Entity, bool) // contains filtered or unexported methods }
EntityTree 实体树接口
type EventEntityMgrAddEntity ¶
type EventEntityMgrAddEntity interface {
OnEntityMgrAddEntity(entityMgr EntityMgr, entity ec.Entity)
}
EventEntityMgrAddEntity [EmitUnExport] 事件:实体管理器添加实体
type EventEntityMgrAddEntityHandler ¶ added in v0.2.51
func HandleEventEntityMgrAddEntity ¶ added in v0.2.50
func HandleEventEntityMgrAddEntity(fun func(entityMgr EntityMgr, entity ec.Entity)) EventEntityMgrAddEntityHandler
func (EventEntityMgrAddEntityHandler) OnEntityMgrAddEntity ¶ added in v0.2.51
func (h EventEntityMgrAddEntityHandler) OnEntityMgrAddEntity(entityMgr EntityMgr, entity ec.Entity)
type EventEntityMgrEntityAddComponents ¶
type EventEntityMgrEntityAddComponents interface {
OnEntityMgrEntityAddComponents(entityMgr EntityMgr, entity ec.Entity, components []ec.Component)
}
EventEntityMgrEntityAddComponents [EmitUnExport] 事件:实体管理器中的实体添加组件
type EventEntityMgrEntityAddComponentsHandler ¶ added in v0.2.51
type EventEntityMgrEntityAddComponentsHandler func(entityMgr EntityMgr, entity ec.Entity, components []ec.Component)
func HandleEventEntityMgrEntityAddComponents ¶ added in v0.2.50
func (EventEntityMgrEntityAddComponentsHandler) OnEntityMgrEntityAddComponents ¶ added in v0.2.51
type EventEntityMgrEntityFirstAccessComponent ¶
type EventEntityMgrEntityFirstAccessComponent interface {
OnEntityMgrEntityFirstAccessComponent(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
}
EventEntityMgrEntityFirstAccessComponent [EmitUnExport] 事件:实体管理器中的实体首次访问组件
type EventEntityMgrEntityFirstAccessComponentHandler ¶ added in v0.2.51
type EventEntityMgrEntityFirstAccessComponentHandler func(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
func HandleEventEntityMgrEntityFirstAccessComponent ¶ added in v0.2.50
func (EventEntityMgrEntityFirstAccessComponentHandler) OnEntityMgrEntityFirstAccessComponent ¶ added in v0.2.51
type EventEntityMgrEntityRemoveComponent ¶
type EventEntityMgrEntityRemoveComponent interface {
OnEntityMgrEntityRemoveComponent(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
}
EventEntityMgrEntityRemoveComponent [EmitUnExport] 事件:实体管理器中的实体删除组件
type EventEntityMgrEntityRemoveComponentHandler ¶ added in v0.2.51
type EventEntityMgrEntityRemoveComponentHandler func(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
func HandleEventEntityMgrEntityRemoveComponent ¶ added in v0.2.50
func (EventEntityMgrEntityRemoveComponentHandler) OnEntityMgrEntityRemoveComponent ¶ added in v0.2.51
type EventEntityMgrRemoveEntity ¶
type EventEntityMgrRemoveEntity interface {
OnEntityMgrRemoveEntity(entityMgr EntityMgr, entity ec.Entity)
}
EventEntityMgrRemoveEntity [EmitUnExport] 事件:实体管理器删除实体
type EventEntityMgrRemoveEntityHandler ¶ added in v0.2.51
func HandleEventEntityMgrRemoveEntity ¶ added in v0.2.50
func HandleEventEntityMgrRemoveEntity(fun func(entityMgr EntityMgr, entity ec.Entity)) EventEntityMgrRemoveEntityHandler
func (EventEntityMgrRemoveEntityHandler) OnEntityMgrRemoveEntity ¶ added in v0.2.51
func (h EventEntityMgrRemoveEntityHandler) OnEntityMgrRemoveEntity(entityMgr EntityMgr, entity ec.Entity)
type EventEntityTreeAddNode ¶ added in v0.2.58
type EventEntityTreeAddNode interface {
OnEntityTreeAddNode(entityTree EntityTree, parent, child ec.Entity)
}
EventEntityTreeAddNode [EmitUnExport] 事件:新增实体树节点
type EventEntityTreeAddNodeHandler ¶ added in v0.2.58
type EventEntityTreeAddNodeHandler func(entityTree EntityTree, parent, child ec.Entity)
func HandleEventEntityTreeAddNode ¶ added in v0.2.58
func HandleEventEntityTreeAddNode(fun func(entityTree EntityTree, parent, child ec.Entity)) EventEntityTreeAddNodeHandler
func (EventEntityTreeAddNodeHandler) OnEntityTreeAddNode ¶ added in v0.2.58
func (h EventEntityTreeAddNodeHandler) OnEntityTreeAddNode(entityTree EntityTree, parent, child ec.Entity)
type EventEntityTreeRemoveNode ¶ added in v0.2.58
type EventEntityTreeRemoveNode interface {
OnEntityTreeRemoveNode(entityTree EntityTree, parent, child ec.Entity)
}
EventEntityTreeRemoveNode [EmitUnExport] 事件:删除实体树节点
type EventEntityTreeRemoveNodeHandler ¶ added in v0.2.58
type EventEntityTreeRemoveNodeHandler func(entityTree EntityTree, parent, child ec.Entity)
func HandleEventEntityTreeRemoveNode ¶ added in v0.2.58
func HandleEventEntityTreeRemoveNode(fun func(entityTree EntityTree, parent, child ec.Entity)) EventEntityTreeRemoveNodeHandler
func (EventEntityTreeRemoveNodeHandler) OnEntityTreeRemoveNode ¶ added in v0.2.58
func (h EventEntityTreeRemoveNodeHandler) OnEntityTreeRemoveNode(entityTree EntityTree, parent, child ec.Entity)
type Frame ¶
type Frame interface { // GetTargetFPS 获取目标FPS GetTargetFPS() float32 // GetCurFPS 获取当前FPS GetCurFPS() float32 // GetTotalFrames 获取运行帧数上限 GetTotalFrames() uint64 // GetCurFrames 获取当前帧数 GetCurFrames() uint64 // 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 ¶
FrameOptions 帧的所有选项
type GC ¶ added in v0.2.53
type GC interface { // GC GC GC() // NeedGC 是否需要GC NeedGC() bool }
GC GC接口
type GCCollector ¶ added in v0.2.53
type GCCollector interface { // CollectGC 收集GC CollectGC(gc GC) }
GCCollector GC收集器接口
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 ¶
- context.go
- context_caller.go
- context_concurrent.go
- context_current.go
- context_gc.go
- context_managedhooks.go
- context_options.go
- context_plugin.go
- doc.go
- entitymgr.go
- entitymgr_event.go
- entitymgr_event_code.go
- entitytree.go
- entitytree_event.go
- entitytree_event_code.go
- errors.go
- frame.go
- frame_options.go
- gc.go
- options.go
- runningstate.go
- runningstate_string.go
- unsafe_context.go
- unsafe_frame.go