ecs

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ecs provides typed component storage, queries, structural commands, schedules, resources and messages. It is independent of scene, rendering, input and UI runtimes; applications supply their own component types.

World.ComponentRevision tracks storage changes, including archetype migrations, and is suitable for caches retaining component references. Caches retaining copied values can use World.ComponentValueRevision to ignore unchanged migrations. World.EntityVersion tracks live entities independently of component membership.

Component access, resources, revision tracking and message writes are generic World methods. Commands provides deferred structural operations; Bundle.Put builds dynamic component groups. EntitySlot methods access the slot's bound world and validate the entity generation on every lookup.

SystemContext provides Local values and Added/Changed filters. World owns FrameValue, FrameScratch, FrameScratchMap, ScopeValue and MessageScratch; these caches retain their distinct reset, scope and message lifetimes.

World.Query and Query2 through Query7 construct typed query views. World also provides NewSpawner1 through NewSpawner8 and NewPatch1 through NewPatch8 for reusable creation and mutation plans bound to that world.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommitComponent

func CommitComponent[T comparable](access ComponentAccess[T], value T) bool

CommitComponent writes only when the value differs. Query accesses use their query tick; bindings obtain a mutation tick only when a value actually changes.

Types

type Bundle

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

func NewBundle

func NewBundle(capacity int) Bundle

func (*Bundle) Extend

func (b *Bundle) Extend(group Bundle)

Extend appends a separately authored component group before spawning. Groups must have disjoint component types, as with individual Bundle.Put calls.

func (*Bundle) Put

func (bundle *Bundle) Put[T any](value T)

func (*Bundle) PutEntity

func (bundle *Bundle) PutEntity[T any](build func(Entity) T)

func (Bundle) Value

func (bundle Bundle) Value[T any]() (T, bool)

Value inspects a statically supplied component before spawning.

type Commands

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

func (*Commands) Despawn

func (commands *Commands) Despawn(entity Entity)

func (*Commands) Insert

func (commands *Commands) Insert[T any](entity Entity, value T)

func (*Commands) Remove

func (commands *Commands) Remove[T any](entity Entity)

func (*Commands) RemovePrepared

func (commands *Commands) RemovePrepared(entity Entity, removal PreparedRemoval)

RemovePrepared queues one batch migration for use during iteration.

func (*Commands) Reserve

func (c *Commands) Reserve(capacity int)

Reserve grows command queue storage without changing its contents. It avoids queue backing-array growth when a system knows its command burst.

func (*Commands) Spawn

func (commands *Commands) Spawn(bundle Bundle) Entity

func (*Commands) SpawnPrepared

func (commands *Commands) SpawnPrepared(bundle PreparedBundle) Entity

SpawnPrepared reserves an entity and queues a previously prepared bundle without rebuilding its component entry list.

type ComponentAccess

type ComponentAccess[T any] struct {
	// contains filtered or unexported fields
}

ComponentAccess provides explicit per-component change tracking. Query accesses expire after iteration; binding accesses expire after structural mutation.

func (ComponentAccess[T]) Get

func (a ComponentAccess[T]) Get() T

func (ComponentAccess[T]) Mut

func (a ComponentAccess[T]) Mut() *T

func (ComponentAccess[T]) Ref

func (a ComponentAccess[T]) Ref() *T

Ref returns a read-only component reference without marking it changed.

type ComponentBinding

type ComponentBinding[T any] struct {
	// contains filtered or unexported fields
}

ComponentBinding resolves a component type once for repeated access in one world. It retains no column pointers and survives entity migrations.

func (ComponentBinding[T]) Access

func (b ComponentBinding[T]) Access(row EntityRow) ComponentAccess[T]

Access returns a missing access (Ref is nil) for an invalid row or absent component. Reads preserve ticks. Mut and CommitComponent mark actual write access.

func (ComponentBinding[T]) Get

func (b ComponentBinding[T]) Get(row EntityRow) (value T, ok bool)

type ComponentType

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

ComponentType identifies a component without constructing or boxing a value. Resolve descriptors once with PrepareRemoval or NewPatchN, outside the execution loop.

func Type

func Type[T any]() ComponentType

type Components2

type Components2[A, B any] struct {
	A ComponentAccess[A]
	B ComponentAccess[B]
}

Components2 contains explicitly tracked component access for one entity.

type Components3

type Components3[A, B, C any] struct {
	A ComponentAccess[A]
	B ComponentAccess[B]
	C ComponentAccess[C]
}

Components3 contains explicitly tracked component access for one entity.

type Components4

type Components4[A, B, C, D any] struct {
	A ComponentAccess[A]
	B ComponentAccess[B]
	C ComponentAccess[C]
	D ComponentAccess[D]
}

Components4 contains explicitly tracked component access for one entity.

type Components5

type Components5[A, B, C, D, E any] struct {
	A ComponentAccess[A]
	B ComponentAccess[B]
	C ComponentAccess[C]
	D ComponentAccess[D]
	E ComponentAccess[E]
}

Components5 contains explicitly tracked component access for one entity.

type Components6

type Components6[A, B, C, D, E, F any] struct {
	A ComponentAccess[A]
	B ComponentAccess[B]
	C ComponentAccess[C]
	D ComponentAccess[D]
	E ComponentAccess[E]
	F ComponentAccess[F]
}

Components6 contains explicitly tracked component access for one entity.

