ecs

package module
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: 7 Imported by: ? 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.

README

ecs

github.com/weakpixel/ecs is an archetype-based Entity Component System for Go. Components are plain structs, entities are stable handles with a generation counter, and the World stores entities with the same components together, column by column, so views iterate contiguous arrays with zero allocations. An optional system package adds a stage-based Schedule, deferred Commands and event queues.

The module targets Go 1.27, uses the standard library only and has no dependencies. It builds for js/wasm.

Package Import path What it is
ecs github.com/weakpixel/ecs World, entities, components, views, queries, resources
system github.com/weakpixel/ecs/system Optional stage-based Schedule, deferred Commands, events

Installation

go get github.com/weakpixel/ecs

Quick start

package main

import (
	"fmt"

	"github.com/weakpixel/ecs"
)

type Position struct{ X, Y int }
type Velocity struct{ X, Y int }

func main() {
	world := ecs.NewWorld()

	entity := ecs.NewEntity2(world, Position{X: 1, Y: 2}, Velocity{X: 3, Y: 4})

	pos := ecs.GetComp[Position](world, entity)
	pos.X = 10

	movement := ecs.NewView2[Position, Velocity](world) // build once, reuse
	for _, c := range movement.Each() {
		pos, vel := c.Unpack()
		pos.X += vel.X
		pos.Y += vel.Y
	}
	fmt.Println(ecs.GetComp[Position](world, entity)) // &{13 6}

	world.DeleteEntity(entity)
	fmt.Println(world.IsAlive(entity)) // false
}

Documentation

Development

make all        # go generate, fmt, vet, test -race
make wasm-test  # the tests under GOOS=js GOARCH=wasm (needs Node)
make bench name=<label>    # benchmarks into build/bench/<label>.txt
make benchcmp new=<label>  # benchstat against build/bench/baseline.txt

License

MIT, see LICENSE.

Documentation

Overview

Package ecs is an archetype-based Entity Component System.

Components are plain non-pointer structs. The component registry is process-global and safe for concurrent use; a World is single-goroutine. Programmer errors panic with messages starting with "ecs: ".

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetComp

func GetComp[T any](w *World, e Entity) *T

GetComp returns a pointer to e's live T. It registers T on first use, like every function in this file.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" if e doesn't currently have T.

Cost: 0 allocations. The pointer is valid until the next structural change to e's archetype (an add, a remove, or a move); re-fetch it after one.

func GetCompOrNil

func GetCompOrNil[T any](w *World, e Entity) *T

GetCompOrNil is GetComp but returns nil instead of panicking when e doesn't currently have T. It still panics on a stale e.

Cost: 0 allocations.

func GetResource

func GetResource[T any](w *World) *T

GetResource returns the World's T resource.

Panics with "ecs: resource not set: <T>" if none is set.

func GetResourceOrNil

func GetResourceOrNil[T any](w *World) *T

GetResourceOrNil returns the World's T resource, or nil if none is set.

func HasComp

func HasComp[T any](w *World, e Entity) bool

HasComp reports whether e currently has T.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func HasResource

func HasResource[T any](w *World) bool

HasResource reports whether a T resource is currently set.

func RemoveComp

func RemoveComp[T any](w *World, e Entity)

RemoveComp removes e's T; a no-op, leaving the revision unchanged, if e doesn't have it. Removing moves e to a new archetype exactly once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func RemoveResource

func RemoveResource[T any](w *World)

RemoveResource removes the World's T resource; a no-op if none is set.

func SetComp

func SetComp[T any](w *World, e Entity, value T)

SetComp adds T to e or replaces it. Replacing a T e already has is in place and leaves the revision unchanged; adding moves e to a new archetype exactly once and bumps the revision once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

func SetResource

func SetResource[T any](w *World, v *T)

SetResource stores v as the World's singleton resource of type T, replacing any value set earlier. Resources are keyed by type, are not components, need no registration and are not attached to any entity.

Types

type ComponentID

type ComponentID uint16

ComponentID identifies a registered component type. IDs are dense, start at 0 and are assigned in registration order, so they are not stable across processes: don't persist them.

func RegisterComp

func RegisterComp[T any]() ComponentID

RegisterComp registers T if needed and returns its ID. It is idempotent, so it is also how to look up the ID of a type. It is safe for concurrent use and for package-level initializers (var id = ecs.RegisterComp[T]()).

Cost: a registered type costs one atomic load and a map lookup, with no allocations. A new type copies the registry once (O(registered types)).

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 4096" when the registry is full.

Example
package main

import (
	"fmt"

	"github.com/weakpixel/ecs"
)

type Position struct{ X, Y int }

func main() {
	id := ecs.RegisterComp[Position]()
	fmt.Println(id == ecs.RegisterComp[Position]()) // idempotent
}
Output:
true

type Components2

type Components2[T1, T2 any] struct {
	Comp1 *T1
	Comp2 *T2
}

Components2 holds pointers to 2 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components2[T1, T2]) Unpack

func (c Components2[T1, T2]) Unpack() (*T1, *T2)

Unpack returns the pointers as separate values.

type Components3

type Components3[T1, T2, T3 any] struct {
	Comp1 *T1
	Comp2 *T2
	Comp3 *T3
}

Components3 holds pointers to 3 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components3[T1, T2, T3]) Unpack

