registry

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: 6 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 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

View Source
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

func Register[T any](r *Registry) storage.CompID

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

func New(max int) *Registry

New returns an empty registry holding at most max component types. Tests use a small max; package ecs uses MaxComponents.

func (*Registry) Info

func (r *Registry) Info(id storage.CompID) Info

Info returns the entry for id. It panics with "ecs: component not registered: ComponentID(<id>)" for an unknown ID.

func (*Registry) Len

func (r *Registry) Len() int

Len returns the number of registered components.

func (*Registry) Lookup

func (r *Registry) Lookup(t reflect.Type) (storage.CompID, bool)

Lookup returns the ID of t and whether t is registered. It never registers and allocates nothing.

Jump to

Keyboard shortcuts

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