type Components7

type Components7[A, B, C, D, E, F, G any] struct {
	A ComponentAccess[A]
	B ComponentAccess[B]
	C ComponentAccess[C]
	D ComponentAccess[D]
	E ComponentAccess[E]
	F ComponentAccess[F]
	G ComponentAccess[G]
}

Components7 contains explicitly tracked component access for one entity.

type Condition

type Condition func(*SystemContext) bool

type Entity

type Entity uint64

func (Entity) Index

func (e Entity) Index() (uint32, bool)

Index decodes the zero-based metadata slot. It does not validate liveness.

func (Entity) PickingID

func (e Entity) PickingID() uint32

PickingID returns the non-zero entity slot encoded into GPU picking targets. The value remains stable for the lifetime of the entity and can be resolved without maintaining a per-frame map.

type EntityRow

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

EntityRow borrows one entity's location until the next structural mutation. Use a fresh Row after spawning, despawning, adding/removing components or World.Maintain, which may compact component storage.

type EntitySlot

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

EntitySlot is a cached entity lookup bound to one World.

A slot keeps the entity generation, so resolving it after the entity has been despawned or its index has been reused fails instead of returning a different entity. Create slots during setup and reuse them in hot paths.

func (EntitySlot) Entity

func (s EntitySlot) Entity() Entity

Entity returns the raw entity handle stored in the slot. Use EntityBySlot when the slot may have outlived a scene mutation and needs validation.

func (EntitySlot) Get

func (s EntitySlot) Get[T any]() (T, bool)

Get reads a component from the bound world. Empty and stale slots return false.

func (EntitySlot) GetMut

func (s EntitySlot) GetMut[T any]() *T

GetMut returns a mutable component reference, or nil for an empty or stale slot. The pointer must not outlive structural mutations.

func (EntitySlot) GetRef

func (s EntitySlot) GetRef[T any]() *T

GetRef returns a component reference without marking it changed, or nil for an empty or stale slot. The pointer must not outlive structural mutations.

func (EntitySlot) Has

func (s EntitySlot) Has[T any]() bool

Has reports whether the bound entity has the component. Empty and stale slots return false.

func (EntitySlot) MustMut

func (s EntitySlot) MustMut[T any]() *T

MustMut requires a component on the bound entity. The pointer must not outlive structural mutations.

func (EntitySlot) Valid

func (s EntitySlot) Valid() bool

Valid reports whether the slot contains a world-bound entity handle. It does not prove that the entity is still alive; resolve it through World.

type MessageReader

type MessageReader[T any] struct {
	// contains filtered or unexported fields
}

MessageReader tracks consumption of one message type within one world. Its zero value starts at the oldest retained message. Consumers use separate readers; copying a reader copies its current position.

func (*MessageReader[T]) All

func (r *MessageReader[T]) All(world *World) iter.Seq[*T]

All visits unread messages without copying them. The reader consumes each message before yielding it, so break, return, and panic retain the remaining messages. Pointers are borrowed only for the current iteration body; do not advance message buffers during iteration. Use a separate reader per consumer.

func (*MessageReader[T]) Discard

func (r *MessageReader[T]) Discard(world *World)

Discard skips all currently retained messages for this reader in constant time. Other readers and messages written later are unaffected.

func (*MessageReader[T]) Read

func (r *MessageReader[T]) Read(world *World) []T

Read copies unread messages to a new slice and consumes them. Use All for direct iteration or ReadInto when a retained copy needs reusable storage.

func (*MessageReader[T]) ReadInto

func (r *MessageReader[T]) ReadInto(world *World, dst []T) []T

ReadInto writes unread messages into a caller-owned buffer and advances the reader. Reusing the returned slice avoids the allocation performed by Read.

type Patch1

type Patch1[A any] struct {
	// contains filtered or unexported fields
}

Patch1 upserts typed values and removes other components in one migration. Prepare once per world; copies share transitions. Inserted types take precedence over removals.

func (Patch1[A]) Apply

func (p Patch1[A]) Apply(entity Entity, a A) error

Apply preserves Added for replacements and both ticks for retained values. Cleanup hooks run before any writes; warmed transitions and capacities allocate nothing.

func (Patch1[A]) Queue

func (p Patch1[A]) Queue(commands *Commands, entity Entity, a A)

Queue copies typed values into reusable command storage for deferred application.

func (Patch1[A]) Reserve

func (p Patch1[A]) Reserve(capacity int)

Reserve prepares populated or preallocated source tables and reserves their migration targets.

type Patch2

type Patch2[A, B any] struct {
	// contains filtered or unexported fields
}

Patch2 upserts typed values and removes other components in one migration. Prepare once per world; copies share transitions. Inserted types take precedence over removals.

func (Patch2[A, B]) Apply

func (p Patch2[A, B]) Apply(entity Entity, a A, b B) error

Apply preserves Added for replacements and both ticks for retained values. Cleanup hooks run before any writes; warmed transitions and capacities allocate nothing.

func (Patch2[A, B]) Queue

func (p Patch2[A, B]) Queue(commands *Commands, entity Entity, a A, b B)

Queue copies typed values into reusable command storage for deferred application.

func (Patch2[A, B]) Reserve

func (p Patch2[A, B]) Reserve(capacity int)

Reserve prepares populated or preallocated source tables and reserves their migration targets.

