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 BindEventEntityMgrEntityFirstTouchComponent(auto iAutoEventEntityMgrEntityFirstTouchComponent, ...) 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 UnsafeConcurrentContext(context ConcurrentContext) _UnsafeConcurrentContextdeprecated
- 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], args ...any) async.AsyncRet
- func (ctx *ContextBehavior) CallDelegate(fun generic.DelegateFuncVar0[any, async.Ret], args ...any) async.AsyncRet
- func (ctx *ContextBehavior) CallVoid(fun generic.ActionVar0[any], args ...any) async.AsyncRet
- func (ctx *ContextBehavior) CallVoidDelegate(fun generic.DelegateActionVar0[any], args ...any) async.AsyncRet
- func (ctx *ContextBehavior) CollectGC(gc GC)
- 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) GetInstanceFaceCache() iface.Cache
- 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 EventEntityMgrEntityFirstTouchComponent
- type EventEntityMgrEntityFirstTouchComponentHandler
- 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 IEntityMgrEventTab
- type IEntityTreeEventTab
- type RunningHandler
- type RunningState
Constants ¶
This section is empty.
Variables ¶
var ( EventEntityMgrAddEntityId = _entityMgrEventTabId + 0 EventEntityMgrRemoveEntityId = _entityMgrEventTabId + 1 EventEntityMgrEntityAddComponentsId = _entityMgrEventTabId + 2 EventEntityMgrEntityRemoveComponentId = _entityMgrEventTabId + 3 EventEntityMgrEntityFirstTouchComponentId = _entityMgrEventTabId + 4 )
var ( EventEntityTreeAddNodeId = _entityTreeEventTabId + 0 EventEntityTreeRemoveNodeId = _entityTreeEventTabId + 1 )
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 BindEventEntityMgrEntityFirstTouchComponent ¶ added in v0.3.47
func BindEventEntityMgrEntityFirstTouchComponent(auto iAutoEventEntityMgrEntityFirstTouchComponent, subscriber EventEntityMgrEntityFirstTouchComponent, 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 UnsafeConcurrentContext
deprecated
added in
v0.3.21
func UnsafeConcurrentContext(context ConcurrentContext) _UnsafeConcurrentContext
Deprecated: UnsafeConcurrentContext 访问多线程安全的上下文接口内部函数
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 { ictx.Context ictx.ConcurrentContextProvider async.Caller fmt.Stringer // GetName 获取名称 GetName() string // GetId 获取运行时Id GetId() uid.Id // contains filtered or unexported methods }
ConcurrentContext 多线程安全的运行时上下文接口
func Concurrent ¶
func Concurrent(provider ictx.ConcurrentContextProvider) ConcurrentContext
Concurrent 获取多线程安全的运行时上下文
type ConcurrentContextProvider ¶
type ConcurrentContextProvider = ictx.ConcurrentContextProvider
ConcurrentContextProvider 多线程安全的上下文提供者
type Context ¶
type Context interface { ictx.Context ictx.CurrentContextProvider reinterpret.InstanceProvider plugin.PluginProvider async.Caller 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(svcCtx service.Context, options ContextOptions) Context
Deprecated: UnsafeNewContext 内部创建运行时上下文
type ContextBehavior ¶
type ContextBehavior struct { ictx.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], args ...any) async.AsyncRet
CallDelegate 异步调用委托,有返回值。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallVoid ¶
func (ctx *ContextBehavior) CallVoid(fun generic.ActionVar0[any], args ...any) async.AsyncRet
CallVoid 异步调用函数,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallVoidDelegate ¶
func (ctx *ContextBehavior) CallVoidDelegate(fun generic.DelegateActionVar0[any], args ...any) async.AsyncRet
CallVoidDelegate 异步调用委托,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
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) GetInstanceFaceCache ¶ added in v0.3.34
func (ctx *ContextBehavior) GetInstanceFaceCache() iface.Cache
GetInstanceFaceCache 支持重新解释类型
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 { InstanceFace 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 = ictx.CurrentContextProvider
CurrentContextProvider 当前上下文提供者
type EntityMgr ¶
type EntityMgr interface { ictx.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 IEntityMgrEventTab }
EntityMgr 实体管理器接口
type EntityTree ¶ added in v0.2.58
type EntityTree interface { ictx.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) IEntityTreeEventTab }
EntityTree 实体树接口
type EventEntityMgrAddEntity ¶
type EventEntityMgrAddEntity interface {
OnEntityMgrAddEntity(entityMgr EntityMgr, entity ec.Entity)
}
EventEntityMgrAddEntity 事件:实体管理器添加实体 +event-gen:export=0
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 事件:实体管理器中的实体添加组件 +event-gen:export=0
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 EventEntityMgrEntityFirstTouchComponent ¶ added in v0.3.47
type EventEntityMgrEntityFirstTouchComponent interface {
OnEntityMgrEntityFirstTouchComponent(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
}
EventEntityMgrEntityFirstTouchComponent 事件:实体管理器中的实体首次访问组件 +event-gen:export=0
type EventEntityMgrEntityFirstTouchComponentHandler ¶ added in v0.3.47
type EventEntityMgrEntityFirstTouchComponentHandler func(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
func HandleEventEntityMgrEntityFirstTouchComponent ¶ added in v0.3.47
func (EventEntityMgrEntityFirstTouchComponentHandler) OnEntityMgrEntityFirstTouchComponent ¶ added in v0.3.47
type EventEntityMgrEntityRemoveComponent ¶
type EventEntityMgrEntityRemoveComponent interface {
OnEntityMgrEntityRemoveComponent(entityMgr EntityMgr, entity ec.Entity, component ec.Component)
}
EventEntityMgrEntityRemoveComponent 事件:实体管理器中的实体删除组件 +event-gen:export=0
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 事件:实体管理器删除实体 +event-gen:export=0
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 事件:新增实体树节点 +event-gen:export=0
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 事件:删除实体树节点 +event-gen:export=0
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() int64 // GetCurFrames 获取当前帧数 GetCurFrames() int64 // 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 IEntityMgrEventTab ¶ added in v0.3.48
type IEntityTreeEventTab ¶ added in v0.3.48
type RunningHandler ¶
type RunningHandler = generic.DelegateActionVar2[Context, RunningState, any] // 运行状态变化处理器
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 // 已停止 RunningState_PluginActivating // 开始激活插件 RunningState_PluginActivated // 插件已激活 RunningState_PluginDeactivating // 开始去激活插件 RunningState_PluginDeactivated // 插件已去激活 )
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.gen.go
- entitymgr_event.go
- entitymgr_event.tab.gen.go
- entitytree.go
- entitytree_event.gen.go
- entitytree_event.go
- entitytree_event.tab.gen.go
- errors.go
- frame.go
- frame_options.go
- gc.go
- options.go
- runningstate.go
- runningstate_string.go
- unsafe_concurrentcontext.go
- unsafe_context.go
- unsafe_frame.go