runtime

package
v0.2.57 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: LGPL-2.1 Imports: 18 Imported by: 15

Documentation

Overview

Package runtime 运行时环境提供的一些接口与函数。

  • 运行时上下文(Context)
  • 实体管理器(EntityMgr)
  • EC树(ECTree)
  • 帧(Frame)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContext   = fmt.Errorf("%w: runtime-context", exception.ErrCore) // 运行时上下文错误
	ErrECTree    = fmt.Errorf("%w: ec-tree", ErrContext)                // EC树错误
	ErrEntityMgr = fmt.Errorf("%w: entity-mgr", ErrContext)             // 实体管理器错误
	ErrFrame     = fmt.Errorf("%w: frame", ErrContext)                  // 帧错误
)
View Source
var (
	ErrAsyncRetClosed = concurrent.ErrAsyncRetClosed
)
View Source
var (
	MakeRet = concurrent.MakeRet // 创建调用结果
)
View Source
var With _Option

Functions

func BindEventECTreeAddChild

func BindEventECTreeAddChild(auto _AutoEventECTreeAddChild, subscriber EventECTreeAddChild, priority ...int32) event.Hook

func BindEventECTreeRemoveChild

func BindEventECTreeRemoveChild(auto _AutoEventECTreeRemoveChild, subscriber EventECTreeRemoveChild, priority ...int32) event.Hook

func BindEventEntityMgrAddEntity

func BindEventEntityMgrAddEntity(auto _AutoEventEntityMgrAddEntity, subscriber EventEntityMgrAddEntity, priority ...int32) event.Hook

func BindEventEntityMgrEntityAddComponents

func BindEventEntityMgrEntityAddComponents(auto _AutoEventEntityMgrEntityAddComponents, subscriber EventEntityMgrEntityAddComponents, priority ...int32) event.Hook

func BindEventEntityMgrEntityFirstAccessComponent

func BindEventEntityMgrEntityFirstAccessComponent(auto _AutoEventEntityMgrEntityFirstAccessComponent, subscriber EventEntityMgrEntityFirstAccessComponent, priority ...int32) event.Hook

func BindEventEntityMgrEntityRemoveComponent

func BindEventEntityMgrEntityRemoveComponent(auto _AutoEventEntityMgrEntityRemoveComponent, subscriber EventEntityMgrEntityRemoveComponent, priority ...int32) event.Hook

func BindEventEntityMgrRemoveEntity

func BindEventEntityMgrRemoveEntity(auto _AutoEventEntityMgrRemoveEntity, subscriber EventEntityMgrRemoveEntity, priority ...int32) event.Hook

func BindEventEntityMgrRemovingEntity

func BindEventEntityMgrRemovingEntity(auto _AutoEventEntityMgrRemovingEntity, 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.Context
	concurrent.Caller
	reinterpret.CompositeProvider
	plugin.PluginProvider
	GCCollector
	fmt.Stringer

	// GetName 获取名称
	GetName() string
	// GetId 获取运行时Id
	GetId() uid.Id
	// GetFrame 获取帧
	GetFrame() Frame
	// GetEntityMgr 获取实体管理器
	GetEntityMgr() EntityMgr
	// GetECTree 获取主EC树
	GetECTree() ECTree
	// ActivateEvent 启用事件
	ActivateEvent(event event.IEventCtrl, recursion event.EventRecursion)
	// ManagedHooks 托管hook,在运行时停止时自动解绑定
	ManagedHooks(hooks ...event.Hook)
	// contains filtered or unexported methods
}

Context 运行时上下文接口

func Current

func Current(ctxProvider CurrentContextProvider) Context

Current 获取当前运行时上下文

func NewContext

func NewContext(servCtx service.Context, settings ...option.Setting[ContextOptions]) Context

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

func (ctx *ContextBehavior) Call(fun generic.FuncVar0[any, Ret], va ...any) AsyncRet

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 GC)

CollectGC 收集GC

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) GetECTree

func (ctx *ContextBehavior) GetECTree() ECTree

GetECTree 获取主EC树

func (*ContextBehavior) GetEntityMgr

func (ctx *ContextBehavior) GetEntityMgr() EntityMgr

GetEntityMgr 获取实体管理器

func (*ContextBehavior) GetFrame

func (ctx *ContextBehavior) GetFrame() Frame

GetFrame 获取帧

func (*ContextBehavior) GetId

func (ctx *ContextBehavior) GetId() uid.Id

GetId 获取运行时Id

func (*ContextBehavior) GetName

func (ctx *ContextBehavior) GetName() string

GetName 获取名称

func (*ContextBehavior) GetPluginBundle

func (ctx *ContextBehavior) GetPluginBundle() plugin.PluginBundle

GetPluginBundle 获取插件包

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 = 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) error
	// RemoveEntity 删除实体
	RemoveEntity(id uid.Id)
	// contains filtered or unexported methods
}

EntityMgr 实体管理器接口

type EventECTreeAddChild

type EventECTreeAddChild interface {
	OnAddChild(ecTree ECTree, parent, child ec.Entity)
}

EventECTreeAddChild [EmitUnExport] 事件:EC树中子实体加入父实体

type EventECTreeAddChildHandler added in v0.2.51

type EventECTreeAddChildHandler func(ecTree ECTree, parent, child ec.Entity)

