ecs

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

type ComToBool

type ComToBool func(IComponent) bool

type Component

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

func NewComponent

func NewComponent(t TComponent) Component

func (*Component) Dispose

func (c *Component) Dispose()

func (*Component) Entity

func (c *Component) Entity() *Entity

func (*Component) Init

func (c *Component) Init()

func (*Component) Start

func (c *Component) Start()

func (*Component) Type

func (c *Component) Type() TComponent

type Entity

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

func NewEntity

func NewEntity(id string) *Entity

func (*Entity) AddComponent

func (e *Entity) AddComponent(c IComponent) *util.Err

func (*Entity) AddComponents

func (e *Entity) AddComponents(components ...IComponent)

func (*Entity) Components

func (e *Entity) Components() []IComponent

func (*Entity) DelComponent

func (e *Entity) DelComponent(t TComponent) bool

func (*Entity) Dispose

func (e *Entity) Dispose()

func (*Entity) GetComponent

func (e *Entity) GetComponent(t TComponent) (IComponent, bool)

func (*Entity) Id

func (e *Entity) Id() string

func (*Entity) IterComponent

func (e *Entity) IterComponent(fn func(IComponent))

func (*Entity) Scene

func (e *Entity) Scene() *Scene

type EntityToBool

type EntityToBool func(*Entity) bool

type EntityToErr

type EntityToErr func(*Entity) *util.Err

type EntityToEvent

type EntityToEvent func(*Entity) IEvent

type FnBufferJob

type FnBufferJob func(JobName, *Buffer, []any)

type FnCom

type FnCom func(IComponent)

type FnComponentBuffer

type FnComponentBuffer func(IComponent, *Buffer)

type FnEntity

type FnEntity func(*Entity)

type FnEntityBuffer

type FnEntityBuffer func(*Entity, *Buffer)

type FnEntityCom

type FnEntityCom func(*Entity, IComponent)

type FnEntityEvent

type FnEntityEvent func(*Entity, IEvent)

type FnEntityFrame

type FnEntityFrame func(*Entity, *Frame)

type FnEntityStr

type FnEntityStr func(*Entity, string)

type FnEntityTCom

type FnEntityTCom func(*Entity, TComponent)

type FnEvent

type FnEvent func(IEvent)

type FnEvents

type FnEvents func([]IEvent)

type FnFrame

type FnFrame func(*Frame)

type FnJob

type FnJob func([]any)

type FnLinkAnySlc

type FnLinkAnySlc func(*ds.FnLink, []any)

type FnScene

type FnScene func(*Scene)

type FnSceneM

type FnSceneM func(*Scene, util.M)

type FnSceneStr

type FnSceneStr func(*Scene, string)

type Frame

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

func NewFrame

func NewFrame(scene *Scene, opts ...FrameOption) *Frame

func (*Frame) AddSystem

func (f *Frame) AddSystem(system ISystem, before TSystem)

func (*Frame) After

func (f *Frame) After() *ds.FnLink

After 每帧末尾调用

func (*Frame) AfterClearTags

func (f *Frame) AfterClearTags(tags ...string)

func (*Frame) Before

func (f *Frame) Before() *ds.FnLink

Before 每帧末尾调用

func (*Frame) DelSystem

func (f *Frame) DelSystem(t TSystem)

func (*Frame) DeltaMillSec

func (f *Frame) DeltaMillSec() int64

func (*Frame) GetSystem

func (f *Frame) GetSystem(typ TSystem) (ISystem, bool)

GetSystem 注意协程安全

func (*Frame) NowMillSecs

func (f *Frame) NowMillSecs() int64

func (*Frame) Num

func (f *Frame) Num() int64

func (*Frame) PushJob

func (f *Frame) PushJob(name JobName, data ...any)

PushJob frame 外部使用,协程安全的

func (*Frame) PutJob

func (f *Frame) PutJob(name JobName, data ...any)

PutJob system内部使用,注意协程安全,需要回到主协程使用