func (c Components3[T1, T2, T3]) Unpack() (*T1, *T2, *T3)

Unpack returns the pointers as separate values.

type Components4

type Components4[T1, T2, T3, T4 any] struct {
	Comp1 *T1
	Comp2 *T2
	Comp3 *T3
	Comp4 *T4
}

Components4 holds pointers to 4 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components4[T1, T2, T3, T4]) Unpack

func (c Components4[T1, T2, T3, T4]) Unpack() (*T1, *T2, *T3, *T4)

Unpack returns the pointers as separate values.

type Components5

type Components5[T1, T2, T3, T4, T5 any] struct {
	Comp1 *T1
	Comp2 *T2
	Comp3 *T3
	Comp4 *T4
	Comp5 *T5
}

Components5 holds pointers to 5 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components5[T1, T2, T3, T4, T5]) Unpack

func (c Components5[T1, T2, T3, T4, T5]) Unpack() (*T1, *T2, *T3, *T4, *T5)

Unpack returns the pointers as separate values.

type Components6

type Components6[T1, T2, T3, T4, T5, T6 any] struct {
	Comp1 *T1
	Comp2 *T2
	Comp3 *T3
	Comp4 *T4
	Comp5 *T5
	Comp6 *T6
}

Components6 holds pointers to 6 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components6[T1, T2, T3, T4, T5, T6]) Unpack

func (c Components6[T1, T2, T3, T4, T5, T6]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6)

Unpack returns the pointers as separate values.

type Components7

type Components7[T1, T2, T3, T4, T5, T6, T7 any] struct {
	Comp1 *T1
	Comp2 *T2
	Comp3 *T3
	Comp4 *T4
	Comp5 *T5
	Comp6 *T6
	Comp7 *T7
}

Components7 holds pointers to 7 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components7[T1, T2, T3, T4, T5, T6, T7]) Unpack

func (c Components7[T1, T2, T3, T4, T5, T6, T7]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7)

Unpack returns the pointers as separate values.

type Components8

type Components8[T1, T2, T3, T4, T5, T6, T7, T8 any] struct {
	Comp1 *T1
	Comp2 *T2
	Comp3 *T3
	Comp4 *T4
	Comp5 *T5
	Comp6 *T6
	Comp7 *T7
	Comp8 *T8
}

Components8 holds pointers to 8 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components8[T1, T2, T3, T4, T5, T6, T7, T8]) Unpack

func (c Components8[T1, T2, T3, T4, T5, T6, T7, T8]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8)

Unpack returns the pointers as separate values.

type Components9

type Components9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any] struct {
	Comp1 *T1
	Comp2 *T2
	Comp3 *T3
	Comp4 *T4
	Comp5 *T5
	Comp6 *T6
	Comp7 *T7
	Comp8 *T8
	Comp9 *T9
}

Components9 holds pointers to 9 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Unpack

func (c Components9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9)

Unpack returns the pointers as separate values.

type Components10

type Components10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any] struct {
	Comp1  *T1
	Comp2  *T2
	Comp3  *T3
	Comp4  *T4
	Comp5  *T5
	Comp6  *T6
	Comp7  *T7
	Comp8  *T8
	Comp9  *T9
	Comp10 *T10
}

Components10 holds pointers to 10 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Unpack

func (c Components10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9, *T10)

Unpack returns the pointers as separate values.

type Components11

type Components11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any] struct {
	Comp1  *T1
	Comp2  *T2
	Comp3  *T3
	Comp4  *T4
	Comp5  *T5
	Comp6  *T6
	Comp7  *T7
	Comp8  *T8
	Comp9  *T9
	Comp10 *T10
	Comp11 *T11
}

Components11 holds pointers to 11 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Unpack

func (c Components11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9, *T10, *T11)

Unpack returns the pointers as separate values.

type Components12

type Components12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any] struct {
	Comp1  *T1
	Comp2  *T2
	Comp3  *T3
	Comp4  *T4
	Comp5  *T5
	Comp6  *T6
	Comp7  *T7
	Comp8  *T8
	Comp9  *T9
	Comp10 *T10
	Comp11 *T11
	Comp12 *T12
}

Components12 holds pointers to 12 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Unpack

func (c Components12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9, *T10, *T11, *T12)

Unpack returns the pointers as separate values.

type Components13

type Components13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any] struct {
	Comp1  *T1
	Comp2  *T2
	Comp3  *T3
	Comp4  *T4
	Comp5  *T5
	Comp6  *T6
	Comp7  *T7
	Comp8  *T8
	Comp9  *T9
	Comp10 *T10
	Comp11 *T11
	Comp12 *T12
	Comp13 *T13
}

Components13 holds pointers to 13 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Unpack

func (c Components13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9, *T10, *T11, *T12, *T13)

Unpack returns the pointers as separate values.

type Components14

type Components14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any] struct {
	Comp1  *T1
	Comp2  *T2
	Comp3  *T3
	Comp4  *T4
	Comp5  *T5
	Comp6  *T6
	Comp7  *T7
	Comp8  *T8
	Comp9  *T9
	Comp10 *T10
	Comp11 *T11
	Comp12 *T12
	Comp13 *T13
	Comp14 *T14
}

Components14 holds pointers to 14 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Unpack

func (c Components14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9, *T10, *T11, *T12, *T13, *T14)

Unpack returns the pointers as separate values.