func HandleEventECTreeAddChild added in v0.2.50

func HandleEventECTreeAddChild(fun func(ecTree ECTree, parent, child ec.Entity)) EventECTreeAddChildHandler

func (EventECTreeAddChildHandler) OnAddChild added in v0.2.51

func (h EventECTreeAddChildHandler) OnAddChild(ecTree ECTree, parent, child ec.Entity)

type EventECTreeRemoveChild

type EventECTreeRemoveChild interface {
	OnRemoveChild(ecTree ECTree, parent, child ec.Entity)
}

EventECTreeRemoveChild [EmitUnExport] 事件:EC树中子实体离开父实体

type EventECTreeRemoveChildHandler added in v0.2.51

type EventECTreeRemoveChildHandler func(ecTree ECTree, parent, child ec.Entity)

func HandleEventECTreeRemoveChild added in v0.2.50

func HandleEventECTreeRemoveChild(fun func(ecTree ECTree, parent, child ec.Entity)) EventECTreeRemoveChildHandler

func (EventECTreeRemoveChildHandler) OnRemoveChild added in v0.2.51

func (h EventECTreeRemoveChildHandler) OnRemoveChild(ecTree ECTree, parent, child ec.Entity)

type EventEntityMgrAddEntity

type EventEntityMgrAddEntity interface {
	OnEntityMgrAddEntity(entityMgr EntityMgr, entity ec.Entity)
}

EventEntityMgrAddEntity [EmitUnExport] 事件:实体管理器添加实体

type EventEntityMgrAddEntityHandler added in v0.2.51

type EventEntityMgrAddEntityHandler func(entityMgr EntityMgr, entity ec.Entity)

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 HandleEventEntityMgrEntityAddComponents(fun func(entityMgr EntityMgr, entity ec.Entity, components []ec.Component)) EventEntityMgrEntityAddComponentsHandler

func (EventEntityMgrEntityAddComponentsHandler) OnEntityMgrEntityAddComponents added in v0.2.51

func (h EventEntityMgrEntityAddComponentsHandler) OnEntityMgrEntityAddComponents(entityMgr EntityMgr, entity ec.Entity, components []ec.Component)

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 HandleEventEntityMgrEntityFirstAccessComponent(fun func(entityMgr EntityMgr, entity ec.Entity, component ec.Component)) EventEntityMgrEntityFirstAccessComponentHandler

func (EventEntityMgrEntityFirstAccessComponentHandler) OnEntityMgrEntityFirstAccessComponent added in v0.2.51

func (h EventEntityMgrEntityFirstAccessComponentHandler) OnEntityMgrEntityFirstAccessComponent(entityMgr EntityMgr, entity ec.Entity, component ec.Component)

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 HandleEventEntityMgrEntityRemoveComponent(fun func(entityMgr EntityMgr, entity ec.Entity, component ec.Component)) EventEntityMgrEntityRemoveComponentHandler

func (EventEntityMgrEntityRemoveComponentHandler) OnEntityMgrEntityRemoveComponent added in v0.2.51

func (h EventEntityMgrEntityRemoveComponentHandler) OnEntityMgrEntityRemoveComponent(entityMgr EntityMgr, entity ec.Entity, component ec.Component)

type EventEntityMgrRemoveEntity

type EventEntityMgrRemoveEntity interface {
	OnEntityMgrRemoveEntity(entityMgr EntityMgr, entity ec.Entity)
}

EventEntityMgrRemoveEntity [EmitUnExport] 事件:实体管理器删除实体

type EventEntityMgrRemoveEntityHandler added in v0.2.51

type EventEntityMgrRemoveEntityHandler func(entityMgr EntityMgr, entity ec.Entity)

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 EventEntityMgrRemovingEntity

type EventEntityMgrRemovingEntity interface {
	OnEntityMgrRemovingEntity(entityMgr EntityMgr, entity ec.Entity)
}

EventEntityMgrRemovingEntity [EmitUnExport] 事件:实体管理器开始删除实体

type EventEntityMgrRemovingEntityHandler added in v0.2.51

type EventEntityMgrRemovingEntityHandler func(entityMgr EntityMgr, entity ec.Entity)

func HandleEventEntityMgrRemovingEntity added in v0.2.50

func HandleEventEntityMgrRemovingEntity(fun func(entityMgr EntityMgr, entity ec.Entity)) EventEntityMgrRemovingEntityHandler

func (EventEntityMgrRemovingEntityHandler) OnEntityMgrRemovingEntity added in v0.2.51

func (h EventEntityMgrRemovingEntityHandler) OnEntityMgrRemovingEntity(entityMgr EntityMgr, entity ec.Entity)

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 帧,在运行时初始化时可以设置帧,用于设置运行时帧更新方式,在逻辑运行过程中可以在运行时上下文中获取帧信息

func NewFrame

func NewFrame(settings ...option.Setting[FrameOptions]) Frame

NewFrame 创建帧,在运行时初始化时可以设置帧,用于设置运行时帧更新方式,在逻辑运行过程中可以在运行时上下文中获取帧信息。

type FrameOptions

type FrameOptions struct {
	TargetFPS   float32 // 目标FPS
	TotalFrames uint64  // 运行帧数上限
	Blink       bool    // 是否是瞬时运行
}

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 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

Jump to

Keyboard shortcuts

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