type Patch3

type Patch3[A, B, C any] struct {
	// contains filtered or unexported fields
}

Patch3 upserts typed values and removes other components in one migration. Prepare once per world; copies share transitions. Inserted types take precedence over removals.

func (Patch3[A, B, C]) Apply

func (p Patch3[A, B, C]) Apply(entity Entity, a A, b B, c C) error

Apply preserves Added for replacements and both ticks for retained values. Cleanup hooks run before any writes; warmed transitions and capacities allocate nothing.

func (Patch3[A, B, C]) Queue

func (p Patch3[A, B, C]) Queue(commands *Commands, entity Entity, a A, b B, c C)

Queue copies typed values into reusable command storage for deferred application.

func (Patch3[A, B, C]) Reserve

func (p Patch3[A, B, C]) Reserve(capacity int)

Reserve prepares populated or preallocated source tables and reserves their migration targets.

type Patch4

type Patch4[A, B, C, D any] struct {
	// contains filtered or unexported fields
}

Patch4 upserts typed values and removes other components in one migration. Prepare once per world; copies share transitions. Inserted types take precedence over removals.

func (Patch4[A, B, C, D]) Apply

func (p Patch4[A, B, C, D]) Apply(entity Entity, a A, b B, c C, d D) error

Apply preserves Added for replacements and both ticks for retained values. Cleanup hooks run before any writes; warmed transitions and capacities allocate nothing.

func (Patch4[A, B, C, D]) Queue

func (p Patch4[A, B, C, D]) Queue(commands *Commands, entity Entity, a A, b B, c C, d D)

Queue copies typed values into reusable command storage for deferred application.

func (Patch4[A, B, C, D]) Reserve

func (p Patch4[A, B, C, D]) Reserve(capacity int)

Reserve prepares populated or preallocated source tables and reserves their migration targets.

type Patch5

type Patch5[A, B, C, D, E any] struct {
	// contains filtered or unexported fields
}

Patch5 upserts typed values and removes other components in one migration. Prepare once per world; copies share transitions. Inserted types take precedence over removals.

func (Patch5[A, B, C, D, E]) Apply

func (p Patch5[A, B, C, D, E]) Apply(entity Entity, a A, b B, c C, d D, e E) error

Apply preserves Added for replacements and both ticks for retained values. Cleanup hooks run before any writes; warmed transitions and capacities allocate nothing.

func (Patch5[A, B, C, D, E]) Queue

func (p Patch5[A, B, C, D, E]) Queue(commands *Commands, entity Entity, a A, b B, c C, d D, e E)

Queue copies typed values into reusable command storage for deferred application.

func (Patch5[A, B, C, D, E]) Reserve

func (p Patch5[A, B, C, D, E]) Reserve(capacity int)

Reserve prepares populated or preallocated source tables and reserves their migration targets.

type Patch6

type Patch6[A, B, C, D, E, F any] struct {
	// contains filtered or unexported fields
}

Patch6 upserts typed values and removes other components in one migration. Prepare once per world; copies share transitions. Inserted types take precedence over removals.

func (Patch6[A, B, C, D, E, F]) Apply

func (p Patch6[A, B, C, D, E, F]) Apply(entity Entity, a A, b B, c C, d D, e E, f F) error

Apply preserves Added for replacements and both ticks for retained values. Cleanup hooks run before any writes; warmed transitions and capacities allocate nothing.

func (Patch6[A, B, C, D, E, F]) Queue

func (p Patch6[A, B, C, D, E, F]) Queue(commands *Commands, entity Entity, a A, b B, c C, d D, e E, f F)

Queue copies typed values into reusable command storage for deferred application.

func (Patch6[A, B, C, D, E, F]) Reserve

func (p Patch6[A, B, C, D, E, F]) Reserve(capacity int)

Reserve prepares populated or preallocated source tables and reserves their migration targets.

type Patch7

type Patch7[A, B, C, D, E, F, G any] struct {
	// contains filtered or unexported fields
}

Patch7 upserts typed values and removes other components in one migration. Prepare once per world; copies share transitions. Inserted types take precedence over removals.

func (Patch7[A, B, C, D, E, F, G]) Apply

func (p Patch7[A, B, C, D, E, F, G]) Apply(entity Entity, a A, b B, c C, d D, e E, f F, g G) error

Apply preserves Added for replacements and both ticks for retained values. Cleanup hooks run before any writes; warmed transitions and capacities allocate nothing.

func (Patch7[A, B, C, D, E, F, G]) Queue

func (p Patch7[A, B, C, D, E, F, G]) Queue(commands *Commands, entity Entity, a A, b B, c C, d D, e E, f F, g G)

Queue copies typed values into reusable command storage for deferred application.

func (Patch7[A, B, C, D, E, F, G]) Reserve

func (p Patch7[A, B, C, D, E, F, G]) Reserve(capacity int)

Reserve prepares populated or preallocated source tables and reserves their migration targets.

type Patch8

type Patch8[A, B, C, D, E, F, G, H any] struct {
	// contains filtered or unexported fields
}

Patch8 upserts typed values and removes other components in one migration. Prepare once per world; copies share transitions. Inserted types take precedence over removals.

func (Patch8[A, B, C, D, E, F, G, H]) Apply

func (p Patch8[A, B, C, D, E, F, G, H]) Apply(entity Entity, a A, b B, c C, d D, e E, f F, g G, h H) error