type Components15

type Components15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any] struct {
	Comp1  *T1
	Comp2  *T2
	Comp3  *T3
	Comp4  *T4
	Comp5  *T5
	Comp6  *T6
	Comp7  *T7
	Comp8  *T8
	Comp9  *T9
	Comp10 *T10
	Comp11 *T11
	Comp12 *T12
	Comp13 *T13
	Comp14 *T14
	Comp15 *T15
}

Components15 holds pointers to 15 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Unpack

func (c Components15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9, *T10, *T11, *T12, *T13, *T14, *T15)

Unpack returns the pointers as separate values.

type Components16

type Components16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any] struct {
	Comp1  *T1
	Comp2  *T2
	Comp3  *T3
	Comp4  *T4
	Comp5  *T5
	Comp6  *T6
	Comp7  *T7
	Comp8  *T8
	Comp9  *T9
	Comp10 *T10
	Comp11 *T11
	Comp12 *T12
	Comp13 *T13
	Comp14 *T14
	Comp15 *T15
	Comp16 *T16
}

Components16 holds pointers to 16 components, in type-parameter order. It is only returned by value; its fields are only valid as long as the pointers themselves are (see ViewN.Get and ViewN.Each).

func (Components16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Unpack

func (c Components16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Unpack() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9, *T10, *T11, *T12, *T13, *T14, *T15, *T16)

Unpack returns the pointers as separate values.

type Entity

type Entity struct {
	ID         EntityID
	Generation uint32
}

Entity is a handle to one entity in a World. It is a small comparable value: copy it freely, store it in maps, slices and struct fields.

A handle becomes stale once its entity is deleted, even if the slot is later reused for a new entity (the new entity gets a different Generation). The zero Entity{} is never a live handle, so it doubles as "no entity" in struct fields: World.IsAlive(Entity{}) is false, and other World methods panic with "ecs: invalid or stale entity".

func NewEntity1

func NewEntity1[T1 any](w *World, v1 T1) Entity

NewEntity1 creates an entity holding exactly these 1 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity2

func NewEntity2[T1, T2 any](w *World, v1 T1, v2 T2) Entity

NewEntity2 creates an entity holding exactly these 2 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity3

func NewEntity3[T1, T2, T3 any](w *World, v1 T1, v2 T2, v3 T3) Entity

NewEntity3 creates an entity holding exactly these 3 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity4

func NewEntity4[T1, T2, T3, T4 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4) Entity

NewEntity4 creates an entity holding exactly these 4 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity5

func NewEntity5[T1, T2, T3, T4, T5 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5) Entity

NewEntity5 creates an entity holding exactly these 5 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity6

func NewEntity6[T1, T2, T3, T4, T5, T6 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6) Entity

NewEntity6 creates an entity holding exactly these 6 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity7

func NewEntity7[T1, T2, T3, T4, T5, T6, T7 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7) Entity

NewEntity7 creates an entity holding exactly these 7 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity8

func NewEntity8[T1, T2, T3, T4, T5, T6, T7, T8 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8) Entity

NewEntity8 creates an entity holding exactly these 8 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity9

func NewEntity9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9) Entity

NewEntity9 creates an entity holding exactly these 9 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity10

func NewEntity10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10) Entity

NewEntity10 creates an entity holding exactly these 10 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity11

func NewEntity11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11) Entity

NewEntity11 creates an entity holding exactly these 11 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity12

func NewEntity12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12) Entity

NewEntity12 creates an entity holding exactly these 12 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity13

func NewEntity13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13) Entity

NewEntity13 creates an entity holding exactly these 13 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity14

func NewEntity14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14) Entity

NewEntity14 creates an entity holding exactly these 14 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity15

func NewEntity15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14, v15 T15) Entity

NewEntity15 creates an entity holding exactly these 15 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

func NewEntity16

func NewEntity16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any](w *World, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14, v15 T15, v16 T16) Entity

NewEntity16 creates an entity holding exactly these 16 components, inferring the component types from the argument types. Registers each type on first use.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type.

Cost: 0 allocations in steady state.

type EntityID

type EntityID uint32

EntityID is the slot index of an Entity. It is reused after the entity is deleted; Entity.Generation is what tells a stale handle from a live one.

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter narrows which entities a view selects, beyond having all of the view's components. Pass filters to a view constructor:

moving := ecs.NewView2[Position, Velocity](w, ecs.Without[Body]())

A filter is checked once per archetype, when the view's match cache takes the archetype in, so it costs nothing per entity during Each. Make one with Without; the zero Filter makes the view constructor panic with "ecs: zero Filter".

func Without

func Without[T any]() Filter

Without returns a filter that drops every entity that has a T: ViewN.Each skips it and ViewN.Has reports false for it. Get, Set, Remove and NewEntity ignore filters. Without registers T like the other generic functions do.

A view constructor panics with "ecs: component both required and excluded: <type>" if T is also one of its type parameters, and with "ecs: duplicate component: <type>" if two filters exclude the same T.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query is a reusable view over every entity whose archetype contains all of a fixed set of components. Copies of a Query share the same underlying state (the archetype-match cache), so it is cheap to pass around and store; build one per World and iterate it as many times as needed.

The zero Query is not bound to any world; calling Each on it panics.

func (Query) Each

