tiny

package module
v0.1.53 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: LGPL-2.1 Imports: 23 Imported by: 0

README

tiny

轻量的EC组件代码框架(Entity Component),适用性能要求较高的场景。

Install

go get -u git.golaxy.org/tiny

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTiny     = exception.ErrTiny                  // 内核错误
	ErrPanicked = exception.ErrPanicked              // panic错误
	ErrArgs     = exception.ErrArgs                  // 参数错误
	ErrRuntime  = fmt.Errorf("%w: runtime", ErrTiny) // 运行时错误
)
View Source
var (
	ErrTaskQueueClosed = fmt.Errorf("%w: task queue is closed", ErrRuntime) // 任务处理流水线关闭
	ErrTaskQueueFull   = fmt.Errorf("%w: task queue is full", ErrRuntime)   // 任务处理流水线已满
)
View Source
var (
	ErrAllAsyncRetExceeded = fmt.Errorf("%w: all of async result exceeded, %w", ErrTiny, context.DeadlineExceeded)
)
View Source
var (
	ErrCtrlChanClosed = fmt.Errorf("%w: ctrl chan is closed", ErrRuntime) // 运行控制已关闭
)
View Source
var With _Option

Functions

func CallAsync added in v0.1.52

CallAsync 异步执行代码,有返回值

func CallVoidAsync added in v0.1.52

func CallVoidAsync(provider corectx.ConcurrentContextProvider, fun generic.ActionVar1[runtime.Context, any], args ...any) async.AsyncRet

CallVoidAsync 异步执行代码,无返回值

func GoAsync added in v0.1.52

func GoAsync(ctx context.Context, fun generic.FuncVar1[context.Context, any, async.Ret], args ...any) async.AsyncRet

GoAsync 使用新线程执行代码,有返回值

func GoVoidAsync added in v0.1.52

func GoVoidAsync(ctx context.Context, fun generic.ActionVar1[context.Context, any], args ...any) async.AsyncRet

GoVoidAsync 使用新线程执行代码,无返回值

func ReadChanAsync added in v0.1.52

func ReadChanAsync(ctx context.Context, ch <-chan any) async.AsyncRet

ReadChanAsync 读取channel转换为AsyncRet

func ReadChanAsyncT added in v0.1.52

func ReadChanAsyncT[T any](ctx context.Context, ch <-chan T) async.AsyncRet

ReadChanAsyncT 读取channel转换为AsyncRet

func TimeAfterAsync added in v0.1.52

func TimeAfterAsync(ctx context.Context, dur time.Duration) async.AsyncRet

TimeAfterAsync 定时器,指定时长

func TimeAtAsync added in v0.1.52

func TimeAtAsync(ctx context.Context, at time.Time) async.AsyncRet

TimeAtAsync 定时器,指定时间点

func TimeTickAsync added in v0.1.52

func TimeTickAsync(ctx context.Context, dur time.Duration) async.AsyncRet

TimeTickAsync 心跳器

func UnsafeRuntime

func UnsafeRuntime(runtime Runtime) _UnsafeRuntime

Types

type AwaitDirector

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

AwaitDirector 异步等待分发器

func Await

func Await(provider corectx.CurrentContextProvider, asyncRets ...async.AsyncRet) AwaitDirector

Await 异步等待结果返回

func (AwaitDirector) All

All 异步等待所有结果返回,有返回值

func (AwaitDirector) AllVoid added in v0.1.52

func (ad AwaitDirector) AllVoid(fun generic.ActionVar2[runtime.Context, []async.Ret, any], args ...any) async.AsyncRet

AllVoid 异步等待所有结果返回,无返回值

func (AwaitDirector) Any

Any 异步等待任意一个结果返回,有返回值

func (AwaitDirector) AnyVoid added in v0.1.52

AnyVoid 异步等待任意一个结果返回,无返回值

func (AwaitDirector) Foreach added in v0.1.52

