entities

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 1 Imported by: 0 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 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

type Record struct {
	Arch *storage.Archetype
	Row  int32
}

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

func (t *Table) Alloc() (storage.Entity, *Record)

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

func (t *Table) Free(e storage.Entity)

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.

func (*Table) Get

func (t *Table) Get(e storage.Entity) (*Record, bool)

Get returns the Record for e and true when e is a live handle: in range, allocated, not freed and matching the slot's current generation. It never panics, so it is also how callers implement IsAlive without a stale-entity panic.

func (*Table) Len

func (t *Table) Len() int

Len returns the number of currently live entities.

Jump to

Keyboard shortcuts

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