func (q Query) Each() iter.Seq2[Entity, []any]

Each yields every entity currently matching the query and, for each, a []any holding one pointer per requested component, in request order.

Do not retain the []any past the loop body; it is reused between iterations (nested iteration of the same Query gets its own, freshly allocated). Replacing a component's value, or writing through a yielded pointer, is safe during iteration. A structural change (NewEntity, DeleteEntity, or SetComp/RemoveComp that adds or removes a component) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop (the body returning false) is always safe, even right after such a mutation.

Panics with "ecs: not bound to a world" if Query is the zero value.

type View1

type View1[T1 any] struct {
	// contains filtered or unexported fields
}

View1 is a reusable view over entities with these 1 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View1 panics with "ecs: not bound to a world" on every method.

func NewView1

func NewView1[T1 any](w *World, filters ...Filter) View1[T1]

NewView1 returns a view over every entity with all 1 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View1[T1]) Each

func (v View1[T1]) Each() iter.Seq2[Entity, *T1]

Each yields every entity that currently has T1 (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointer, or a Set on an entity that already has T1, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View1 (the same View1 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View1 is the zero value.

func (View1[T1]) Get

func (v View1[T1]) Get(e Entity) *T1

Get returns a pointer to e's live T1.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" if e doesn't currently have it.

Cost: 0 allocations.

func (View1[T1]) Has

func (v View1[T1]) Has(e Entity) bool

Has reports whether e currently has all 1 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View1[T1]) NewEntity

func (v View1[T1]) NewEntity(v1 T1) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View1[T1]) Remove

func (v View1[T1]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View1[T1]) Set

func (v View1[T1]) Set(e Entity, v1 T1)

Set adds or replaces all 1 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View2

type View2[T1, T2 any] struct {
	// contains filtered or unexported fields
}

View2 is a reusable view over entities with these 2 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View2 panics with "ecs: not bound to a world" on every method.

func NewView2

func NewView2[T1, T2 any](w *World, filters ...Filter) View2[T1, T2]

NewView2 returns a view over every entity with all 2 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View2[T1, T2]) Each

func (v View2[T1, T2]) Each() iter.Seq2[Entity, Components2[T1, T2]]

Each yields every entity that currently has all 2 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View2 (the same View2 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View2 is the zero value.

func (View2[T1, T2]) Get

func (v View2[T1, T2]) Get(e Entity) Components2[T1, T2]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View2[T1, T2]) Has

func (v View2[T1, T2]) Has(e Entity) bool

Has reports whether e currently has all 2 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View2[T1, T2]) NewEntity

func (v View2[T1, T2]) NewEntity(v1 T1, v2 T2) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View2[T1, T2]) Remove

func (v View2[T1, T2]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View2[T1, T2]) Set

func (v View2[T1, T2]) Set(e Entity, v1 T1, v2 T2)

Set adds or replaces all 2 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View3

type View3[T1, T2, T3 any] struct {
	// contains filtered or unexported fields
}

View3 is a reusable view over entities with these 3 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View3 panics with "ecs: not bound to a world" on every method.

func NewView3

func NewView3[T1, T2, T3 any](w *World, filters ...Filter) View3[T1, T2, T3]

NewView3 returns a view over every entity with all 3 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View3[T1, T2, T3]) Each

func (v View3[T1, T2, T3]) Each() iter.Seq2[Entity, Components3[T1, T2, T3]]

Each yields every entity that currently has all 3 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View3 (the same View3 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View3 is the zero value.

func (View3[T1, T2, T3]) Get

func (v View3[T1, T2, T3]) Get(e Entity) Components3[T1, T2, T3]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View3[T1, T2, T3]) Has

func (v View3[T1, T2, T3]) Has(e Entity) bool

Has reports whether e currently has all 3 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View3[T1, T2, T3]) NewEntity

func (v View3[T1, T2, T3]) NewEntity(v1 T1, v2 T2, v3 T3) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View3[T1, T2, T3]) Remove

func (v View3[T1, T2, T3]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View3[T1, T2, T3]) Set

func (v View3[T1, T2, T3]) Set(e Entity, v1 T1, v2 T2, v3 T3)

Set adds or replaces all 3 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View4

type View4[T1, T2, T3, T4 any] struct {
	// contains filtered or unexported fields
}

View4 is a reusable view over entities with these 4 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View4 panics with "ecs: not bound to a world" on every method.

func NewView4

func NewView4[T1, T2, T3, T4 any](w *World, filters ...Filter) View4[T1, T2, T3, T4]

NewView4 returns a view over every entity with all 4 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View4[T1, T2, T3, T4]) Each

func (v View4[T1, T2, T3, T4]) Each() iter.Seq2[Entity, Components4[T1, T2, T3, T4]]

Each yields every entity that currently has all 4 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View4 (the same View4 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View4 is the zero value.

func (View4[T1, T2, T3, T4]) Get

func (v View4[T1, T2, T3, T4]) Get(e Entity) Components4[T1, T2, T3, T4]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View4[T1, T2, T3, T4]) Has

func (v View4[T1, T2, T3, T4]) Has(e Entity) bool

Has reports whether e currently has all 4 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View4[T1, T2, T3, T4]) NewEntity

func (v View4[T1, T2, T3, T4]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View4[T1, T2, T3, T4]) Remove