Foreach 异步等待产出(yield)返回

func (AwaitDirector) OK added in v0.1.52

OK 异步等待任意一个结果成功返回,有返回值

func (AwaitDirector) OKVoid added in v0.1.52

OKVoid 异步等待任意一个结果成功返回,无返回值

func (AwaitDirector) Transform added in v0.1.52

func (ad AwaitDirector) Transform(fun generic.FuncVar2[runtime.Context, async.Ret, any, async.Ret], args ...any) async.AsyncRet

Transform 异步等待产出(yield)返回,并变换结果

type CustomGC

type CustomGC = generic.Action1[Runtime] // 自定义GC函数

type EntityCreator added in v0.1.52

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

EntityCreator 实体构建器

func BuildEntity added in v0.1.52

func BuildEntity(provider corectx.CurrentContextProvider, prototype string) *EntityCreator

BuildEntity 创建实体

func (*EntityCreator) AssignMeta added in v0.1.52

func (c *EntityCreator) AssignMeta(m meta.Meta) *EntityCreator

AssignMeta 赋值Meta信息

func (*EntityCreator) MergeMeta added in v0.1.52

func (c *EntityCreator) MergeMeta(dict map[string]any) *EntityCreator

MergeMeta 合并Meta信息,如果存在则覆盖

func (*EntityCreator) MergeMetaIfAbsent added in v0.1.52

func (c *EntityCreator) MergeMetaIfAbsent(dict map[string]any) *EntityCreator

MergeMetaIfAbsent 合并Meta信息,如果存在则跳过

func (*EntityCreator) New added in v0.1.52

func (c *EntityCreator) New() (ec.Entity, error)

New 创建实体

func (*EntityCreator) SetComponentAwakeOnFirstTouch added in v0.1.52

func (c *EntityCreator) SetComponentAwakeOnFirstTouch(b bool) *EntityCreator

SetComponentAwakeOnFirstTouch 设置当实体组件首次被访问时,生命周期是否进入唤醒(Awake)

func (*EntityCreator) SetInstance added in v0.1.52

func (c *EntityCreator) SetInstance(instance ec.Entity) *EntityCreator

SetInstance 设置实例,用于扩展实体能力

func (*EntityCreator) SetInstanceFace added in v0.1.52

func (c *EntityCreator) SetInstanceFace(face iface.Face[ec.Entity]) *EntityCreator

SetInstanceFace 设置实例,用于扩展实体能力

func (*EntityCreator) SetMeta added in v0.1.52

func (c *EntityCreator) SetMeta(dict map[string]any) *EntityCreator

SetMeta 设置Meta信息

func (*EntityCreator) SetParentId added in v0.1.52

func (c *EntityCreator) SetParentId(id id.Id) *EntityCreator

SetParentId 设置父实体Id

type EntityPTCreator added in v0.1.52

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

EntityPTCreator 实体原型构建器

func BuildEntityPT added in v0.1.52

func BuildEntityPT(provider corectx.CurrentContextProvider, prototype string) *EntityPTCreator

BuildEntityPT 创建实体原型

func (*EntityPTCreator) AddComponent added in v0.1.52

func (c *EntityPTCreator) AddComponent(comp any, name ...string) *EntityPTCreator

AddComponent 添加组件

func (*EntityPTCreator) AssignMeta added in v0.1.52

func (c *EntityPTCreator) AssignMeta(m meta.Meta) *EntityPTCreator

AssignMeta 赋值原型Meta信息

func (*EntityPTCreator) Declare added in v0.1.52

func (c *EntityPTCreator) Declare()

Declare 声明实体原型

func (*EntityPTCreator) MergeMeta added in v0.1.52

func (c *EntityPTCreator) MergeMeta(dict map[string]any) *EntityPTCreator

MergeMeta 合并原型Meta信息,如果存在则覆盖

func (*EntityPTCreator) MergeMetaIfAbsent added in v0.1.52