func (*Frame) Scene

func (f *Frame) Scene() *Scene

func (*Frame) Start

func (f *Frame) Start()

func (*Frame) StartTime

func (f *Frame) StartTime() int64

func (*Frame) Stop

func (f *Frame) Stop()

type FrameOption

type FrameOption func(o *frameOption)

func FrameBeforeDispose

func FrameBeforeDispose(fn FnFrame) FrameOption

func FrameMax

func FrameMax(frames int64) FrameOption

func FrameSystems

func FrameSystems(systems ...ISystem) FrameOption

func FrameTickDur

func FrameTickDur(dur time.Duration) FrameOption

type IComponent

type IComponent interface {
	Entity() *Entity

	Type() TComponent
	// Init 添加到Entity时调用
	Init()
	// Start Entity添加到Scene时调用
	Start()
	Dispose()
	// contains filtered or unexported methods
}

func PTagComponentsTo

func PTagComponentsTo[T any](s *System, tag string, fn func(IComponent) T, complete func([]T)) ([]IComponent, bool)
func PTagComponentsToLink[T any](s *Scene, tag string, fn func(IComponent, *ds.Link[T]), pcr func(*ds.Link[T])) ([]IComponent, bool)

type IEvent

type IEvent interface {
	Type() TEvent
}

type ISystem

type ISystem interface {
	Type() TSystem
	Frame() *Frame
	Scene() *Scene
	FrameBefore() *ds.FnLink
	FrameAfter() *ds.FnLink
	OnBeforeStart()
	OnStart(frame *Frame)
	OnAfterStart()
	OnStop()
	OnUpdate()
	PutJob(name JobName, data ...any)
	DoJob(name JobName)
	BindJob(name JobName, handler util.FnAnySlc)
	BindPJob(name JobName, fn util.FnAnySlc)
	BindPFnJob(name JobName, fn FnLinkAnySlc)
	PTagComponents(tag string, fn func(IComponent)) ([]IComponent, bool)
	PTagComponentsWithParams(tag string, fn func(IComponent, []any), params ...any) ([]IComponent, bool)
	PTagComponentsToFnLink(tag string, fn func(IComponent, *ds.FnLink)) ([]IComponent, bool)
	PTagComponentsToFnLinkWithParams(tag string, fn func(IComponent, []any, *ds.FnLink), params ...any) ([]IComponent, bool)
}

type JobName

type JobName = string

type Scene

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

func NewScene

func NewScene(id string, typ TScene) *Scene

func (*Scene) AddEntity

func (s *Scene) AddEntity(e *Entity) *util.Err

func (*Scene) BindAddComponent

func (s *Scene) BindAddComponent(fn FnEntityCom)

func (*Scene) BindAfterAddEntity

func (s *Scene) BindAfterAddEntity(fn FnEntity)

func (*Scene) BindAfterDisposeEntity

func (s *Scene) BindAfterDisposeEntity(fn FnEntity)

func (*Scene) BindBeforeAddEntity

func (s *Scene) BindBeforeAddEntity(fn EntityToErr)

func (*Scene) BindBeforeDisposeEntity

func (s *Scene) BindBeforeDisposeEntity(fn EntityToErr)

func (*Scene) BindDelComponent

func (s *Scene) BindDelComponent(fn FnEntityTCom)

func (*Scene) ClearComponentTags

func (s *Scene) ClearComponentTags(component IComponent)

func (*Scene) ClearTag

func (s *Scene) ClearTag(tag string) bool

func (*Scene) ClearTags

func (s *Scene) ClearTags(tags ...string)

func (*Scene) Data

func (s *Scene) Data() util.M

func (*Scene) DelEntity

func (s *Scene) DelEntity(id string) *util.Err

func (*Scene) Dispose

func (s *Scene) Dispose()

func (*Scene) Entities

func (s *Scene) Entities() []*Entity

func (*Scene) EntityCount

