tiny

package module
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: LGPL-2.1 Imports: 18 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) // 运行时错误
	ErrService  = fmt.Errorf("%w: service", ErrTiny) // 服务错误
)
View Source
var (
	ErrProcessQueueClosed = fmt.Errorf("%w: process queue is closed", ErrRuntime) // 任务处理流水线关闭
	ErrProcessQueueFull   = fmt.Errorf("%w: process queue is full", ErrRuntime)   // 任务处理流水线已满
)
View Source
var (
	ErrAllFailures = fmt.Errorf("%w: all of async result failures", exception.ErrTiny)
)
View Source
var (
	ErrCtrlChanClosed = fmt.Errorf("%w: ctrl chan is closed", ErrRuntime) // 运行控制已关闭
)
View Source
var With _RuntimeOption

Functions

func Async

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

func AsyncVoid

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

func Go

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

func GoVoid

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

func ReadChan

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

ReadChan 读取channel

func TimeAfter

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

TimeAfter 定时器,指定时长

func TimeAt

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

TimeAt 定时器,指定时间点

func TimeTick

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

TimeTick 心跳器

func UnsafeRuntime

func UnsafeRuntime(runtime Runtime) _UnsafeRuntime

Types

type AwaitDirector

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

AwaitDirector 异步等待分发器

func Await

func Await(provider gctx.CurrentContextProvider, asyncRet ...async.AsyncRet) AwaitDirector

Await 异步等待结果返回

func (AwaitDirector) All

func (ad AwaitDirector) All(fun generic.ActionVar2[runtime.Context, []async.Ret, any], va ...any)

All 异步等待所有结果返回

func (AwaitDirector) Any

func (ad AwaitDirector) Any(fun generic.ActionVar2[runtime.Context, async.Ret, any], va ...any)

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

func (AwaitDirector) AnyOK

func (ad AwaitDirector) AnyOK(fun generic.ActionVar2[runtime.Context, async.Ret, any], va ...any)

AnyOK 异步等待任意一个结果成功返回

func (AwaitDirector) Pipe

Pipe 异步等待管道返回

type CustomGC

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

type LifecycleComponentAwake

type LifecycleComponentAwake interface {
	Awake()
}

LifecycleComponentAwake 组件的生命周期进入唤醒(awake)时的回调,组件实现此接口即可使用

type LifecycleComponentDispose

type LifecycleComponentDispose interface {
	Dispose()
}

LifecycleComponentDispose 组件的生命周期进入死亡(death)时的回调,组件实现此接口即可使用

type LifecycleComponentLateUpdate

type LifecycleComponentLateUpdate = eventLateUpdate

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

type LifecycleComponentShut

type LifecycleComponentShut interface {
	Shut()
}

LifecycleComponentShut 组件的生命周期进入结束(shut)时的回调,组件实现此接口即可使用

type LifecycleComponentStart

type LifecycleComponentStart interface {
	Start()
}

LifecycleComponentStart 组件的生命周期进入开始(start)时的回调,组件实现此接口即可使用

type LifecycleComponentUpdate

type LifecycleComponentUpdate = eventUpdate

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

type LifecycleEntityAwake

type LifecycleEntityAwake interface {
	Awake()
}

LifecycleEntityAwake 实体的生命周期进入唤醒(awake)时的回调,实体实现此接口即可使用

type LifecycleEntityDispose

type LifecycleEntityDispose interface {
	Dispose()
}

LifecycleEntityDispose 实体的生命周期进入死亡(death)时的回调,实体实现此接口即可使用

type LifecycleEntityLateUpdate

type LifecycleEntityLateUpdate = eventLateUpdate

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

type LifecycleEntityShut

type LifecycleEntityShut interface {
	Shut()
}

LifecycleEntityShut 实体的生命周期进入结束(shut)时的回调,实体实现此接口即可使用

type LifecycleEntityStart

type LifecycleEntityStart interface {
	Start()
}

LifecycleEntityStart 实体的生命周期进入开始(start)时的回调,实体实现此接口即可使用

type LifecycleEntityUpdate

type LifecycleEntityUpdate = eventUpdate

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

type LifecyclePluginInit

type LifecyclePluginInit interface {
	InitP(ctx runtime.Context)
}

LifecyclePluginInit 运行时上的插件初始化回调,插件实现此接口即可使用

type LifecyclePluginShut

type LifecyclePluginShut interface {
	ShutP(ctx runtime.Context)
}

LifecyclePluginShut 运行时上的插件结束回调,插件实现此接口即可使用

type Running

type Running interface {
	// Run 运行
	Run() <-chan struct{}
	// Play 播放指定时长
	Play(delta time.Duration) error
	// PlayAt 播放至指定位置
	PlayAt(at time.Duration) error
	// PlayFrames 播放指定帧数
	PlayFrames(delta int64) error
	// PlayAtFrames 播放至指定帧数
	PlayAtFrames(at int64) error
	// PlayAtFunc 播放至函数指定位置
	PlayAtFunc(fun generic.Func1[runtime.Context, bool]) error
	// Terminate 停止
	Terminate() <-chan struct{}
	// TerminatedChan 已停止chan
	TerminatedChan() <-chan struct{}
}

Running 运行接口

type Runtime

type Runtime interface {
	gctx.CurrentContextProvider
	gctx.ConcurrentContextProvider
	async.Callee
	reinterpret.CompositeProvider
	Running
	// contains filtered or unexported methods
}

