Documentation
¶
Overview ¶
Package entities tracks the live location of every entity in a World: a slot table keyed by entity ID, holding a generation counter (to detect stale handles) and a Record (which archetype and row currently store the entity).
The package works entirely in terms of storage.Entity; package ecs converts to and from its own Entity type field by field. It imports nothing beyond the standard library and ecs/internal/storage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Record ¶
Record is the current location of a live entity: the archetype that stores it and the row within that archetype. Arch is nil for a free slot.
A *Record returned by Table.Alloc or Table.Get is valid until the next call to Alloc, which may grow the backing slice; callers don't hold it across an allocation.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table maps entity IDs to their current Record and detects stale handles through a per-slot generation counter. The zero Table is ready to use.
Table is not safe for concurrent use; a World (which owns one) is single-goroutine.
func (*Table) Alloc ¶
Alloc reserves a slot and returns its handle together with a pointer to its Record, which the caller fills in (typically after appending a row to the destination archetype, since the row-to-entity table needs the handle first). The Record starts zeroed (Arch == nil); the caller must set it before the entity is considered alive.
Alloc reuses the most recently freed slot (LIFO), which keeps the slot table compact under churn and gives it good cache locality. The first ever Alloc returns generation 1 (see Free for why generation 0 never appears).
func (*Table) Free ¶
Free releases e's slot, invalidating every handle with its current generation, and makes the slot available for reuse by a later Alloc.
The caller must have confirmed e is currently alive (for example via Get); Free doesn't validate e and panics on an out-of-range ID.
The generation is incremented so stale handles are detected after reuse. On wrap from math.MaxUint32 it skips 0 and goes to 1, since generation 0 would make Entity{} (the zero Entity, ID 0, Generation 0) collide with a reused slot 0 — the zero Entity must never be alive.