Apply preserves Added for replacements and both ticks for retained values. Cleanup hooks run before any writes; warmed transitions and capacities allocate nothing.

func (Patch8[A, B, C, D, E, F, G, H]) Queue

func (p Patch8[A, B, C, D, E, F, G, H]) Queue(commands *Commands, entity Entity, a A, b B, c C, d D, e E, f F, g G, h H)

Queue copies typed values into reusable command storage for deferred application.

func (Patch8[A, B, C, D, E, F, G, H]) Reserve

func (p Patch8[A, B, C, D, E, F, G, H]) Reserve(capacity int)

Reserve prepares populated or preallocated source tables and reserves their migration targets.

type PreparedBundle

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

PreparedBundle caches the world-specific component IDs and sorted entries of a Bundle. It is immutable after creation and can be reused for repeated spawns without rebuilding the bundle description.

type PreparedRemoval

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

PreparedRemoval removes a component set in one archetype migration. Copies share the same world-bound transition cache. Missing types are ignored.

func (PreparedRemoval) Apply

func (r PreparedRemoval) Apply(entity Entity) bool

Apply returns whether any components were removed. It is allocation-free once the source transition and destination capacity have been prepared. Cleanup hooks see the complete source row and run before storage is moved. Hook panics do not move the row; external side effects are not rolled back.

func (PreparedRemoval) Reserve

func (r PreparedRemoval) Reserve(capacity int)

Reserve prepares populated or preallocated source archetypes and reserves each destination for capacity entities. Unused shapes still need warming.

type QueryOption

type QueryOption interface {
	// contains filtered or unexported methods
}

func Unscoped

func Unscoped() QueryOption

Unscoped visits matching tables independently of the current execution scope. It is intended for world-owned indexes that also include suspended scenes.

func With

func With[T any]() QueryOption

func Without

func Without[T any]() QueryOption

type QueryScope

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

QueryScope confines ordinary queries to a borrowed entity set. Direct component access remains available for loading and lifetime management. Ordinary queries use table order; explicit Query.In lists preserve order. Membership is compiled at structural boundaries; warm iteration does not allocate. World.Maintain retires caches unused for 30 frames. Borrowed membership survives.

func (*QueryScope) ReleaseCache

func (s *QueryScope) ReleaseCache()

ReleaseCache retires compiled membership and system values, preserving the borrowed entity set. Existing cache pointers must no longer be used.

func (*QueryScope) Reset

func (s *QueryScope) Reset(entities []Entity)

type QueryView1

type QueryView1[A any] struct {
	// contains filtered or unexported fields
}

QueryView1 retains a query plan and its filter snapshot. Range over All to iterate.

func (QueryView1[A]) All

func (v QueryView1[A]) All(yield func(Entity, ComponentAccess[A]) bool)

func (QueryView1[A]) In

func (v QueryView1[A]) In(entities []Entity) QueryView1[A]

In limits traversal to the supplied entities, preserving their order. The list is borrowed and must not change during iteration. Nil visits none.

type QueryView2

type QueryView2[A, B any] struct {
	// contains filtered or unexported fields
}

QueryView2 retains a query plan and its filter snapshot. Range over All to iterate.

func (QueryView2[A, B]) All

func (v QueryView2[A, B]) All(yield func(Entity, Components2[A, B]) bool)

func (QueryView2[A, B]) In

func (v QueryView2[A, B]) In(entities []Entity) QueryView2[A, B]

In limits traversal to the supplied entities, preserving their order. The list is borrowed and must not change during iteration. Nil visits none.

type QueryView3

type QueryView3[A, B, C any] struct {
	// contains filtered or unexported fields
}

QueryView3 retains a query plan and its filter snapshot. Range over All to iterate.

func (QueryView3[A, B, C]) All

func (v QueryView3[A, B, C]) All(yield func(Entity, Components3[A, B, C]) bool)

func (QueryView3[A, B, C]) In

func (v QueryView3[A, B, C]) In(entities []Entity) QueryView3[A, B, C]

In limits traversal to the supplied entities, preserving their order. The list is borrowed and must not change during iteration. Nil visits none.

type QueryView4

type QueryView4[A, B, C, D any] struct {
	// contains filtered or unexported fields
}

QueryView4 retains a query plan and its filter snapshot. Range over All to iterate.

func (QueryView4[A, B, C, D]) All

func (v QueryView4[A, B, C, D]) All(yield func(Entity, Components4[A, B, C, D]) bool)

func (QueryView4[A, B, C, D]) In

func (v QueryView4[A, B, C, D]) In(entities []Entity) QueryView4[A, B, C, D]

In limits traversal to the supplied entities, preserving their order. The list is borrowed and must not change during iteration. Nil visits none.

type QueryView5

type QueryView5[A, B, C, D, E any] struct {
	// contains filtered or unexported fields
}

QueryView5 retains a query plan and its filter snapshot. Range over All to iterate.

func (QueryView5[A, B, C, D, E]) All

func (v QueryView5[A, B, C, D, E]) All(yield func(Entity, Components5[A, B, C, D, E]) bool)

func (QueryView5[A, B, C, D, E]) In

func (v QueryView5[A, B, C, D, E]) In(entities []Entity) QueryView5[A, B, C, D, E]

In limits traversal to the supplied entities, preserving their order. The list is borrowed and must not change during iteration. Nil visits none.