func (c *EntityPTCreator) MergeMetaIfAbsent(dict map[string]any) *EntityPTCreator

MergeMetaIfAbsent 合并原型Meta信息,如果存在则跳过

func (*EntityPTCreator) SetComponentAwakeOnFirstTouch added in v0.1.52

func (c *EntityPTCreator) SetComponentAwakeOnFirstTouch(b bool) *EntityPTCreator

SetComponentAwakeOnFirstTouch 设置当实体组件首次被访问时,生命周期是否进入唤醒(Awake)

func (*EntityPTCreator) SetInstance added in v0.1.52

func (c *EntityPTCreator) SetInstance(instance any) *EntityPTCreator

SetInstance 设置实例,用于扩展实体能力

func (*EntityPTCreator) SetMeta added in v0.1.52

func (c *EntityPTCreator) SetMeta(dict map[string]any) *EntityPTCreator

SetMeta 设置原型Meta信息

type FrameOptions added in v0.1.52

type FrameOptions struct {
	Enabled     bool              // 是否启用帧
	Mode        runtime.FrameMode // 帧模式
	TargetFPS   float64           // 目标FPS
	TotalFrames int64             // 运行帧数上限
}

FrameOptions 帧的所有选项

type LifecycleAddInOnRuntimeRunningEvent added in v0.1.52

type LifecycleAddInOnRuntimeRunningEvent = runtime.EventContextRunningEvent

LifecycleAddInOnRuntimeRunningEvent 运行事件,当插件安装在运行时上时,实现此接口即可使用

type LifecycleComponentAwake

type LifecycleComponentAwake interface {
	Awake()
}

LifecycleComponentAwake 组件的生命周期进入唤醒(Awake)时的回调,与死亡(Death)成对,只会调用一次,组件实现此接口即可使用

type LifecycleComponentDispose

type LifecycleComponentDispose interface {
	Dispose()
}

LifecycleComponentDispose 组件的生命周期进入死亡(Death)时的回调,与唤醒(Awake)成对,只会调用一次,组件实现此接口即可使用

type LifecycleComponentLateUpdate

type LifecycleComponentLateUpdate = eventLateUpdate

LifecycleComponentLateUpdate 如果开启运行时的帧更新特性,那么组件状态为活跃(Alive)时,将会收到这个帧迟滞更新(Late Update)回调,组件实现此接口即可使用

type LifecycleComponentOnDisable added in v0.1.52

type LifecycleComponentOnDisable interface {
	OnDisable()
}

LifecycleComponentOnDisable 组件的生命周期进入关闭(OnDisable)时的回调,与启用(OnEnable)成对,组件实现此接口即可使用

type LifecycleComponentOnEnable added in v0.1.52

type LifecycleComponentOnEnable interface {
	OnEnable()
}

LifecycleComponentOnEnable 组件的生命周期进入启用(OnEnable)时的回调,与关闭(OnDisable)成对,组件实现此接口即可使用

type LifecycleComponentShut

type LifecycleComponentShut interface {
	Shut()
}

LifecycleComponentShut 组件的生命周期进入结束(Shut)时的回调,与开始(Start)成对,只会调用一次,组件实现此接口即可使用

type LifecycleComponentStart

type LifecycleComponentStart interface {
	Start()
}

LifecycleComponentStart 组件的生命周期进入开始(Start)时的回调,与结束(Shut)成对,只会调用一次,组件实现此接口即可使用

type LifecycleComponentUpdate

type LifecycleComponentUpdate = eventUpdate

LifecycleComponentUpdate 如果开启运行时的帧更新特性,那么组件状态为活跃(Alive)时,将会收到这个帧更新(Update)回调,组件实现此接口即可使用

type LifecycleEntityAwake

type LifecycleEntityAwake interface {
	Awake()
}

LifecycleEntityAwake 实体的生命周期进入唤醒(Awake)时的回调,与死亡(Death)成对,只会调用一次,实体实现此接口即可使用