func (s *Scene) EntityCount() int

func (*Scene) EntityIds

func (s *Scene) EntityIds(ids *[]string)

func (*Scene) GetEntity

func (s *Scene) GetEntity(id string) (*Entity, bool)

func (*Scene) GetTagComponents

func (s *Scene) GetTagComponents(tag string) ([]IComponent, bool)

func (*Scene) HasTagComponent

func (s *Scene) HasTagComponent(component IComponent, tag string) bool

func (*Scene) Id

func (s *Scene) Id() string

func (*Scene) IsEmpty

func (s *Scene) IsEmpty() bool

func (*Scene) IterEntities

func (s *Scene) IterEntities(fn FnEntity)

func (*Scene) TagComponent

func (s *Scene) TagComponent(component IComponent, tags ...string)

func (*Scene) TagEntityComponent

func (s *Scene) TagEntityComponent(entityId string, t TComponent, tags ...string)

func (*Scene) TestGetTagComponents

func (s *Scene) TestGetTagComponents(tag string) (*ds.SetItem[string, IComponent], bool)

func (*Scene) TransferComponentTag

func (s *Scene) TransferComponentTag(target string, origin string)

func (*Scene) Type

func (s *Scene) Type() TScene

func (*Scene) UntagComponent

func (s *Scene) UntagComponent(component IComponent, tags ...string)

type SceneToErr

type SceneToErr func(*Scene) *util.Err

type System

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

func NewSystem

func NewSystem(t TSystem) System

func (*System) BindJob

func (s *System) BindJob(name JobName, fn util.FnAnySlc)

func (*System) BindPFnJob

func (s *System) BindPFnJob(name JobName, fn FnLinkAnySlc)

func (*System) BindPJob

func (s *System) BindPJob(name JobName, fn util.FnAnySlc)

func (*System) DoJob

func (s *System) DoJob(name JobName)

func (*System) Frame

func (s *System) Frame() *Frame

func (*System) FrameAfter

func (s *System) FrameAfter() *ds.FnLink

func (*System) FrameBefore

func (s *System) FrameBefore() *ds.FnLink

func (*System) Jobs

func (s *System) Jobs() []worker.JobName

func (*System) OnAfterStart

func (s *System) OnAfterStart()

func (*System) OnBeforeStart

func (s *System) OnBeforeStart()

func (*System) OnStart

func (s *System) OnStart(frame *Frame)

func (*System) OnStop

func (s *System) OnStop()

func (*System) OnUpdate

func (s *System) OnUpdate()

func (*System) PEntities

func (s *System) PEntities(fn func(*Entity)) []*Entity

func (*System) PEntitiesWithParams

func (s *System) PEntitiesWithParams(fn func(*Entity, []any), params ...any) []*Entity

func (*System) PTagComponents

func (s *System) PTagComponents(tag string, fn func(IComponent)) ([]IComponent, bool)
func (s *System) PTagComponentsToFnLink(tag string, fn func(IComponent, *ds.FnLink)) ([]IComponent, bool)

func (*System) PTagComponentsToFnLinkWithParams

func (s *System) PTagComponentsToFnLinkWithParams(tag string, fn func(IComponent, []any, *ds.FnLink), params ...any) ([]IComponent, bool)

func (*System) PTagComponentsWithParams

func (s *System) PTagComponentsWithParams(tag string, fn func(IComponent, []any), params ...any) ([]IComponent, bool)

func (*System) PutJob

func (s *System) PutJob(name worker.JobName, data ...any)

func (*System) Scene

func (s *System) Scene() *Scene

func (*System) Type

func (s *System) Type() TSystem

type TComponent

type TComponent string

type TEvent

type TEvent string

type TJob

type TJob uint8
const (
	JobDef TJob = iota
	JobP
	JobPLink
)

type TScene

type TScene string

type TSystem

type TSystem string

type ToEvent

type ToEvent func() IEvent

Jump to

Keyboard shortcuts

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