type QueryView6

type QueryView6[A, B, C, D, E, F any] struct {
	// contains filtered or unexported fields
}

QueryView6 retains a query plan and its filter snapshot. Range over All to iterate.

func (QueryView6[A, B, C, D, E, F]) All

func (v QueryView6[A, B, C, D, E, F]) All(yield func(Entity, Components6[A, B, C, D, E, F]) bool)

func (QueryView6[A, B, C, D, E, F]) In

func (v QueryView6[A, B, C, D, E, F]) In(entities []Entity) QueryView6[A, B, C, D, E, F]

In limits traversal to the supplied entities, preserving their order. The list is borrowed and must not change during iteration. Nil visits none.

type QueryView7

type QueryView7[A, B, C, D, E, F, G any] struct {
	// contains filtered or unexported fields
}

QueryView7 retains a query plan and its filter snapshot. Range over All to iterate.

func (QueryView7[A, B, C, D, E, F, G]) All

func (v QueryView7[A, B, C, D, E, F, G]) All(yield func(Entity, Components7[A, B, C, D, E, F, G]) bool)

func (QueryView7[A, B, C, D, E, F, G]) In

func (v QueryView7[A, B, C, D, E, F, G]) In(entities []Entity) QueryView7[A, B, C, D, E, F, G]

In limits traversal to the supplied entities, preserving their order. The list is borrowed and must not change during iteration. Nil visits none.

type Schedule

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

func NewSchedule

func NewSchedule(name string) *Schedule

func (*Schedule) Add

func (s *Schedule) Add(config SystemConfig) error

func (*Schedule) Order

func (s *Schedule) Order() ([]string, error)

func (*Schedule) Remove

func (s *Schedule) Remove(name string)

func (*Schedule) Run

func (s *Schedule) Run(world *World) error

type Scratch

type Scratch[T any] struct {
	Values []T
	// contains filtered or unexported fields
}

func (*Scratch[T]) ReleaseUnused

func (s *Scratch[T]) ReleaseUnused()

ReleaseUnused clears references in the portion used by the previous frame that was not overwritten in the current frame.

func (*Scratch[T]) Reserve

func (s *Scratch[T]) Reserve(want int) []T

Reserve truncates the buffer to empty and grows it to hold want values. Growth is geometric so a slowly rising entity count does not reallocate each frame.

type Spawner1

type Spawner1[A any] struct {
	// contains filtered or unexported fields
}

Spawner1 binds component columns once for repeated allocation-free creation.

func (*Spawner1[A]) Reserve

func (s *Spawner1[A]) Reserve(capacity int)

Reserve preallocates the archetype and world metadata for capacity entities.

func (*Spawner1[A]) Spawn

func (s *Spawner1[A]) Spawn(a A) Entity

type Spawner2

type Spawner2[A, B any] struct {
	// contains filtered or unexported fields
}

Spawner2 binds component columns once for repeated allocation-free creation.

func (*Spawner2[A, B]) Reserve

func (s *Spawner2[A, B]) Reserve(capacity int)

Reserve preallocates the archetype and world metadata for capacity entities.

func (*Spawner2[A, B]) Spawn

func (s *Spawner2[A, B]) Spawn(a A, b B) Entity

type Spawner3

type Spawner3[A, B, C any] struct {
	// contains filtered or unexported fields
}

Spawner3 binds component columns once for repeated allocation-free creation.

func (*Spawner3[A, B, C]) Reserve

func (s *Spawner3[A, B, C]) Reserve(capacity int)

Reserve preallocates the archetype and world metadata for capacity entities.

func (*Spawner3[A, B, C]) Spawn

func (s *Spawner3[A, B, C]) Spawn(a A, b B, c C) Entity

type Spawner4

type Spawner4[A, B, C, D any] struct {
	// contains filtered or unexported fields
}

Spawner4 binds component columns once for repeated allocation-free creation.

func (*Spawner4[A, B, C, D]) Reserve

func (s *Spawner4[A, B, C, D]) Reserve(capacity int)

Reserve preallocates the archetype and world metadata for capacity entities.

func (*Spawner4[A, B, C, D]) Spawn

func (s *Spawner4[A, B, C, D]) Spawn(a A, b B, c C, d D) Entity

type Spawner5

type Spawner5[A, B, C, D, E any] struct {
	// contains filtered or unexported fields
}

Spawner5 binds component columns once for repeated allocation-free creation.

func (*Spawner5[A, B, C, D, E]) Reserve

func (s *Spawner5[A, B, C, D, E]) Reserve(capacity int)

Reserve preallocates the archetype and world metadata for capacity entities.

func (*Spawner5[A, B, C, D, E]) Spawn

func (s *Spawner5[A, B, C, D, E]) Spawn(a A, b B, c C, d D, e E) Entity

type Spawner6

type Spawner6[A, B, C, D, E, F any] struct {
	// contains filtered or unexported fields
}

Spawner6 binds component columns once for repeated allocation-free creation.

func (*Spawner6[A, B, C, D, E, F]) Reserve

func (s *Spawner6[A, B, C, D, E, F]) Reserve(capacity int)

Reserve preallocates the archetype and world metadata for capacity entities.

func (*Spawner6[A, B, C, D, E, F]) Spawn

func (s *Spawner6[A, B, C, D, E, F]) Spawn(a A, b B, c C, d D, e E, f F) Entity