type LifecycleEntityDispose

type LifecycleEntityDispose interface {
	Dispose()
}

LifecycleEntityDispose 实体的生命周期进入死亡(Death)时的回调,与唤醒(Awake)成对,只会调用一次,实体实现此接口即可使用

type LifecycleEntityLateUpdate

type LifecycleEntityLateUpdate = eventLateUpdate

LifecycleEntityLateUpdate 如果开启运行时的帧更新特性,那么实体状态为活跃(Alive)时,将会收到这个帧迟滞更新(Late Update)回调,实体实现此接口即可使用

type LifecycleEntityShut

type LifecycleEntityShut interface {
	Shut()
}

LifecycleEntityShut 实体的生命周期进入结束(Shut)时的回调,与开始(Start)成对,只会调用一次,实体实现此接口即可使用

type LifecycleEntityStart

type LifecycleEntityStart interface {
	Start()
}

LifecycleEntityStart 实体的生命周期进入开始(Start)时的回调,与结束(Shut)成对,只会调用一次,实体实现此接口即可使用

type LifecycleEntityUpdate

type LifecycleEntityUpdate = eventUpdate

LifecycleEntityUpdate 如果开启运行时的帧更新特性,那么实体状态为活跃(Alive)时,将会收到这个帧更新(Update)回调,实体实现此接口即可使用

type LifecycleRuntimeAddInInit added in v0.1.52

type LifecycleRuntimeAddInInit interface {
	Init(rtCtx runtime.Context)
}

LifecycleRuntimeAddInInit 运行时插件初始化回调,当插件安装在运行时上时,实现此接口即可使用

type LifecycleRuntimeAddInShut added in v0.1.52

type LifecycleRuntimeAddInShut interface {
	Shut(rtCtx runtime.Context)
}

LifecycleRuntimeAddInShut 运行时插件结束回调,当插件安装在运行时上时,实现此接口即可使用

type Runtime

type Runtime interface {
	corectx.CurrentContextProvider
	corectx.ConcurrentContextProvider
	reinterpret.InstanceProvider
	async.Callee
	// contains filtered or unexported methods
}

Runtime 运行时接口

func NewRuntime

func NewRuntime(rtCtx runtime.Context, settings ...option.Setting[RuntimeOptions]) Runtime

NewRuntime 创建运行时

func UnsafeNewRuntime deprecated

func UnsafeNewRuntime(rtCtx runtime.Context, options RuntimeOptions) Runtime

Deprecated: UnsafeNewRuntime 内部创建运行时

type RuntimeBehavior

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

RuntimeBehavior 运行时行为,在扩展运行时能力时,匿名嵌入至运行时结构体中

func (*RuntimeBehavior) ConcurrentContext added in v0.1.52

func (rt *RuntimeBehavior) ConcurrentContext() iface.Cache

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

func (*RuntimeBehavior) CurrentContext added in v0.1.52

func (rt *RuntimeBehavior) CurrentContext() iface.Cache

CurrentContext 获取当前上下文

func (*RuntimeBehavior) InstanceFaceCache added in v0.1.52

func (rt *RuntimeBehavior) InstanceFaceCache() iface.Cache

InstanceFaceCache 支持重新解释类型

func (*RuntimeBehavior) Play

func (rt *RuntimeBehavior) Play(ctx context.Context, delta time.Duration) (err error)

Play 播放指定时长

func (*RuntimeBehavior) PlayAt

func (rt *RuntimeBehavior) PlayAt(ctx context.Context, at time.Duration) (err error)

PlayAt 播放至指定位置

func (*RuntimeBehavior) PlayFrames

func (rt *RuntimeBehavior) PlayFrames(ctx context.Context, delta int64) (err error)

PlayFrames 播放指定帧数

func (*RuntimeBehavior) PlayFramesAt added in v0.1.52

func (rt *RuntimeBehavior) PlayFramesAt(ctx context.Context, at int64) (err error)