func (v View4[T1, T2, T3, T4]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View4[T1, T2, T3, T4]) Set

func (v View4[T1, T2, T3, T4]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4)

Set adds or replaces all 4 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View5

type View5[T1, T2, T3, T4, T5 any] struct {
	// contains filtered or unexported fields
}

View5 is a reusable view over entities with these 5 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View5 panics with "ecs: not bound to a world" on every method.

func NewView5

func NewView5[T1, T2, T3, T4, T5 any](w *World, filters ...Filter) View5[T1, T2, T3, T4, T5]

NewView5 returns a view over every entity with all 5 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View5[T1, T2, T3, T4, T5]) Each

func (v View5[T1, T2, T3, T4, T5]) Each() iter.Seq2[Entity, Components5[T1, T2, T3, T4, T5]]

Each yields every entity that currently has all 5 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View5 (the same View5 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View5 is the zero value.

func (View5[T1, T2, T3, T4, T5]) Get

func (v View5[T1, T2, T3, T4, T5]) Get(e Entity) Components5[T1, T2, T3, T4, T5]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View5[T1, T2, T3, T4, T5]) Has

func (v View5[T1, T2, T3, T4, T5]) Has(e Entity) bool

Has reports whether e currently has all 5 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View5[T1, T2, T3, T4, T5]) NewEntity

func (v View5[T1, T2, T3, T4, T5]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View5[T1, T2, T3, T4, T5]) Remove

func (v View5[T1, T2, T3, T4, T5]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View5[T1, T2, T3, T4, T5]) Set

func (v View5[T1, T2, T3, T4, T5]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5)

Set adds or replaces all 5 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View6

type View6[T1, T2, T3, T4, T5, T6 any] struct {
	// contains filtered or unexported fields
}

View6 is a reusable view over entities with these 6 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View6 panics with "ecs: not bound to a world" on every method.

func NewView6

func NewView6[T1, T2, T3, T4, T5, T6 any](w *World, filters ...Filter) View6[T1, T2, T3, T4, T5, T6]

NewView6 returns a view over every entity with all 6 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View6[T1, T2, T3, T4, T5, T6]) Each

func (v View6[T1, T2, T3, T4, T5, T6]) Each() iter.Seq2[Entity, Components6[T1, T2, T3, T4, T5, T6]]

Each yields every entity that currently has all 6 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View6 (the same View6 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View6 is the zero value.

func (View6[T1, T2, T3, T4, T5, T6]) Get

func (v View6[T1, T2, T3, T4, T5, T6]) Get(e Entity) Components6[T1, T2, T3, T4, T5, T6]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View6[T1, T2, T3, T4, T5, T6]) Has

func (v View6[T1, T2, T3, T4, T5, T6]) Has(e Entity) bool

Has reports whether e currently has all 6 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View6[T1, T2, T3, T4, T5, T6]) NewEntity

func (v View6[T1, T2, T3, T4, T5, T6]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View6[T1, T2, T3, T4, T5, T6]) Remove

func (v View6[T1, T2, T3, T4, T5, T6]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View6[T1, T2, T3, T4, T5, T6]) Set

func (v View6[T1, T2, T3, T4, T5, T6]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6)

Set adds or replaces all 6 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View7

type View7[T1, T2, T3, T4, T5, T6, T7 any] struct {
	// contains filtered or unexported fields
}

View7 is a reusable view over entities with these 7 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View7 panics with "ecs: not bound to a world" on every method.

func NewView7

func NewView7[T1, T2, T3, T4, T5, T6, T7 any](w *World, filters ...Filter) View7[T1, T2, T3, T4, T5, T6, T7]

NewView7 returns a view over every entity with all 7 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View7[T1, T2, T3, T4, T5, T6, T7]) Each

func (v View7[T1, T2, T3, T4, T5, T6, T7]) Each() iter.Seq2[Entity, Components7[T1, T2, T3, T4, T5, T6, T7]]

Each yields every entity that currently has all 7 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View7 (the same View7 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View7 is the zero value.

func (View7[T1, T2, T3, T4, T5, T6, T7]) Get

func (v View7[T1, T2, T3, T4, T5, T6, T7]) Get(e Entity) Components7[T1, T2, T3, T4, T5, T6, T7]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View7[T1, T2, T3, T4, T5, T6, T7]) Has

func (v View7[T1, T2, T3, T4, T5, T6, T7]) Has(e Entity) bool

Has reports whether e currently has all 7 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View7[T1, T2, T3, T4, T5, T6, T7]) NewEntity

func (v View7[T1, T2, T3, T4, T5, T6, T7]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View7[T1, T2, T3, T4, T5, T6, T7]) Remove

func (v View7[T1, T2, T3, T4, T5, T6, T7]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View7[T1, T2, T3, T4, T5, T6, T7]) Set

func (v View7[T1, T2, T3, T4, T5, T6, T7]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7)

Set adds or replaces all 7 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View8

type View8[T1, T2, T3, T4, T5, T6, T7, T8 any] struct {
	// contains filtered or unexported fields
}

View8 is a reusable view over entities with these 8 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View8 panics with "ecs: not bound to a world" on every method.

func NewView8

func NewView8[T1, T2, T3, T4, T5, T6, T7, T8 any](w *World, filters ...Filter) View8[T1, T2, T3, T4, T5, T6, T7, T8]

