Documentation
¶
Overview ¶
Package registry maps component types to dense IDs and keeps, per component, the reflect.Type and a column factory captured at registration.
The factory is created inside Register, the only place where the concrete component type is known; later code that only holds an ID (archetype creation, values passed as any) builds columns through Info.NewColumn.
A Registry is safe for concurrent use. Reads are lock-free; see Registry.
Index ¶
Constants ¶
const MaxComponents = 4096
MaxComponents is the capacity of a registry: IDs 0..MaxComponents-1. It stays far below the int16 limit of storage.Archetype's column index.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
Register returns the ID of T, registering it on first use. It is idempotent.
It panics with "ecs: component must be a non-pointer struct: <type>" when T is not a struct (pointers included), and with "ecs: component registry capacity exceeded: max <n>" when the registry is full. A registered type is returned before either check, so a full registry still resolves its existing types.
Types ¶
type Info ¶
type Info struct {
ID storage.CompID
Type reflect.Type
// NewColumn returns an empty column of the component type. It allocates,
// which is fine because it only runs when an archetype is created.
NewColumn func() storage.Column
}
Info describes one registered component.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry assigns dense IDs, starting at 0 in registration order and never reused, to component types.
Reads use a copy-on-write snapshot behind an atomic pointer, so the steady state (an already registered type) costs one atomic load plus one map lookup and allocates nothing. Registering a new type takes a mutex and copies the map and slice: O(n) with n <= MaxComponents, paid once per type, mostly at package init.
func New ¶
New returns an empty registry holding at most max component types. Tests use a small max; package ecs uses MaxComponents.
func (*Registry) Info ¶
Info returns the entry for id. It panics with "ecs: component not registered: ComponentID(<id>)" for an unknown ID.