PlayFramesAt 播放至指定帧数

func (*RuntimeBehavior) PlayIfContinue added in v0.1.52

func (rt *RuntimeBehavior) PlayIfContinue(ctx context.Context, continueFunc generic.Func1[runtime.Context, bool]) (err error)

PlayIfContinue 指定函数判断是否继续播放

func (*RuntimeBehavior) PushCallAsync added in v0.1.52

func (rt *RuntimeBehavior) PushCallAsync(fun generic.FuncVar0[any, async.Ret], args ...any) async.AsyncRet

PushCallAsync 将调用函数压入接受者的任务处理流水线,返回AsyncRet。

func (*RuntimeBehavior) PushCallDelegateAsync added in v0.1.52

func (rt *RuntimeBehavior) PushCallDelegateAsync(fun generic.DelegateVar0[any, async.Ret], args ...any) async.AsyncRet

PushCallDelegateAsync 将调用委托压入接受者的任务处理流水线,返回AsyncRet。

func (*RuntimeBehavior) PushCallDelegateVoidAsync added in v0.1.52

func (rt *RuntimeBehavior) PushCallDelegateVoidAsync(fun generic.DelegateVoidVar0[any], args ...any) async.AsyncRet

PushCallDelegateVoidAsync 将调用委托压入接受者的任务处理流水线,返回AsyncRet。

func (*RuntimeBehavior) PushCallVoidAsync added in v0.1.52

func (rt *RuntimeBehavior) PushCallVoidAsync(fun generic.ActionVar0[any], args ...any) async.AsyncRet

PushCallVoidAsync 将调用函数压入接受者的任务处理流水线,返回AsyncRet。

func (*RuntimeBehavior) Run

func (rt *RuntimeBehavior) Run() async.AsyncRet

Run 运行

func (*RuntimeBehavior) Stats added in v0.1.52

func (rt *RuntimeBehavior) Stats() RuntimeStats

Stats 获取运行时统计信息

func (*RuntimeBehavior) Terminate

func (rt *RuntimeBehavior) Terminate() async.AsyncRet

Terminate 停止

func (*RuntimeBehavior) Terminated added in v0.1.52

func (rt *RuntimeBehavior) Terminated() async.AsyncRet

Terminated 已停止

type RuntimeOptions

type RuntimeOptions struct {
	InstanceFace                    iface.Face[Runtime] // 实例,用于扩展运行时能力
	AutoRun                         bool                // 是否开启自动运行
	ContinueOnActivatingEntityPanic bool                // 激活实体时发生panic是否继续,不继续将会主动删除实体
	Frame                           FrameOptions        // 帧配置
	TaskQueue                       TaskQueueOptions    // 任务处理流水线配置
	GCInterval                      time.Duration       // GC间隔时长
	CustomGC                        CustomGC            // 自定义GC
}

RuntimeOptions 创建运行时的所有选项

type RuntimeStats added in v0.1.52

type RuntimeStats struct {
	WaitGroupCount  int64             // 等待组任务数量
	WaitGroupClosed bool              // 等待组是否已关闭
	TaskQueue       [2]TaskQueueStats // 任务队列统计信息
}

RuntimeStats 运行时统计信息

type TaskQueueOptions added in v0.1.52

type TaskQueueOptions struct {
	Unbounded bool // 是否无上限
	Capacity  int  // 流水线大小
}

TaskQueueOptions 任务处理流水线的所有选项

type TaskQueueStats added in v0.1.52

type TaskQueueStats struct {
	Enqueued  int64
	Pending   int64
	Rejected  int64
	Completed int64
}

TaskQueueStats 任务队列统计信息

type TaskType added in v0.1.52

type TaskType int8
const (
	TaskType_Call TaskType = iota
	TaskType_Frame
)

Directories

Path Synopsis
ec
pt
utils
id

Jump to

Keyboard shortcuts

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