type Spawner7

type Spawner7[A, B, C, D, E, F, G any] struct {
	// contains filtered or unexported fields
}

Spawner7 binds component columns once for repeated allocation-free creation.

func (*Spawner7[A, B, C, D, E, F, G]) Reserve

func (s *Spawner7[A, B, C, D, E, F, G]) Reserve(capacity int)

Reserve preallocates the archetype and world metadata for capacity entities.

func (*Spawner7[A, B, C, D, E, F, G]) Spawn

func (s *Spawner7[A, B, C, D, E, F, G]) Spawn(a A, b B, c C, d D, e E, f F, g G) Entity

type Spawner8

type Spawner8[A, B, C, D, E, F, G, H any] struct {
	// contains filtered or unexported fields
}

Spawner8 binds component columns once for repeated allocation-free creation.

func (*Spawner8[A, B, C, D, E, F, G, H]) Reserve

func (s *Spawner8[A, B, C, D, E, F, G, H]) Reserve(capacity int)

Reserve preallocates the archetype and world metadata for capacity entities.

func (*Spawner8[A, B, C, D, E, F, G, H]) Spawn

func (s *Spawner8[A, B, C, D, E, F, G, H]) Spawn(a A, b B, c C, d D, e E, f F, g G, h H) Entity

type System

type System func(*SystemContext) error

type SystemConfig

type SystemConfig struct {
	System System
	Name   string
	Before []string
	After  []string
	RunIf  []Condition
}

func (SystemConfig) Run

func (c SystemConfig) Run(world *World) error

type SystemContext

type SystemContext struct {
	World    *World
	Commands *Commands
	// contains filtered or unexported fields
}

func (*SystemContext) Added

func (context *SystemContext) Added[T any]() QueryOption

func (*SystemContext) Changed

func (context *SystemContext) Changed[T any]() QueryOption

func (*SystemContext) LastRun

func (c *SystemContext) LastRun() Tick

func (*SystemContext) Local

func (context *SystemContext) Local[Tag, T any]() *T

func (*SystemContext) ResourceAdded

func (context *SystemContext) ResourceAdded[T any]() bool

func (*SystemContext) ResourceChanged

func (context *SystemContext) ResourceChanged[T any]() bool

func (*SystemContext) ThisRun

func (c *SystemContext) ThisRun() Tick

type Tick

type Tick uint32

type World

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

func NewWorld

func NewWorld() *World

func (*World) AdvanceMessages

func (world *World) AdvanceMessages()

func (*World) BindComponent

func (w *World) BindComponent[T any]() ComponentBinding[T]

func (*World) ChangeTick

func (w *World) ChangeTick() Tick

ChangeTick returns the current change-tracking clock without advancing it.

func (*World) ChangesSince

func (w *World) ChangesSince(since Tick) SystemContext

ChangesSince snapshots a read window ending at the current change tick. It does not execute a system or advance the clock.

func (*World) Commands

func (w *World) Commands() *Commands

func (*World) ComponentRevision

func (world *World) ComponentRevision[T any]() (version, structure uint64)

ComponentRevision reads the content and structural versions in one lookup. Missing types return zero without registering storage or advancing ticks.

func (*World) ComponentStructureVersion

func (world *World) ComponentStructureVersion[T any]() uint64

ComponentStructureVersion changes when rows are inserted or removed.

func (*World) ComponentValueRevision

func (world *World) ComponentValueRevision[T any]() (version, membership uint64)

ComponentValueRevision reports writes and membership changes, excluding migrations that only relocate unchanged values between archetypes. The second result changes only when values are inserted or removed.

func (*World) ComponentVersion

func (world *World) ComponentVersion[T any]() uint64

ComponentVersion changes for writes, insertion, removal and row migration.

func (*World) Despawn

func (w *World) Despawn(entity Entity) bool

func (*World) Entities

func (w *World) Entities() iter.Seq[Entity]

Entities traverses every live entity independently of the current scope. It is intended for rebuilding scopes, not normal system updates.

func (*World) EntityByPickingID

func (w *World) EntityByPickingID(id uint32) (Entity, bool)

EntityByPickingID resolves the current live entity occupying a GPU picking slot. A stale or background ID returns false.

func (*World) EntityBySlot

func (w *World) EntityBySlot(slot EntitySlot) (Entity, bool)

EntityBySlot resolves a cached entity lookup without string or map allocation. Slots from another world and stale generations are rejected.

func (*World) EntityCount

func (w *World) EntityCount() int

func (*World) EntitySlots

func (w *World) EntitySlots() int

EntitySlots reports the metadata slots used by live, free and reserved entities. Indexed external caches can grow to this size and check handles.

func (*World) EntityVersion

func (w *World) EntityVersion() uint64

EntityVersion changes only when a live entity is spawned or despawned. Adding or removing components does not change entity membership.

func (*World) FlushCommands

func (w *World) FlushCommands() error

func (*World) FrameScratch

func (world *World) FrameScratch[Tag, T any]() *Scratch[T]

func (*World) FrameScratchMap

func (world *World) FrameScratchMap[Tag any, K comparable, V any]() map[K]V

FrameScratchMap returns a per-frame map that is cleared on every call. Maps are reference values, so the stored map is the one callers mutate.

func (*World) FrameValue

