Skip to content

1681-engine / index / Entity

Type Alias: Entity ​

ts
type Entity = number;

Defined in: src/ecs/World.ts:22

An entity–component–system store. Entities are numbers; components are data kept in one sparse set per component type; systems are functions run in the order they were added, each in a phase:

  • fixed runs once per simulation step (FixedLoop), for movement and rules;
  • frame runs once per rendered frame, for drawing and anything purely visual.

Storage is a sparse set per component (packed arrays, O(1) lookups), the layout fast ECS libraries use. For hot loops prefer each (a callback, no allocation per entity) over query (an iterator yielding a fresh row).

Entity ids are recycled: an id carries its slot index and a generation, so an id kept after its entity was destroyed never matches the entity that later reuses the slot.

Changing structure while walking: adding components is always safe (new entries are not visited this walk). Removing a component or destroying an entity while a query, an each or a system run is in progress is deferred until it ends, so nothing is skipped or visited twice.

Released under the MIT License.