NewView8 returns a view over every entity with all 8 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View8[T1, T2, T3, T4, T5, T6, T7, T8]) Each

func (v View8[T1, T2, T3, T4, T5, T6, T7, T8]) Each() iter.Seq2[Entity, Components8[T1, T2, T3, T4, T5, T6, T7, T8]]

Each yields every entity that currently has all 8 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View8 (the same View8 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View8 is the zero value.

func (View8[T1, T2, T3, T4, T5, T6, T7, T8]) Get

func (v View8[T1, T2, T3, T4, T5, T6, T7, T8]) Get(e Entity) Components8[T1, T2, T3, T4, T5, T6, T7, T8]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View8[T1, T2, T3, T4, T5, T6, T7, T8]) Has

func (v View8[T1, T2, T3, T4, T5, T6, T7, T8]) Has(e Entity) bool

Has reports whether e currently has all 8 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View8[T1, T2, T3, T4, T5, T6, T7, T8]) NewEntity

func (v View8[T1, T2, T3, T4, T5, T6, T7, T8]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View8[T1, T2, T3, T4, T5, T6, T7, T8]) Remove

func (v View8[T1, T2, T3, T4, T5, T6, T7, T8]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View8[T1, T2, T3, T4, T5, T6, T7, T8]) Set

func (v View8[T1, T2, T3, T4, T5, T6, T7, T8]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8)

Set adds or replaces all 8 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View9

type View9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any] struct {
	// contains filtered or unexported fields
}

View9 is a reusable view over entities with these 9 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View9 panics with "ecs: not bound to a world" on every method.

func NewView9

func NewView9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](w *World, filters ...Filter) View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]

NewView9 returns a view over every entity with all 9 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Each