func (world *World) FrameValue[Tag, T any]() *T

func (*World) Get

func (world *World) Get[T any](entity Entity) (value T, ok bool)

func (*World) GetMut

func (world *World) GetMut[T any](entity Entity) *T

func (*World) GetRef

func (world *World) GetRef[T any](entity Entity) *T

GetRef returns a component reference without marking it changed. Callers must not mutate it or retain it across structural mutations.

func (*World) GetResource

func (world *World) GetResource[T any]() (T, bool)

func (*World) GetResourceMut

func (world *World) GetResourceMut[T any]() (*T, bool)

func (*World) Has

func (world *World) Has[T any](entity Entity) bool

func (*World) InQueryScope

func (w *World) InQueryScope(entity Entity) bool

InQueryScope reports whether a live entity belongs to the current query scope. It lets hierarchy traversals honor scopes without scanning them.

func (*World) Insert

func (world *World) Insert[T any](entity Entity, value T) error

func (*World) Insert2

func (world *World) Insert2[A, B any](entity Entity, a A, b B) error

Insert2 upserts values together, reusing a world-local patch plan.

func (*World) Insert3

func (world *World) Insert3[A, B, C any](entity Entity, a A, b B, c C) error

Insert3 upserts values together, reusing a world-local patch plan.

func (*World) Insert4

func (world *World) Insert4[A, B, C, D any](entity Entity, a A, b B, c C, d D) error

Insert4 upserts values together, reusing a world-local patch plan.

func (*World) Insert5

func (world *World) Insert5[A, B, C, D, E any](entity Entity, a A, b B, c C, d D, e E) error

Insert5 upserts values together, reusing a world-local patch plan.

func (*World) Insert6

func (world *World) Insert6[A, B, C, D, E, F any](entity Entity, a A, b B, c C, d D, e E, f F) error

Insert6 upserts values together, reusing a world-local patch plan.

func (*World) Insert7

func (world *World) Insert7[A, B, C, D, E, F, G any](entity Entity, a A, b B, c C, d D, e E, f F, g G) error

Insert7 upserts values together, reusing a world-local patch plan.

func (*World) Insert8

func (world *World) Insert8[A, B, C, D, E, F, G, H any](entity Entity, a A, b B, c C, d D, e E, f F, g G, h H) error

Insert8 upserts values together, reusing a world-local patch plan.

func (*World) InsertResource

func (world *World) InsertResource[T any](resource T)

func (*World) IsAlive

func (w *World) IsAlive(entity Entity) bool

func (*World) Maintain

func (w *World) Maintain()

Maintain releases caches after sustained underuse. Call once at the end of a frame, after all borrowed component accesses and drawing snapshots are done. Table and column identities survive; borrowed rows expire if storage moves.

func (*World) MessageScratch

func (world *World) MessageScratch[Tag, T any]() *Scratch[T]

MessageScratch provides two-buffer storage for data borrowed by messages. Append to Values; AdvanceMessages retains it for the next message frame and recycles the older buffer. Tags isolate arenas even when T is identical. Do not overwrite borrowed values before two calls to AdvanceMessages.

func (*World) MustMut

func (world *World) MustMut[T any](entity Entity) *T

MustMut returns an existing component with write access. A missing component or stale entity is a structural error. Do not retain the pointer across structural mutations.

func (*World) MutationVersion

func (w *World) MutationVersion() uint64

func (*World) NewPatch1

func (world *World) NewPatch1[A any](removed ...ComponentType) Patch1[A]

func (*World) NewPatch2

func (world *World) NewPatch2[A, B any](removed ...ComponentType) Patch2[A, B]

func (*World) NewPatch3

func (world *World) NewPatch3[A, B, C any](removed ...ComponentType) Patch3[A, B, C]

func (*World) NewPatch4

func (world *World) NewPatch4[A, B, C, D any](removed ...ComponentType) Patch4[A, B, C, D]

func (*World) NewPatch5

func (world *World) NewPatch5[A, B, C, D, E any](removed ...ComponentType) Patch5[A, B, C, D, E]

func (*World) NewPatch6

func (world *World) NewPatch6[A, B, C, D, E, F any](removed ...ComponentType) Patch6[A, B, C, D, E, F]

func (*World) NewPatch7

func (world *World) NewPatch7[A, B, C, D, E, F, G any](removed ...ComponentType) Patch7[A, B, C, D, E, F, G]

func (*World) NewPatch8

func (world *World) NewPatch8[A, B, C, D, E, F, G, H any](removed ...ComponentType) Patch8[A, B, C, D, E, F, G, H]

func (*World) NewSpawner1

func (world *World) NewSpawner1[A any]() Spawner1[A]

func (*World) NewSpawner2

func (world *World) NewSpawner2[A, B any]() Spawner2[A, B]

func (*World) NewSpawner3

func (world *World) NewSpawner3[A, B, C any]() Spawner3[A, B, C]

func (*World) NewSpawner4

func (world *World) NewSpawner4[A, B, C, D any]() Spawner4[A, B, C, D]

func (*World) NewSpawner5

func (world *World) NewSpawner5[A, B, C, D, E any]() Spawner5[A, B, C, D, E]

func (*World) NewSpawner6

func (world *World) NewSpawner6[A, B, C, D, E, F any]() Spawner6[A, B, C, D, E, F]

func (*World) NewSpawner7

