ecs

package
v0.0.0-...-20810c9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DATA_MAX = 64

Variables

This section is empty.

Functions

func Add

func Add[T any](e *Entity) *T

func DefineTypeComponent

func DefineTypeComponent[T any, C any](t *Data[T], c *Data[C], get func(data *T) *C)

func Get

func Get[T any](e *Entity) *T

func HasActiveWorld

func HasActiveWorld() bool

func Set

func Set[T any](e *Entity, value T) bool

Types

type ArrangementID

type ArrangementID uint16

type Context

type Context struct {
	World *World
}

type Data

type Data[D any] struct {
	// contains filtered or unexported fields
}

func DefineComponent

func DefineComponent[C any](name string, initial C) *Data[C]

func DefineType

func DefineType[T any](name string, initial T, with func(t *Data[T])) *Data[T]

func (*Data[V]) Add

func (d *Data[V]) Add(e *Entity) *V

func (*Data[V]) AddSystem

func (d *Data[V]) AddSystem(sys DataSystem[V])

func (*Data[D]) Enable

func (d *Data[D]) Enable(settings DataSettings)

func (*Data[V]) Get

func (d *Data[V]) Get(e *Entity) *V

func (Data[V]) ID

func (d Data[V]) ID() DataID

func (*Data[V]) Iterable

func (d *Data[V]) Iterable() ds.Iterable[Value[*V]]

func (Data[V]) Name

func (d Data[V]) Name() string

func (*Data[V]) Set

func (d *Data[V]) Set(e *Entity, value V)

func (*Data[V]) SetSystem

func (d *Data[V]) SetSystem(sys DataSystem[V]) *Data[V]

type DataBase

type DataBase interface {
	ID() DataID
	Name() string
	Enable(settings DataSettings)
}

type DataID

type DataID uint8

type DataIDs

type DataIDs = ds.Bits64Indexed[DataID]

type DataOffset

type DataOffset uint32

type DataSettings

type DataSettings struct {
	Capacity             uint32
	StageCapacity        uint32
	ExcludeDefaultSystem bool
}

type DataSystem

type DataSystem[D any] interface {
	OnStage(data *D, e *Entity, ctx Context)
	OnLive(data *D, e *Entity, ctx Context)
	OnRemove(data *D, e *Entity, ctx Context)
	Init(ctx Context) error
	Update(iter ds.Iterable[Value[*D]], ctx Context)
	Destroy(ctx Context)
}

type Entity

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

func New

func New() *Entity

func (*Entity) Delete

func (e *Entity) Delete()

func (Entity) Deleted

func (e Entity) Deleted() bool

func (Entity) Has

func (e Entity) Has(comp DataBase) bool

func (Entity) HasLive

func (e Entity) HasLive(comp DataBase) bool

func (Entity) HasStaging

func (e Entity) HasStaging(comp DataBase) bool

func (Entity) ID

func (e Entity) ID() ID

func (Entity) Live

func (e Entity) Live() bool

func (Entity) LiveDatas

func (e Entity) LiveDatas() DataIDs

func (Entity) LiveValues

func (e Entity) LiveValues() DataIDs

func (Entity) Staging

func (e Entity) Staging() bool

func (Entity) StagingValues

func (e Entity) StagingValues() DataIDs

func (Entity) Values

func (e Entity) Values() DataIDs

type ID

type ID uint32

func (ID) Entity

func (id ID) Entity() *Entity

type System

type System interface {
	OnStage(e *Entity, ctx Context)
	OnLive(e *Entity, ctx Context)
	OnDelete(e *Entity, ctx Context)
	Init(ctx Context) error
	Update(iter ds.Iterable[Entity], ctx Context)
	Destroy(ctx Context)
}

func NewSystemFiltered

func NewSystemFiltered(sys System, filter WorldSearch) System

type Tree

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

func NewTree

func NewTree(e *Entity, getTree func(e *Entity) *Tree) Tree

func (*Tree) AddChild

func (t *Tree) AddChild(child *Entity)

func (*Tree) AddChildTree

func (t *Tree) AddChildTree(child *Tree)

func (*Tree) Children

func (t *Tree) Children() []*Entity

func (*Tree) Delete

func (t *Tree) Delete()

func (*Tree) DeleteChildren

func (t *Tree) DeleteChildren()

func (*Tree) Entity

func (t *Tree) Entity() *Entity

func (*Tree) Parent

func (t *Tree) Parent() *Entity

func (*Tree) RemoveChild

func (t *Tree) RemoveChild(child *Entity)

func (*Tree) SetParent

func (t *Tree) SetParent(parent *Entity)

func (*Tree) SetParentTree

func (t *Tree) SetParentTree(parent *Tree)

type Value

type Value[D any] struct {
	Data D
	ID   ID
}

type World

type World struct {
	Settings WorldSettings
	Name     string
	// contains filtered or unexported fields
}

func ActiveWorld

func ActiveWorld() *World

func NewWorld

func NewWorld(name string, settings WorldSettings) *World

func (*World) Activate

func (w *World) Activate()

func (*World) AddSystem

func (w *World) AddSystem(sys System)

func (*World) Delete

func (w *World) Delete(e *Entity)

func (*World) Destroy

func (w *World) Destroy()

func (*World) Enable

func (w *World) Enable(settings DataSettings, datas ...DataBase)

func (*World) Init

func (w *World) Init() error

func (*World) IsActive

func (w *World) IsActive() bool

func (*World) Iterable

func (w *World) Iterable() ds.Iterable[Entity]

func (*World) New

func (w *World) New() *Entity

func (*World) Search

func (w *World) Search(search WorldSearch) ds.Iterable[Entity]

func (*World) Stage

func (w *World) Stage()

func (*World) Update

func (w *World) Update()

type WorldSearch

type WorldSearch struct {
	Match               util.Match[DataIDs]
	IncludeStagedValues bool
	IncludeStaged       bool
}

func (WorldSearch) IsMatch

func (search WorldSearch) IsMatch(e *Entity) bool

type WorldSettings

type WorldSettings struct {
	EntityCapacity            uint32
	EntityStageCapacity       uint32
	AverageComponentPerEntity uint32
	DeleteOnDestroy           bool
}

func (WorldSettings) IsZero

func (ws WorldSettings) IsZero() bool

Jump to

Keyboard shortcuts

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