Runtime 运行时接口

func NewRuntime

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

NewRuntime 创建运行时

func UnsafeNewRuntime deprecated

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

Deprecated: UnsafeNewRuntime 内部创建运行时

type RuntimeBehavior

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

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

func (*RuntimeBehavior) GetCompositeFaceCache

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

GetCompositeFaceCache 支持重新解释类型

func (*RuntimeBehavior) GetConcurrentContext

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

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

func (*RuntimeBehavior) GetCurrentContext

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

GetCurrentContext 获取当前上下文

func (*RuntimeBehavior) OnComponentDestroySelf

func (rt *RuntimeBehavior) OnComponentDestroySelf(comp ec.Component)

OnComponentDestroySelf 事件处理器:组件销毁自身

func (*RuntimeBehavior) OnEntityDestroySelf

func (rt *RuntimeBehavior) OnEntityDestroySelf(entity ec.Entity)

OnEntityDestroySelf 事件处理器:实体销毁自身

func (*RuntimeBehavior) OnEntityMgrAddEntity

func (rt *RuntimeBehavior) OnEntityMgrAddEntity(entityMgr runtime.EntityMgr, entity ec.Entity)

OnEntityMgrAddEntity 事件处理器:实体管理器添加实体

func (*RuntimeBehavior) OnEntityMgrEntityAddComponents

func (rt *RuntimeBehavior) OnEntityMgrEntityAddComponents(entityMgr runtime.EntityMgr, entity ec.Entity, components []ec.Component)

OnEntityMgrEntityAddComponents 事件处理器:实体管理器中的实体添加组件

func (*RuntimeBehavior) OnEntityMgrEntityFirstAccessComponent

func (rt *RuntimeBehavior) OnEntityMgrEntityFirstAccessComponent(entityMgr runtime.EntityMgr, entity ec.Entity, component ec.Component)

OnEntityMgrEntityFirstAccessComponent 事件处理器:实体管理器中的实体首次访问组件

func (*RuntimeBehavior) OnEntityMgrEntityRemoveComponent

func (rt *RuntimeBehavior) OnEntityMgrEntityRemoveComponent(entityMgr runtime.EntityMgr, entity ec.Entity, component ec.Component)

OnEntityMgrEntityRemoveComponent 事件处理器:实体管理器中的实体删除组件

func (*RuntimeBehavior) OnEntityMgrRemoveEntity

func (rt *RuntimeBehavior) OnEntityMgrRemoveEntity(entityMgr runtime.EntityMgr, entity ec.Entity)

OnEntityMgrRemoveEntity 事件处理器:实体管理器删除实体

func (*RuntimeBehavior) Play

func (rt *RuntimeBehavior) Play(delta time.Duration) (err error)

Play 播放指定时长

func (*RuntimeBehavior) PlayAt

func (rt *RuntimeBehavior) PlayAt(at time.Duration) (err error)

PlayAt 播放至指定位置

func (*RuntimeBehavior) PlayAtFrames

func (rt *RuntimeBehavior) PlayAtFrames(at int64) (err error)

PlayAtFrames 播放至指定帧数

func (*RuntimeBehavior) PlayAtFunc added in v0.1.30

func (rt *RuntimeBehavior) PlayAtFunc(fun generic.Func1[runtime.Context, bool]) (err error)

PlayAtFunc 播放至函数指定位置

func (*RuntimeBehavior) PlayFrames

func (rt *RuntimeBehavior) PlayFrames(delta int64) (err error)

PlayFrames 播放指定帧数

func (*RuntimeBehavior) PushCall

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

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

func (*RuntimeBehavior) PushCallDelegate

func (rt *RuntimeBehavior) PushCallDelegate(fun generic.DelegateFuncVar0[any, async.Ret], va ...any) async.AsyncRet

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

func (*RuntimeBehavior) PushCallVoid

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

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

func (*RuntimeBehavior) PushCallVoidDelegate

func (rt *RuntimeBehavior) PushCallVoidDelegate(fun generic.DelegateActionVar0[any], va ...any) async.AsyncRet

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

func (*RuntimeBehavior) Run

func (rt *RuntimeBehavior) Run() <-chan struct{}

Run 运行

func (*RuntimeBehavior) Terminate

func (rt *RuntimeBehavior) Terminate() <-chan struct{}

Terminate 停止

func (*RuntimeBehavior) TerminatedChan

func (rt *RuntimeBehavior) TerminatedChan() <-chan struct{}

TerminatedChan 已停止chan

type RuntimeOptions

type RuntimeOptions struct {
	CompositeFace        iface.Face[Runtime] // 扩展者,在扩展运行时自身能力时使用
	AutoRun              bool                // 是否开启自动运行
	ProcessQueueCapacity int                 // 任务处理流水线大小
	Frame                runtime.Frame       // 帧,设置为nil表示不使用帧更新特性
	GCInterval           time.Duration       // GC间隔时长
	CustomGC             CustomGC            // 自定义GC
}

RuntimeOptions 创建运行时的所有选项

Directories

Path Synopsis
eventcode
Package eventcode 使用go:generate功能,在编译前自动化生成代码
Package eventcode 使用go:generate功能,在编译前自动化生成代码
internal
utils
uid

Jump to

Keyboard shortcuts

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