func (world *World) NewSpawner7[A, B, C, D, E, F, G any]() Spawner7[A, B, C, D, E, F, G]

func (*World) NewSpawner8

func (world *World) NewSpawner8[A, B, C, D, E, F, G, H any]() Spawner8[A, B, C, D, E, F, G, H]

func (*World) OnComponentRemove

func (world *World) OnComponentRemove[T any](cleanup func(*World, Entity, *T))

OnComponentRemove installs a cleanup hook for removal and despawn. Hooks must not change entity structure; archetype migration does not invoke them.

func (*World) PrepareBundle

func (w *World) PrepareBundle(bundle Bundle) PreparedBundle

PrepareBundle resolves and sorts a bundle for this world. Reuse the result with SpawnPrepared when the same component shape is spawned repeatedly.

func (*World) PrepareRemoval

func (world *World) PrepareRemoval(types ...ComponentType) PreparedRemoval

PrepareRemoval registers the supplied types and binds a reusable removal set. Duplicate descriptors are harmless; an empty set never changes an entity.

func (*World) Query

func (world *World) Query[A any](options ...QueryOption) QueryView1[A]

Query iterates matching entities. Get and Ref do not mark changes; Mut does. Access values and component pointers must not outlive the iteration.

func (*World) Query2

func (world *World) Query2[A, B any](options ...QueryOption) QueryView2[A, B]

Query2 iterates matching entities. Get and Ref do not mark changes; Mut does. Access values and component pointers must not outlive the iteration.

func (*World) Query3

func (world *World) Query3[A, B, C any](options ...QueryOption) QueryView3[A, B, C]

Query3 iterates matching entities. Get and Ref do not mark changes; Mut does. Access values and component pointers must not outlive the iteration.

func (*World) Query4

func (world *World) Query4[A, B, C, D any](options ...QueryOption) QueryView4[A, B, C, D]

Query4 iterates matching entities. Get and Ref do not mark changes; Mut does. Access values and component pointers must not outlive the iteration.

func (*World) Query5

func (world *World) Query5[A, B, C, D, E any](options ...QueryOption) QueryView5[A, B, C, D, E]

Query5 iterates matching entities. Get and Ref do not mark changes; Mut does. Access values and component pointers must not outlive the iteration.

func (*World) Query6

func (world *World) Query6[A, B, C, D, E, F any](options ...QueryOption) QueryView6[A, B, C, D, E, F]

Query6 iterates matching entities. Get and Ref do not mark changes; Mut does. Access values and component pointers must not outlive the iteration.

func (*World) Query7

func (world *World) Query7[A, B, C, D, E, F, G any](options ...QueryOption) QueryView7[A, B, C, D, E, F, G]

Query7 iterates matching entities. Get and Ref do not mark changes; Mut does. Access values and component pointers must not outlive the iteration.

func (*World) QueryScope

func (w *World) QueryScope() *QueryScope

func (*World) QueryScopeKey

func (w *World) QueryScopeKey() (*QueryScope, uint64)

QueryScopeKey identifies both the selected scope and its structural revision.

func (*World) Remove

func (world *World) Remove[T any](entity Entity) (T, bool)

func (*World) RemoveResource

func (world *World) RemoveResource[T any]() (T, bool)

func (*World) ReserveEntities

func (w *World) ReserveEntities(capacity int)

ReserveEntities grows entity metadata storage without changing the live entity count. Use it before a known spawn burst to keep the burst allocation free; archetype columns can be reserved through SpawnerN.Reserve.

func (*World) ResourceChangeTick

func (world *World) ResourceChangeTick[T any]() Tick

ResourceChangeTick returns the last write tick, or zero for a missing resource.

func (*World) Row

func (w *World) Row(entity Entity) EntityRow

func (*World) ScopeValue

func (world *World) ScopeValue[Tag, T any]() *T

ScopeValue keeps long-lived system caches separate for execution and rendering scopes. Switching scopes does not rebuild the other scope's cache. Fetch values again when using a scope after ReleaseCache, an empty Reset or 30 frames without using it; previously borrowed cache pointers have expired.

func (*World) SetIfChanged

func (world *World) SetIfChanged[T comparable](entity Entity, value T) bool

SetIfChanged updates an existing component only when its value differs. It returns false for equal values, missing components and stale entities. It does not insert components and may be used during query iteration.

func (*World) SetQueryScope

func (w *World) SetQueryScope(scope *QueryScope) *QueryScope

SetQueryScope returns the previous scope. Nil restores unrestricted queries. A scope cannot change while a query iterator is live.

func (*World) Slot

func (w *World) Slot(entity Entity) EntitySlot

Slot creates a cached lookup for an alive entity in this world. The slot does not keep the entity alive; EntityBySlot reports false after despawn or slot reuse. An invalid entity produces the zero slot.

func (*World) Spawn

func (w *World) Spawn(bundle Bundle) Entity

func (*World) SpawnPrepared

func (w *World) SpawnPrepared(bundle PreparedBundle) Entity

SpawnPrepared spawns a previously prepared bundle without rebuilding its component entry list. The prepared bundle must belong to this world.

func (*World) StructureVersion

func (w *World) StructureVersion() uint64

StructureVersion changes when entities are spawned, despawned or moved.

func (*World) WriteMessage

func (world *World) WriteMessage[T any](message T)

Jump to

Keyboard shortcuts

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