func (v View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Each() iter.Seq2[Entity, Components9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

Each yields every entity that currently has all 9 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View9 (the same View9 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View9 is the zero value.

func (View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Get

func (v View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Get(e Entity) Components9[T1, T2, T3, T4, T5, T6, T7, T8, T9]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Has

func (v View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Has(e Entity) bool

Has reports whether e currently has all 9 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) NewEntity

func (v View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Remove

func (v View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Set

func (v View9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9)

Set adds or replaces all 9 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View10

type View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any] struct {
	// contains filtered or unexported fields
}

View10 is a reusable view over entities with these 10 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View10 panics with "ecs: not bound to a world" on every method.

func NewView10

func NewView10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](w *World, filters ...Filter) View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]

NewView10 returns a view over every entity with all 10 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Each

func (v View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Each() iter.Seq2[Entity, Components10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

Each yields every entity that currently has all 10 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View10 (the same View10 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View10 is the zero value.

func (View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Get

func (v View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Get(e Entity) Components10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Has

func (v View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Has(e Entity) bool

Has reports whether e currently has all 10 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) NewEntity

func (v View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Remove

func (v View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Set

func (v View10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10)

Set adds or replaces all 10 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View11

type View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any] struct {
	// contains filtered or unexported fields
}

View11 is a reusable view over entities with these 11 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View11 panics with "ecs: not bound to a world" on every method.

func NewView11

func NewView11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any](w *World, filters ...Filter) View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]

NewView11 returns a view over every entity with all 11 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Each

func (v View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Each() iter.Seq2[Entity, Components11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]]

Each yields every entity that currently has all 11 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View11 (the same View11 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View11 is the zero value.

func (View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Get

func (v View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Get(e Entity) Components11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Has

func (v View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Has(e Entity) bool

Has reports whether e currently has all 11 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) NewEntity

func (v View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Remove

func (v View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Set

func (v View11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11)

Set adds or replaces all 11 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View12

type View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any] struct {
	// contains filtered or unexported fields
}

View12 is a reusable view over entities with these 12 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View12 panics with "ecs: not bound to a world" on every method.

func NewView12

func NewView12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any](w *World, filters ...Filter) View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]

NewView12 returns a view over every entity with all 12 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Each

func (v View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Each() iter.Seq2[Entity, Components12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]]

Each yields every entity that currently has all 12 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View12 (the same View12 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View12 is the zero value.

func (View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Get

func (v View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Get(e Entity) Components12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Has

func (v View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Has(e Entity) bool

Has reports whether e currently has all 12 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) NewEntity

func (v View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Remove

func (v View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Set

func (v View12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12)

Set adds or replaces all 12 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View13

type View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any] struct {
	// contains filtered or unexported fields
}

View13 is a reusable view over entities with these 13 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View13 panics with "ecs: not bound to a world" on every method.

func NewView13

func NewView13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any](w *World, filters ...Filter) View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]

NewView13 returns a view over every entity with all 13 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Each

func (v View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Each() iter.Seq2[Entity, Components13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]]

Each yields every entity that currently has all 13 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View13 (the same View13 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View13 is the zero value.

func (View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Get

func (v View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Get(e Entity) Components13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Has

func (v View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Has(e Entity) bool

Has reports whether e currently has all 13 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) NewEntity

func (v View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Remove

func (v View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Set

func (v View13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13)

Set adds or replaces all 13 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View14

type View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any] struct {
	// contains filtered or unexported fields
}

View14 is a reusable view over entities with these 14 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View14 panics with "ecs: not bound to a world" on every method.

func NewView14

func NewView14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any](w *World, filters ...Filter) View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]

NewView14 returns a view over every entity with all 14 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Each

func (v View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Each() iter.Seq2[Entity, Components14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]]

Each yields every entity that currently has all 14 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View14 (the same View14 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View14 is the zero value.

func (View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Get

func (v View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Get(e Entity) Components14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Has

func (v View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Has(e Entity) bool

Has reports whether e currently has all 14 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) NewEntity

func (v View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Remove

func (v View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Set

func (v View14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14)

Set adds or replaces all 14 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View15

type View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any] struct {
	// contains filtered or unexported fields
}

View15 is a reusable view over entities with these 15 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View15 panics with "ecs: not bound to a world" on every method.

func NewView15

func NewView15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any](w *World, filters ...Filter) View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]

NewView15 returns a view over every entity with all 15 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Each

func (v View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Each() iter.Seq2[Entity, Components15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]]

Each yields every entity that currently has all 15 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View15 (the same View15 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View15 is the zero value.

func (View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Get

func (v View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Get(e Entity) Components15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Has

func (v View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Has(e Entity) bool

Has reports whether e currently has all 15 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) NewEntity

func (v View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14, v15 T15) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Remove

func (v View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Set

func (v View15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14, v15 T15)

Set adds or replaces all 15 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type View16

type View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any] struct {
	// contains filtered or unexported fields
}

View16 is a reusable view over entities with these 16 fixed component types. It is a small value holding a pointer to shared state, so copies share it; store and reuse one instead of constructing it per call. The zero View16 panics with "ecs: not bound to a world" on every method.

func NewView16

func NewView16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any](w *World, filters ...Filter) View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]

NewView16 returns a view over every entity with all 16 of these component types. It registers and resolves the component IDs now; the archetype it spawns into (ViewN.NewEntity) and the archetype-match cache (ViewN.Each) are each resolved lazily, on first use. Filters such as Without narrow which entities Each and Has select; they are checked once per archetype, not per entity.

Panics with "ecs: duplicate component: <type>" if two type parameters are the same type or two filters exclude the same type, with "ecs: component both required and excluded: <type>" if a filter excludes one of the type parameters, and with "ecs: zero Filter" for a Filter not made by Without.

func (View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Each

func (v View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Each() iter.Seq2[Entity, Components16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]]

Each yields every entity that currently has all 16 components (entities with additional components also match, unless a filter excludes one of them).

Writing through the yielded pointers, or a Set on an entity that already has every component, is safe during iteration. A structural change (creating or deleting an entity, or an add/remove) panics with "ecs: query invalidated by world mutation" once the loop body that caused it returns true to continue; breaking out of the loop is always safe.

Cost: 0 allocations per loop in the common case. A nested iteration of the same View16 (the same View16 used inside its own Each loop) allocates once: the per-archetype column buffer below is already in use by the outer call.

Panics with "ecs: not bound to a world" if View16 is the zero value.

func (View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Get

func (v View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Get(e Entity) Components16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]

Get returns pointers to e's live components, in type-parameter order.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: entity does not have component: <type>" on the first one e doesn't currently have.

Cost: 0 allocations.

func (View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Has

func (v View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Has(e Entity) bool

Has reports whether e currently has all 16 components and none that the view's filters exclude, which is whether Each would yield it.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) NewEntity

func (v View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) NewEntity(v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14, v15 T15, v16 T16) Entity

NewEntity creates an entity with exactly this view's components, using the archetype resolved on the view's first NewEntity call.

Cost: 0 allocations in steady state.

func (View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Remove

func (v View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Remove(e Entity)

Remove removes whichever of this view's components e currently has, in one archetype move; a no-op, leaving the revision unchanged, if e has none of them.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

func (View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Set

func (v View16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) Set(e Entity, v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, v10 T10, v11 T11, v12 T12, v13 T13, v14 T14, v15 T15, v16 T16)

Set adds or replaces all 16 components. In place, with the revision unchanged, when e already has every one of them; otherwise e moves to a new archetype exactly once and the revision bumps once.

Panics with "ecs: invalid or stale entity: <e>" if e is stale.

Cost: 0 allocations, in place and when moving.

type World

type World struct {
	// contains filtered or unexported fields
}

World owns all entities, archetypes and resources for one simulation. Worlds are independent from each other; they share only the process-global component registry (see RegisterComp). A World is not safe for concurrent use.

func NewWorld

func NewWorld() *World

NewWorld returns an empty World.

func (*World) DeleteEntity

func (w *World) DeleteEntity(e Entity)

DeleteEntity removes e and invalidates every handle to it, including e itself.

Panics with "ecs: invalid or stale entity: <e>" if e is already stale.

func (*World) GetComp

func (w *World) GetComp(e Entity, id ComponentID) any

GetComp returns a pointer to e's live component id, as *T boxed in any.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, with "ecs: component not registered: ComponentID(<id>)" if id is unknown, and with "ecs: entity does not have component: <type>" if e doesn't currently have it.

Cost: 0 allocations. The pointer is valid until the next structural change to e's archetype (any SetComp that adds a component, RemoveComp, NewEntity or DeleteEntity); re-fetch it after one.

Example
package main

import (
	"fmt"

	"github.com/weakpixel/ecs"
)

type (
	Position struct{ X, Y int }
	Velocity struct{ X, Y int }
)

func main() {
	world := ecs.NewWorld()
	posID := ecs.RegisterComp[Position]()
	velID := ecs.RegisterComp[Velocity]()

	e := world.NewEntity(Position{X: 1, Y: 2}, Velocity{X: 3, Y: 4})

	pos := world.GetComp(e, posID).(*Position)
	pos.X = 99 // writes to the world's storage

	if v := world.GetCompOrNil(e, velID); v != nil {
		v.(*Velocity).X = 1
	}

	world.SetComp(e, Velocity{X: 10, Y: 20}, Position{X: 4, Y: 5})
	world.RemoveComp(e, velID)

	fmt.Println(world.GetComp(e, posID).(*Position))
	fmt.Println(world.HasComp(e, velID))
}
Output:
&{4 5}
false

func (*World) GetCompOrNil

func (w *World) GetCompOrNil(e Entity, id ComponentID) any

GetCompOrNil is GetComp but returns a literal untyped nil instead of panicking when e doesn't currently have the component. It still panics on a stale e or an unregistered id.

Cost: 0 allocations.

func (*World) HasComp

func (w *World) HasComp(e Entity, id ComponentID) bool

HasComp reports whether e currently has component id.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: component not registered: ComponentID(<id>)" if id is unknown.

func (*World) IsAlive

func (w *World) IsAlive(e Entity) bool

IsAlive reports whether e is a current live handle. It never panics; the zero Entity{} and any stale or out-of-range handle report false.

func (*World) NewEntity

func (w *World) NewEntity(values ...any) Entity

NewEntity creates an entity holding values, stored inline in its archetype. Each value's dynamic type selects the component; order doesn't matter.

Panics with "ecs: component must be a non-pointer struct: <type>" for a pointer or non-struct value, "ecs: component not registered: <type>" for a struct type nothing has registered yet, and "ecs: duplicate component: <type>" if two values share a type. Validation happens before any entity is created.

Example
package main

import (
	"fmt"

	"github.com/weakpixel/ecs"
)

type (
	Position struct{ X, Y int }
	Velocity struct{ X, Y int }
)

func main() {
	ecs.RegisterComp[Position]()
	ecs.RegisterComp[Velocity]()

	world := ecs.NewWorld()
	e := world.NewEntity(Position{X: 1, Y: 2}, Velocity{X: 3, Y: 4})
	world.DeleteEntity(e)
	fmt.Println(world.IsAlive(e))
}
Output:
false

func (*World) Query

func (w *World) Query(ids ...ComponentID) Query

Query returns a Query over every entity whose archetype contains all of ids. Order matters: it is the order Each's []any slice uses. Query() with no ids matches every archetype.

Panics with "ecs: component not registered: ComponentID(<id>)" if any id is unknown, and with "ecs: duplicate component: <type>" if the same id is given twice.

func (*World) RemoveComp

func (w *World) RemoveComp(e Entity, ids ...ComponentID)

RemoveComp removes components from e; ids it doesn't have are ignored, and repeating an id is tolerated (unlike SetComp/NewEntity, this is not a duplicate-component panic). Removing nothing, because ids is empty or none of it is present, is a no-op and leaves the revision unchanged.

Panics with "ecs: invalid or stale entity: <e>" if e is stale, and with "ecs: component not registered: ComponentID(<id>)" for an unknown id.

Removing anything moves e to a new archetype exactly once; pointers GetComp previously returned for e are invalidated.

func (*World) SetComp

func (w *World) SetComp(e Entity, values ...any)

SetComp adds or replaces components on e, choosing the component by each value's dynamic type. A component e already has is replaced; others are added. An empty call is a no-op.

Panics with "ecs: invalid or stale entity: <e>" if e is stale (checked first, even for an empty call), "ecs: component must be a non-pointer struct: <type>" for a pointer or non-struct value, "ecs: component not registered: <type>" for an unregistered struct type, and "ecs: duplicate component: <type>" if two values share a type. Everything is validated before any mutation; values is never modified.

Replacing every given value in place (e already has all of them) leaves the revision unchanged. Otherwise e moves to a new archetype exactly once, however many components are added, and the revision is bumped once. A move invalidates pointers GetComp previously returned for e.

Directories

Path Synopsis
internal
entities
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).
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).
gen command
Command gen generates the arity-1..16 generic API family (ComponentsN, NewEntityN, NewViewN/ViewN) into zz_gen_generic-api.go at the module root, plus a round-trip smoke test per arity into zz_gen_generic-api_test.go.
Command gen generates the arity-1..16 generic API family (ComponentsN, NewEntityN, NewViewN/ViewN) into zz_gen_generic-api.go at the module root, plus a round-trip smoke test per arity into zz_gen_generic-api_test.go.
registry
Package registry maps component types to dense IDs and keeps, per component, the reflect.Type and a column factory captured at registration.
Package registry maps component types to dense IDs and keeps, per component, the reflect.Type and a column factory captured at registration.
storage
Package storage holds the archetype tables behind package ecs: typed component columns, archetypes (rows of entities that share one component set) and an append-only index of archetypes with cached add and remove edges.
Package storage holds the archetype tables behind package ecs: typed component columns, archetypes (rows of entities that share one component set) and an append-only index of archetypes with cached add and remove edges.
Package system runs game logic ("systems") against an ecs.World.
Package system runs game logic ("systems") against an ecs.World.

Jump to

Keyboard shortcuts

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