ecs

package
v0.0.0-...-3a520fb Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ecs provides the core API of Ark, an Entity Component System (ECS) for Go.

See the top-level module github.com/mlange-42/ark for an overview.

🕮 Also read Ark's User Guide and take a look at the examples!

Outline

ECS Manipulations

This section gives an overview on how to achieve typical ECS operations in Ark.

Access data:

Manipulate a single Entity:

Manipulate entities in batches:

Build tags

Ark provides two build tags:

  • ark_tiny: Reduces the maximum number of components to 64, for faster mask-related operations and smaller archetype memory footprint.
  • ark_debug: Improves error messages on incorrect use, at the cost of performance. Use this if you get panics from queries or maps.

When building your application, use them like this:

go build -tags ark_tiny .
go build -tags ark_debug .
go build -tags ark_tiny,ark_debug .

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetResource

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

GetResource returns a pointer to the given resource type in the world. Returns nil if there is no such resource.

Uses reflection. For more efficient repeated access, use Resource. Once created, it is more than 20 times faster than the GetResource function.

See also AddResource.

Example
world := ecs.NewWorld()

gridResource := NewGrid(100, 100)
ecs.AddResource(&world, &gridResource)

grid := ecs.GetResource[Grid](&world)
entity := grid.Get(13, 42)
_ = entity

func ResourceType

func ResourceType(w *World, id ResID) (reflect.Type, bool)

ResourceType returns the reflect.Type for a resource ResID, and whether the ID is assigned.

Types

type Batch

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

Batch is like a filter for batch processing of entities. Create it using Filter2.Batch etc.

⚠️ This should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter2.Batch with different relationship targets may modify stored instances.

type Comp

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

Comp is a helper to pass component types to functions and methods. Use function C to create one.

func C

func C[T any]() Comp

C creates a Comp instance for the given type.

func (Comp) Type

func (c Comp) Type() reflect.Type

Type returns the reflect.Type of the component.

type CompInfo

type CompInfo struct {
	Type       reflect.Type
	ID         ID
	IsRelation bool
}

CompInfo provides information about a registered component. Returned by ComponentInfo.

func ComponentInfo

func ComponentInfo(w *World, id ID) (CompInfo, bool)

ComponentInfo returns the CompInfo for a component ID, and whether the ID is assigned.

type Entity

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

Entity is an identifier for entities.

Can be stored safely in components, resources or elsewhere. For stored entities, it may be necessary to check their alive status with World.Alive.

⚠️ Always store entities by value, never by pointer!

In Ark, entities are returned to a pool when they are removed from the world. These entities can be recycled, with the same ID (Entity.ID), but an incremented generation (Entity.Gen). This allows to determine whether an entity hold by the user is still alive, despite it was potentially recycled.

func (Entity) Gen

func (e Entity) Gen() uint32

Gen returns the entity's generation, primarily for debugging purposes.

func (Entity) ID

func (e Entity) ID() uint32

ID returns the entity's ID, primarily for debugging purposes.

func (Entity) IsZero

func (e Entity) IsZero() bool

IsZero returns whether this entity is the reserved zero entity.

func (Entity) MarshalJSON

func (e Entity) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of the entity, for serialization purposes.

The JSON representation of an entity is a two-element array of entity ID and generation.

func (*Entity) UnmarshalJSON

func (e *Entity) UnmarshalJSON(data []byte) error

UnmarshalJSON into an entity.

For serialization purposes only. Do not use this to create entities!

type EntityDump

type EntityDump struct {
	Entities  []Entity // Entities in the World's entity pool.
	Alive     []uint32 // IDs of all alive entities in query iteration order.
	Next      uint32   // The next free entity of the World's entity pool.
	Available uint32   // The number of allocated and available entities in the World's entity pool.
}

EntityDump is a dump of the entire entity data of the world.

See [World.DumpEntities] and [World.LoadEntities].

type Exchange1

type Exchange1[A any] struct {
	// contains filtered or unexported fields
}

Exchange1 allows to exchange components of entities. It adds the given components. Use Exchange1.Removes to set components to be removed.

Instances should be created during initialization and stored, e.g. in systems.

See Exchange2 for a usage example.

func NewExchange1

func NewExchange1[A any](world *World) *Exchange1[A]

NewExchange1 creates an Exchange1.

func (*Exchange1[A]) Add

func (ex *Exchange1[A]) Add(entity Entity, a *A, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange1[A]) AddBatch

func (ex *Exchange1[A]) AddBatch(batch *Batch, a *A, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange1[A]) AddBatchFn

func (ex *Exchange1[A]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange1[A]) AddFn

func (ex *Exchange1[A]) AddFn(entity Entity, fn func(a *A), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange1[A]) Exchange

func (ex *Exchange1[A]) Exchange(entity Entity, a *A, rel ...Relation)

Exchange performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange1.Removes.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange1[A]) ExchangeBatch

func (ex *Exchange1[A]) ExchangeBatch(batch *Batch, a *A, rel ...Relation)

ExchangeBatch performs the exchange on all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange1[A]) ExchangeBatchFn

func (ex *Exchange1[A]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A), rel ...Relation)

ExchangeBatchFn performs the exchange on all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange1[A]) ExchangeFn

func (ex *Exchange1[A]) ExchangeFn(entity Entity, fn func(a *A), rel ...Relation)

ExchangeFn performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange1.Removes. It runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange1[A]) New

func (_ *Exchange1[A]) New(world *World) *Exchange1[A]

New creates a new Exchange1. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Exchange2.New for an example.

func (*Exchange1[A]) Remove

func (ex *Exchange1[A]) Remove(entity Entity)

Remove the components previously specified with Exchange1.Removes from the given entity.

func (*Exchange1[A]) RemoveBatch

func (ex *Exchange1[A]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the components previously specified with Exchange1.Removes from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Exchange1[A]) Removes

func (ex *Exchange1[A]) Removes(components ...Comp) *Exchange1[A]

Removes sets the components that this Exchange1 removes. Can be called multiple times in chains, or once with multiple arguments.

type Exchange2

type Exchange2[A any, B any] struct {
	// contains filtered or unexported fields
}

Exchange2 allows to exchange components of entities. It adds the given components. Use Exchange2.Removes to set components to be removed.

Instances should be created during initialization and stored, e.g. in systems.

Example
world := ecs.NewWorld()

// Create a component mapper.
mapper := ecs.NewMap[Altitude](&world)

// Create an exchange helper.
// Adds Position and Velocity, removes Altitude.
exchange := ecs.NewExchange2[Position, Velocity](&world).
	Removes(ecs.C[Altitude]())

// Create an entity with an Altitude component.
entity := mapper.NewEntity(&Altitude{Z: 10_000})

// Remove Altitude and add Position and Velocity.
exchange.Exchange(entity, &Position{X: 100, Y: 100}, &Velocity{X: 1, Y: -1})

// Create another entity.
entity = mapper.NewEntity(&Altitude{Z: 10_000})

// Remove Altitude.
exchange.Remove(entity)

// Add Position and Velocity.
exchange.Add(entity, &Position{X: 100, Y: 100}, &Velocity{X: 1, Y: -1})

func NewExchange2

func NewExchange2[A any, B any](world *World) *Exchange2[A, B]

NewExchange2 creates an Exchange2.

func (*Exchange2[A, B]) Add

func (ex *Exchange2[A, B]) Add(entity Entity, a *A, b *B, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange2[A, B]) AddBatch

func (ex *Exchange2[A, B]) AddBatch(batch *Batch, a *A, b *B, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange2[A, B]) AddBatchFn

func (ex *Exchange2[A, B]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange2[A, B]) AddFn

func (ex *Exchange2[A, B]) AddFn(entity Entity, fn func(a *A, b *B), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange2[A, B]) Exchange

func (ex *Exchange2[A, B]) Exchange(entity Entity, a *A, b *B, rel ...Relation)

Exchange performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange2.Removes.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange2[A, B]) ExchangeBatch

func (ex *Exchange2[A, B]) ExchangeBatch(batch *Batch, a *A, b *B, rel ...Relation)

ExchangeBatch performs the exchange on all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange2[A, B]) ExchangeBatchFn

func (ex *Exchange2[A, B]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), rel ...Relation)

ExchangeBatchFn performs the exchange on all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange2[A, B]) ExchangeFn

func (ex *Exchange2[A, B]) ExchangeFn(entity Entity, fn func(a *A, b *B), rel ...Relation)

ExchangeFn performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange2.Removes. It runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange2[A, B]) New

func (_ *Exchange2[A, B]) New(world *World) *Exchange2[A, B]

New creates a new Exchange2. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

Example
world := ecs.NewWorld()

// Declare the exchange helper, e.g. in your system struct.
var exchange *ecs.Exchange2[Position, Velocity]

// Construct the exchange helper, avoiding repeated listing of generics.
exchange = exchange.New(&world).Removes(ecs.C[Altitude]())

func (*Exchange2[A, B]) Remove

func (ex *Exchange2[A, B]) Remove(entity Entity)

Remove the components previously specified with Exchange2.Removes from the given entity.

func (*Exchange2[A, B]) RemoveBatch

func (ex *Exchange2[A, B]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the components previously specified with Exchange2.Removes from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Exchange2[A, B]) Removes

func (ex *Exchange2[A, B]) Removes(components ...Comp) *Exchange2[A, B]

Removes sets the components that this Exchange2 removes. Can be called multiple times in chains, or once with multiple arguments.

type Exchange3

type Exchange3[A any, B any, C any] struct {
	// contains filtered or unexported fields
}

Exchange3 allows to exchange components of entities. It adds the given components. Use Exchange3.Removes to set components to be removed.

Instances should be created during initialization and stored, e.g. in systems.

See Exchange2 for a usage example.

func NewExchange3

func NewExchange3[A any, B any, C any](world *World) *Exchange3[A, B, C]

NewExchange3 creates an Exchange3.

func (*Exchange3[A, B, C]) Add

func (ex *Exchange3[A, B, C]) Add(entity Entity, a *A, b *B, c *C, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange3[A, B, C]) AddBatch

func (ex *Exchange3[A, B, C]) AddBatch(batch *Batch, a *A, b *B, c *C, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange3[A, B, C]) AddBatchFn

func (ex *Exchange3[A, B, C]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange3[A, B, C]) AddFn

func (ex *Exchange3[A, B, C]) AddFn(entity Entity, fn func(a *A, b *B, c *C), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange3[A, B, C]) Exchange

func (ex *Exchange3[A, B, C]) Exchange(entity Entity, a *A, b *B, c *C, rel ...Relation)

Exchange performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange3.Removes.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange3[A, B, C]) ExchangeBatch

func (ex *Exchange3[A, B, C]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, rel ...Relation)

ExchangeBatch performs the exchange on all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange3[A, B, C]) ExchangeBatchFn

func (ex *Exchange3[A, B, C]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), rel ...Relation)

ExchangeBatchFn performs the exchange on all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange3[A, B, C]) ExchangeFn

func (ex *Exchange3[A, B, C]) ExchangeFn(entity Entity, fn func(a *A, b *B, c *C), rel ...Relation)

ExchangeFn performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange3.Removes. It runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange3[A, B, C]) New

func (_ *Exchange3[A, B, C]) New(world *World) *Exchange3[A, B, C]

New creates a new Exchange3. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Exchange2.New for an example.

func (*Exchange3[A, B, C]) Remove

func (ex *Exchange3[A, B, C]) Remove(entity Entity)

Remove the components previously specified with Exchange3.Removes from the given entity.

func (*Exchange3[A, B, C]) RemoveBatch

func (ex *Exchange3[A, B, C]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the components previously specified with Exchange3.Removes from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Exchange3[A, B, C]) Removes

func (ex *Exchange3[A, B, C]) Removes(components ...Comp) *Exchange3[A, B, C]

Removes sets the components that this Exchange3 removes. Can be called multiple times in chains, or once with multiple arguments.

type Exchange4

type Exchange4[A any, B any, C any, D any] struct {
	// contains filtered or unexported fields
}

Exchange4 allows to exchange components of entities. It adds the given components. Use Exchange4.Removes to set components to be removed.

Instances should be created during initialization and stored, e.g. in systems.

See Exchange2 for a usage example.

func NewExchange4

func NewExchange4[A any, B any, C any, D any](world *World) *Exchange4[A, B, C, D]

NewExchange4 creates an Exchange4.

func (*Exchange4[A, B, C, D]) Add

func (ex *Exchange4[A, B, C, D]) Add(entity Entity, a *A, b *B, c *C, d *D, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange4[A, B, C, D]) AddBatch

func (ex *Exchange4[A, B, C, D]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange4[A, B, C, D]) AddBatchFn

func (ex *Exchange4[A, B, C, D]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange4[A, B, C, D]) AddFn

func (ex *Exchange4[A, B, C, D]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange4[A, B, C, D]) Exchange

func (ex *Exchange4[A, B, C, D]) Exchange(entity Entity, a *A, b *B, c *C, d *D, rel ...Relation)

Exchange performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange4.Removes.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange4[A, B, C, D]) ExchangeBatch

func (ex *Exchange4[A, B, C, D]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, rel ...Relation)

ExchangeBatch performs the exchange on all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange4[A, B, C, D]) ExchangeBatchFn

func (ex *Exchange4[A, B, C, D]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...Relation)

ExchangeBatchFn performs the exchange on all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange4[A, B, C, D]) ExchangeFn

func (ex *Exchange4[A, B, C, D]) ExchangeFn(entity Entity, fn func(a *A, b *B, c *C, d *D), rel ...Relation)

ExchangeFn performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange4.Removes. It runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange4[A, B, C, D]) New

func (_ *Exchange4[A, B, C, D]) New(world *World) *Exchange4[A, B, C, D]

New creates a new Exchange4. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Exchange2.New for an example.

func (*Exchange4[A, B, C, D]) Remove

func (ex *Exchange4[A, B, C, D]) Remove(entity Entity)

Remove the components previously specified with Exchange4.Removes from the given entity.

func (*Exchange4[A, B, C, D]) RemoveBatch

func (ex *Exchange4[A, B, C, D]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the components previously specified with Exchange4.Removes from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Exchange4[A, B, C, D]) Removes

func (ex *Exchange4[A, B, C, D]) Removes(components ...Comp) *Exchange4[A, B, C, D]

Removes sets the components that this Exchange4 removes. Can be called multiple times in chains, or once with multiple arguments.

type Exchange5

type Exchange5[A any, B any, C any, D any, E any] struct {
	// contains filtered or unexported fields
}

Exchange5 allows to exchange components of entities. It adds the given components. Use Exchange5.Removes to set components to be removed.

Instances should be created during initialization and stored, e.g. in systems.

See Exchange2 for a usage example.

func NewExchange5

func NewExchange5[A any, B any, C any, D any, E any](world *World) *Exchange5[A, B, C, D, E]

NewExchange5 creates an Exchange5.

func (*Exchange5[A, B, C, D, E]) Add

func (ex *Exchange5[A, B, C, D, E]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange5[A, B, C, D, E]) AddBatch

func (ex *Exchange5[A, B, C, D, E]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange5[A, B, C, D, E]) AddBatchFn

func (ex *Exchange5[A, B, C, D, E]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange5[A, B, C, D, E]) AddFn

func (ex *Exchange5[A, B, C, D, E]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange5[A, B, C, D, E]) Exchange

func (ex *Exchange5[A, B, C, D, E]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...Relation)

Exchange performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange5.Removes.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange5[A, B, C, D, E]) ExchangeBatch

func (ex *Exchange5[A, B, C, D, E]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...Relation)

ExchangeBatch performs the exchange on all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange5[A, B, C, D, E]) ExchangeBatchFn

func (ex *Exchange5[A, B, C, D, E]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E), rel ...Relation)

ExchangeBatchFn performs the exchange on all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange5[A, B, C, D, E]) ExchangeFn

func (ex *Exchange5[A, B, C, D, E]) ExchangeFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E), rel ...Relation)

ExchangeFn performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange5.Removes. It runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange5[A, B, C, D, E]) New

func (_ *Exchange5[A, B, C, D, E]) New(world *World) *Exchange5[A, B, C, D, E]

New creates a new Exchange5. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Exchange2.New for an example.

func (*Exchange5[A, B, C, D, E]) Remove

func (ex *Exchange5[A, B, C, D, E]) Remove(entity Entity)

Remove the components previously specified with Exchange5.Removes from the given entity.

func (*Exchange5[A, B, C, D, E]) RemoveBatch

func (ex *Exchange5[A, B, C, D, E]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the components previously specified with Exchange5.Removes from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Exchange5[A, B, C, D, E]) Removes

func (ex *Exchange5[A, B, C, D, E]) Removes(components ...Comp) *Exchange5[A, B, C, D, E]

Removes sets the components that this Exchange5 removes. Can be called multiple times in chains, or once with multiple arguments.

type Exchange6

type Exchange6[A any, B any, C any, D any, E any, F any] struct {
	// contains filtered or unexported fields
}

Exchange6 allows to exchange components of entities. It adds the given components. Use Exchange6.Removes to set components to be removed.

Instances should be created during initialization and stored, e.g. in systems.

See Exchange2 for a usage example.

func NewExchange6

func NewExchange6[A any, B any, C any, D any, E any, F any](world *World) *Exchange6[A, B, C, D, E, F]

NewExchange6 creates an Exchange6.

func (*Exchange6[A, B, C, D, E, F]) Add

func (ex *Exchange6[A, B, C, D, E, F]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange6[A, B, C, D, E, F]) AddBatch

func (ex *Exchange6[A, B, C, D, E, F]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange6[A, B, C, D, E, F]) AddBatchFn

func (ex *Exchange6[A, B, C, D, E, F]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange6[A, B, C, D, E, F]) AddFn

func (ex *Exchange6[A, B, C, D, E, F]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange6[A, B, C, D, E, F]) Exchange

func (ex *Exchange6[A, B, C, D, E, F]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation)

Exchange performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange6.Removes.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange6[A, B, C, D, E, F]) ExchangeBatch

func (ex *Exchange6[A, B, C, D, E, F]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation)

ExchangeBatch performs the exchange on all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange6[A, B, C, D, E, F]) ExchangeBatchFn

func (ex *Exchange6[A, B, C, D, E, F]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation)

ExchangeBatchFn performs the exchange on all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange6[A, B, C, D, E, F]) ExchangeFn

func (ex *Exchange6[A, B, C, D, E, F]) ExchangeFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation)

ExchangeFn performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange6.Removes. It runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange6[A, B, C, D, E, F]) New

func (_ *Exchange6[A, B, C, D, E, F]) New(world *World) *Exchange6[A, B, C, D, E, F]

New creates a new Exchange6. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Exchange2.New for an example.

func (*Exchange6[A, B, C, D, E, F]) Remove

func (ex *Exchange6[A, B, C, D, E, F]) Remove(entity Entity)

Remove the components previously specified with Exchange6.Removes from the given entity.

func (*Exchange6[A, B, C, D, E, F]) RemoveBatch

func (ex *Exchange6[A, B, C, D, E, F]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the components previously specified with Exchange6.Removes from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Exchange6[A, B, C, D, E, F]) Removes

func (ex *Exchange6[A, B, C, D, E, F]) Removes(components ...Comp) *Exchange6[A, B, C, D, E, F]

Removes sets the components that this Exchange6 removes. Can be called multiple times in chains, or once with multiple arguments.

type Exchange7

type Exchange7[A any, B any, C any, D any, E any, F any, G any] struct {
	// contains filtered or unexported fields
}

Exchange7 allows to exchange components of entities. It adds the given components. Use Exchange7.Removes to set components to be removed.

Instances should be created during initialization and stored, e.g. in systems.

See Exchange2 for a usage example.

func NewExchange7

func NewExchange7[A any, B any, C any, D any, E any, F any, G any](world *World) *Exchange7[A, B, C, D, E, F, G]

NewExchange7 creates an Exchange7.

func (*Exchange7[A, B, C, D, E, F, G]) Add

func (ex *Exchange7[A, B, C, D, E, F, G]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange7[A, B, C, D, E, F, G]) AddBatch

func (ex *Exchange7[A, B, C, D, E, F, G]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange7[A, B, C, D, E, F, G]) AddBatchFn

func (ex *Exchange7[A, B, C, D, E, F, G]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange7[A, B, C, D, E, F, G]) AddFn

func (ex *Exchange7[A, B, C, D, E, F, G]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange7[A, B, C, D, E, F, G]) Exchange

func (ex *Exchange7[A, B, C, D, E, F, G]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation)

Exchange performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange7.Removes.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange7[A, B, C, D, E, F, G]) ExchangeBatch

func (ex *Exchange7[A, B, C, D, E, F, G]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation)

ExchangeBatch performs the exchange on all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange7[A, B, C, D, E, F, G]) ExchangeBatchFn

func (ex *Exchange7[A, B, C, D, E, F, G]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation)

ExchangeBatchFn performs the exchange on all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange7[A, B, C, D, E, F, G]) ExchangeFn

func (ex *Exchange7[A, B, C, D, E, F, G]) ExchangeFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation)

ExchangeFn performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange7.Removes. It runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange7[A, B, C, D, E, F, G]) New

func (_ *Exchange7[A, B, C, D, E, F, G]) New(world *World) *Exchange7[A, B, C, D, E, F, G]

New creates a new Exchange7. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Exchange2.New for an example.

func (*Exchange7[A, B, C, D, E, F, G]) Remove

func (ex *Exchange7[A, B, C, D, E, F, G]) Remove(entity Entity)

Remove the components previously specified with Exchange7.Removes from the given entity.

func (*Exchange7[A, B, C, D, E, F, G]) RemoveBatch

func (ex *Exchange7[A, B, C, D, E, F, G]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the components previously specified with Exchange7.Removes from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Exchange7[A, B, C, D, E, F, G]) Removes

func (ex *Exchange7[A, B, C, D, E, F, G]) Removes(components ...Comp) *Exchange7[A, B, C, D, E, F, G]

Removes sets the components that this Exchange7 removes. Can be called multiple times in chains, or once with multiple arguments.

type Exchange8

type Exchange8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
	// contains filtered or unexported fields
}

Exchange8 allows to exchange components of entities. It adds the given components. Use Exchange8.Removes to set components to be removed.

Instances should be created during initialization and stored, e.g. in systems.

See Exchange2 for a usage example.

func NewExchange8

func NewExchange8[A any, B any, C any, D any, E any, F any, G any, H any](world *World) *Exchange8[A, B, C, D, E, F, G, H]

NewExchange8 creates an Exchange8.

func (*Exchange8[A, B, C, D, E, F, G, H]) Add

func (ex *Exchange8[A, B, C, D, E, F, G, H]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange8[A, B, C, D, E, F, G, H]) AddBatch

func (ex *Exchange8[A, B, C, D, E, F, G, H]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange8[A, B, C, D, E, F, G, H]) AddBatchFn

func (ex *Exchange8[A, B, C, D, E, F, G, H]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange8[A, B, C, D, E, F, G, H]) AddFn

func (ex *Exchange8[A, B, C, D, E, F, G, H]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange8[A, B, C, D, E, F, G, H]) Exchange

func (ex *Exchange8[A, B, C, D, E, F, G, H]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation)

Exchange performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange8.Removes.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange8[A, B, C, D, E, F, G, H]) ExchangeBatch

func (ex *Exchange8[A, B, C, D, E, F, G, H]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation)

ExchangeBatch performs the exchange on all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Exchange8[A, B, C, D, E, F, G, H]) ExchangeBatchFn

func (ex *Exchange8[A, B, C, D, E, F, G, H]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation)

ExchangeBatchFn performs the exchange on all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange8[A, B, C, D, E, F, G, H]) ExchangeFn

func (ex *Exchange8[A, B, C, D, E, F, G, H]) ExchangeFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation)

ExchangeFn performs the exchange on the given entity, adding the provided components and removing those previously specified with Exchange8.Removes. It runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Exchange8[A, B, C, D, E, F, G, H]) New

func (_ *Exchange8[A, B, C, D, E, F, G, H]) New(world *World) *Exchange8[A, B, C, D, E, F, G, H]

New creates a new Exchange8. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Exchange2.New for an example.

func (*Exchange8[A, B, C, D, E, F, G, H]) Remove

func (ex *Exchange8[A, B, C, D, E, F, G, H]) Remove(entity Entity)

Remove the components previously specified with Exchange8.Removes from the given entity.

func (*Exchange8[A, B, C, D, E, F, G, H]) RemoveBatch

func (ex *Exchange8[A, B, C, D, E, F, G, H]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the components previously specified with Exchange8.Removes from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Exchange8[A, B, C, D, E, F, G, H]) Removes

func (ex *Exchange8[A, B, C, D, E, F, G, H]) Removes(components ...Comp) *Exchange8[A, B, C, D, E, F, G, H]

Removes sets the components that this Exchange8 removes. Can be called multiple times in chains, or once with multiple arguments.

type Filter0

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

Filter0 is a filter for 0 components. Used to create Query0 iterators.

Instances should be created during initialization and stored, e.g. in systems.

See Filter2 for a usage example.

func NewFilter0

func NewFilter0(world *World) *Filter0

NewFilter0 creates a new Filter0.

Use Filter0.Query to obtain a Query0.

func (*Filter0) Batch

func (f *Filter0) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter0.Relations. Relation components must be in the filter's parameters or added via Filter0.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter0.Batch or Filter0.Query with different relationship targets may modify stored instances.

func (*Filter0) Exclusive

func (f *Filter0) Exclusive() *Filter0

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter0) New

func (*Filter0) New(world *World) *Filter0

New creates a new Filter0. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Filter2.New for an example.

func (*Filter0) Query

func (f *Filter0) Query(rel ...Relation) Query0

Query creates a Query0 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter0.Relations. Relation components must be in the filter's parameters or added via Filter0.With beforehand.

⚠️ The returned Query0 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter0.Batch or Filter0.Query with different relationship targets may modify stored instances.

func (*Filter0) Register

func (f *Filter0) Register() *Filter0

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter0) Relations

func (f *Filter0) Relations(rel ...Relation) *Filter0

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter0.Query or Filter0.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter0.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter0) Unregister

func (f *Filter0) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter0) With

func (f *Filter0) With(comps ...Comp) *Filter0

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter0) Without

func (f *Filter0) Without(comps ...Comp) *Filter0

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type Filter1

type Filter1[A any] struct {
	// contains filtered or unexported fields
}

Filter1 is a filter for 1 components. Used to create Query1 iterators.

Instances should be created during initialization and stored, e.g. in systems.

See Filter2 for a usage example.

func NewFilter1

func NewFilter1[A any](world *World) *Filter1[A]

NewFilter1 creates a new Filter1.

Use Filter1.Query to obtain a Query1.

func (*Filter1[A]) Batch

func (f *Filter1[A]) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter1.Relations. Relation components must be in the filter's parameters or added via Filter1.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter1.Batch or Filter1.Query with different relationship targets may modify stored instances.

func (*Filter1[A]) Exclusive

func (f *Filter1[A]) Exclusive() *Filter1[A]

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter1[A]) New

func (*Filter1[A]) New(world *World) *Filter1[A]

New creates a new Filter1. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Filter2.New for an example.

func (*Filter1[A]) Query

func (f *Filter1[A]) Query(rel ...Relation) Query1[A]

Query creates a Query1 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter1.Relations. Relation components must be in the filter's parameters or added via Filter1.With beforehand.

⚠️ The returned Query1 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter1.Batch or Filter1.Query with different relationship targets may modify stored instances.

func (*Filter1[A]) Register

func (f *Filter1[A]) Register() *Filter1[A]

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter1[A]) Relations

func (f *Filter1[A]) Relations(rel ...Relation) *Filter1[A]

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter1.Query or Filter1.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter1.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter1[A]) Unregister

func (f *Filter1[A]) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter1[A]) With

func (f *Filter1[A]) With(comps ...Comp) *Filter1[A]

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter1[A]) Without

func (f *Filter1[A]) Without(comps ...Comp) *Filter1[A]

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type Filter2

type Filter2[A any, B any] struct {
	// contains filtered or unexported fields
}

Filter2 is a filter for 2 components. Used to create Query2 iterators.

Instances should be created during initialization and stored, e.g. in systems.

Example
world := ecs.NewWorld()

// A simple filter for components (non-exclusive).
simpleFilter := ecs.NewFilter2[Position, Velocity](&world)

// A simple filter with an additional (unused) and an excluded component.
complexFilter := ecs.NewFilter2[Position, Velocity](&world).
	With(ecs.C[Altitude]()).
	Without(ecs.C[ChildOf]())

// A cached/registered filter, with an additional (unused) component.
cachedFilter := ecs.NewFilter2[Position, Velocity](&world).
	With(ecs.C[Altitude]()).
	Register()

// Create a query from a filter, and iterate it.
query := simpleFilter.Query()
for query.Next() {
	// ...
}

_, _ = complexFilter, cachedFilter

func NewFilter2

func NewFilter2[A any, B any](world *World) *Filter2[A, B]

NewFilter2 creates a new Filter2.

Use Filter2.Query to obtain a Query2.

func (*Filter2[A, B]) Batch

func (f *Filter2[A, B]) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter2.Relations. Relation components must be in the filter's parameters or added via Filter2.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter2.Batch or Filter2.Query with different relationship targets may modify stored instances.

func (*Filter2[A, B]) Exclusive

func (f *Filter2[A, B]) Exclusive() *Filter2[A, B]

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter2[A, B]) New

func (*Filter2[A, B]) New(world *World) *Filter2[A, B]

New creates a new Filter2. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

Example
world := ecs.NewWorld()

// Declare the filter, e.g. in your system struct.
var filter *ecs.Filter2[Position, Velocity]

// Construct the filter, avoiding repeated listing of generics.
filter = filter.New(&world)

func (*Filter2[A, B]) Query

func (f *Filter2[A, B]) Query(rel ...Relation) Query2[A, B]

Query creates a Query2 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter2.Relations. Relation components must be in the filter's parameters or added via Filter2.With beforehand.

⚠️ The returned Query2 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter2.Batch or Filter2.Query with different relationship targets may modify stored instances.

func (*Filter2[A, B]) Register

func (f *Filter2[A, B]) Register() *Filter2[A, B]

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter2[A, B]) Relations

func (f *Filter2[A, B]) Relations(rel ...Relation) *Filter2[A, B]

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter2.Query or Filter2.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter2.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter2[A, B]) Unregister

func (f *Filter2[A, B]) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter2[A, B]) With

func (f *Filter2[A, B]) With(comps ...Comp) *Filter2[A, B]

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter2[A, B]) Without

func (f *Filter2[A, B]) Without(comps ...Comp) *Filter2[A, B]

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type Filter3

type Filter3[A any, B any, C any] struct {
	// contains filtered or unexported fields
}

Filter3 is a filter for 3 components. Used to create Query3 iterators.

Instances should be created during initialization and stored, e.g. in systems.

See Filter2 for a usage example.

func NewFilter3

func NewFilter3[A any, B any, C any](world *World) *Filter3[A, B, C]

NewFilter3 creates a new Filter3.

Use Filter3.Query to obtain a Query3.

func (*Filter3[A, B, C]) Batch

func (f *Filter3[A, B, C]) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter3.Relations. Relation components must be in the filter's parameters or added via Filter3.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter3.Batch or Filter3.Query with different relationship targets may modify stored instances.

func (*Filter3[A, B, C]) Exclusive

func (f *Filter3[A, B, C]) Exclusive() *Filter3[A, B, C]

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter3[A, B, C]) New

func (*Filter3[A, B, C]) New(world *World) *Filter3[A, B, C]

New creates a new Filter3. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Filter2.New for an example.

func (*Filter3[A, B, C]) Query

func (f *Filter3[A, B, C]) Query(rel ...Relation) Query3[A, B, C]

Query creates a Query3 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter3.Relations. Relation components must be in the filter's parameters or added via Filter3.With beforehand.

⚠️ The returned Query3 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter3.Batch or Filter3.Query with different relationship targets may modify stored instances.

func (*Filter3[A, B, C]) Register

func (f *Filter3[A, B, C]) Register() *Filter3[A, B, C]

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter3[A, B, C]) Relations

func (f *Filter3[A, B, C]) Relations(rel ...Relation) *Filter3[A, B, C]

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter3.Query or Filter3.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter3.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter3[A, B, C]) Unregister

func (f *Filter3[A, B, C]) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter3[A, B, C]) With

func (f *Filter3[A, B, C]) With(comps ...Comp) *Filter3[A, B, C]

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter3[A, B, C]) Without

func (f *Filter3[A, B, C]) Without(comps ...Comp) *Filter3[A, B, C]

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type Filter4

type Filter4[A any, B any, C any, D any] struct {
	// contains filtered or unexported fields
}

Filter4 is a filter for 4 components. Used to create Query4 iterators.

Instances should be created during initialization and stored, e.g. in systems.

See Filter2 for a usage example.

func NewFilter4

func NewFilter4[A any, B any, C any, D any](world *World) *Filter4[A, B, C, D]

NewFilter4 creates a new Filter4.

Use Filter4.Query to obtain a Query4.

func (*Filter4[A, B, C, D]) Batch

func (f *Filter4[A, B, C, D]) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter4.Relations. Relation components must be in the filter's parameters or added via Filter4.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter4.Batch or Filter4.Query with different relationship targets may modify stored instances.

func (*Filter4[A, B, C, D]) Exclusive

func (f *Filter4[A, B, C, D]) Exclusive() *Filter4[A, B, C, D]

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter4[A, B, C, D]) New

func (*Filter4[A, B, C, D]) New(world *World) *Filter4[A, B, C, D]

New creates a new Filter4. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Filter2.New for an example.

func (*Filter4[A, B, C, D]) Query

func (f *Filter4[A, B, C, D]) Query(rel ...Relation) Query4[A, B, C, D]

Query creates a Query4 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter4.Relations. Relation components must be in the filter's parameters or added via Filter4.With beforehand.

⚠️ The returned Query4 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter4.Batch or Filter4.Query with different relationship targets may modify stored instances.

func (*Filter4[A, B, C, D]) Register

func (f *Filter4[A, B, C, D]) Register() *Filter4[A, B, C, D]

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter4[A, B, C, D]) Relations

func (f *Filter4[A, B, C, D]) Relations(rel ...Relation) *Filter4[A, B, C, D]

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter4.Query or Filter4.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter4.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter4[A, B, C, D]) Unregister

func (f *Filter4[A, B, C, D]) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter4[A, B, C, D]) With

func (f *Filter4[A, B, C, D]) With(comps ...Comp) *Filter4[A, B, C, D]

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter4[A, B, C, D]) Without

func (f *Filter4[A, B, C, D]) Without(comps ...Comp) *Filter4[A, B, C, D]

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type Filter5

type Filter5[A any, B any, C any, D any, E any] struct {
	// contains filtered or unexported fields
}

Filter5 is a filter for 5 components. Used to create Query5 iterators.

Instances should be created during initialization and stored, e.g. in systems.

See Filter2 for a usage example.

func NewFilter5

func NewFilter5[A any, B any, C any, D any, E any](world *World) *Filter5[A, B, C, D, E]

NewFilter5 creates a new Filter5.

Use Filter5.Query to obtain a Query5.

func (*Filter5[A, B, C, D, E]) Batch

func (f *Filter5[A, B, C, D, E]) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter5.Relations. Relation components must be in the filter's parameters or added via Filter5.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter5.Batch or Filter5.Query with different relationship targets may modify stored instances.

func (*Filter5[A, B, C, D, E]) Exclusive

func (f *Filter5[A, B, C, D, E]) Exclusive() *Filter5[A, B, C, D, E]

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter5[A, B, C, D, E]) New

func (*Filter5[A, B, C, D, E]) New(world *World) *Filter5[A, B, C, D, E]

New creates a new Filter5. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Filter2.New for an example.

func (*Filter5[A, B, C, D, E]) Query

func (f *Filter5[A, B, C, D, E]) Query(rel ...Relation) Query5[A, B, C, D, E]

Query creates a Query5 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter5.Relations. Relation components must be in the filter's parameters or added via Filter5.With beforehand.

⚠️ The returned Query5 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter5.Batch or Filter5.Query with different relationship targets may modify stored instances.

func (*Filter5[A, B, C, D, E]) Register

func (f *Filter5[A, B, C, D, E]) Register() *Filter5[A, B, C, D, E]

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter5[A, B, C, D, E]) Relations

func (f *Filter5[A, B, C, D, E]) Relations(rel ...Relation) *Filter5[A, B, C, D, E]

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter5.Query or Filter5.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter5.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter5[A, B, C, D, E]) Unregister

func (f *Filter5[A, B, C, D, E]) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter5[A, B, C, D, E]) With

func (f *Filter5[A, B, C, D, E]) With(comps ...Comp) *Filter5[A, B, C, D, E]

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter5[A, B, C, D, E]) Without

func (f *Filter5[A, B, C, D, E]) Without(comps ...Comp) *Filter5[A, B, C, D, E]

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type Filter6

type Filter6[A any, B any, C any, D any, E any, F any] struct {
	// contains filtered or unexported fields
}

Filter6 is a filter for 6 components. Used to create Query6 iterators.

Instances should be created during initialization and stored, e.g. in systems.

See Filter2 for a usage example.

func NewFilter6

func NewFilter6[A any, B any, C any, D any, E any, F any](world *World) *Filter6[A, B, C, D, E, F]

NewFilter6 creates a new Filter6.

Use Filter6.Query to obtain a Query6.

func (*Filter6[A, B, C, D, E, F]) Batch

func (f *Filter6[A, B, C, D, E, F]) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter6.Relations. Relation components must be in the filter's parameters or added via Filter6.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter6.Batch or Filter6.Query with different relationship targets may modify stored instances.

func (*Filter6[A, B, C, D, E, F]) Exclusive

func (f *Filter6[A, B, C, D, E, F]) Exclusive() *Filter6[A, B, C, D, E, F]

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter6[A, B, C, D, E, F]) New

func (*Filter6[A, B, C, D, E, F]) New(world *World) *Filter6[A, B, C, D, E, F]

New creates a new Filter6. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Filter2.New for an example.

func (*Filter6[A, B, C, D, E, F]) Query

func (f *Filter6[A, B, C, D, E, F]) Query(rel ...Relation) Query6[A, B, C, D, E, F]

Query creates a Query6 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter6.Relations. Relation components must be in the filter's parameters or added via Filter6.With beforehand.

⚠️ The returned Query6 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter6.Batch or Filter6.Query with different relationship targets may modify stored instances.

func (*Filter6[A, B, C, D, E, F]) Register

func (f *Filter6[A, B, C, D, E, F]) Register() *Filter6[A, B, C, D, E, F]

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter6[A, B, C, D, E, F]) Relations

func (f *Filter6[A, B, C, D, E, F]) Relations(rel ...Relation) *Filter6[A, B, C, D, E, F]

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter6.Query or Filter6.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter6.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter6[A, B, C, D, E, F]) Unregister

func (f *Filter6[A, B, C, D, E, F]) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter6[A, B, C, D, E, F]) With

func (f *Filter6[A, B, C, D, E, F]) With(comps ...Comp) *Filter6[A, B, C, D, E, F]

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter6[A, B, C, D, E, F]) Without

func (f *Filter6[A, B, C, D, E, F]) Without(comps ...Comp) *Filter6[A, B, C, D, E, F]

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type Filter7

type Filter7[A any, B any, C any, D any, E any, F any, G any] struct {
	// contains filtered or unexported fields
}

Filter7 is a filter for 7 components. Used to create Query7 iterators.

Instances should be created during initialization and stored, e.g. in systems.

See Filter2 for a usage example.

func NewFilter7

func NewFilter7[A any, B any, C any, D any, E any, F any, G any](world *World) *Filter7[A, B, C, D, E, F, G]

NewFilter7 creates a new Filter7.

Use Filter7.Query to obtain a Query7.

func (*Filter7[A, B, C, D, E, F, G]) Batch

func (f *Filter7[A, B, C, D, E, F, G]) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter7.Relations. Relation components must be in the filter's parameters or added via Filter7.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter7.Batch or Filter7.Query with different relationship targets may modify stored instances.

func (*Filter7[A, B, C, D, E, F, G]) Exclusive

func (f *Filter7[A, B, C, D, E, F, G]) Exclusive() *Filter7[A, B, C, D, E, F, G]

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter7[A, B, C, D, E, F, G]) New

func (*Filter7[A, B, C, D, E, F, G]) New(world *World) *Filter7[A, B, C, D, E, F, G]

New creates a new Filter7. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Filter2.New for an example.

func (*Filter7[A, B, C, D, E, F, G]) Query

func (f *Filter7[A, B, C, D, E, F, G]) Query(rel ...Relation) Query7[A, B, C, D, E, F, G]

Query creates a Query7 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter7.Relations. Relation components must be in the filter's parameters or added via Filter7.With beforehand.

⚠️ The returned Query7 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter7.Batch or Filter7.Query with different relationship targets may modify stored instances.

func (*Filter7[A, B, C, D, E, F, G]) Register

func (f *Filter7[A, B, C, D, E, F, G]) Register() *Filter7[A, B, C, D, E, F, G]

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter7[A, B, C, D, E, F, G]) Relations

func (f *Filter7[A, B, C, D, E, F, G]) Relations(rel ...Relation) *Filter7[A, B, C, D, E, F, G]

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter7.Query or Filter7.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter7.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter7[A, B, C, D, E, F, G]) Unregister

func (f *Filter7[A, B, C, D, E, F, G]) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter7[A, B, C, D, E, F, G]) With

func (f *Filter7[A, B, C, D, E, F, G]) With(comps ...Comp) *Filter7[A, B, C, D, E, F, G]

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter7[A, B, C, D, E, F, G]) Without

func (f *Filter7[A, B, C, D, E, F, G]) Without(comps ...Comp) *Filter7[A, B, C, D, E, F, G]

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type Filter8

type Filter8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
	// contains filtered or unexported fields
}

Filter8 is a filter for 8 components. Used to create Query8 iterators.

Instances should be created during initialization and stored, e.g. in systems.

See Filter2 for a usage example.

func NewFilter8

func NewFilter8[A any, B any, C any, D any, E any, F any, G any, H any](world *World) *Filter8[A, B, C, D, E, F, G, H]

NewFilter8 creates a new Filter8.

Use Filter8.Query to obtain a Query8.

func (*Filter8[A, B, C, D, E, F, G, H]) Batch

func (f *Filter8[A, B, C, D, E, F, G, H]) Batch(rel ...Relation) *Batch

Batch creates a Batch from this filter.

Relation targets provided here are added to those specified with Filter8.Relations. Relation components must be in the filter's parameters or added via Filter8.With beforehand.

⚠️ The returned Batch filter should not be stored, but used immediately and re-generated each time a batch operation is called. Otherwise, changes to the origin filter or calls to Filter8.Batch or Filter8.Query with different relationship targets may modify stored instances.

func (*Filter8[A, B, C, D, E, F, G, H]) Exclusive

func (f *Filter8[A, B, C, D, E, F, G, H]) Exclusive() *Filter8[A, B, C, D, E, F, G, H]

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (*Filter8[A, B, C, D, E, F, G, H]) New

func (*Filter8[A, B, C, D, E, F, G, H]) New(world *World) *Filter8[A, B, C, D, E, F, G, H]

New creates a new Filter8. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Filter2.New for an example.

func (*Filter8[A, B, C, D, E, F, G, H]) Query

func (f *Filter8[A, B, C, D, E, F, G, H]) Query(rel ...Relation) Query8[A, B, C, D, E, F, G, H]

Query creates a Query8 from this filter. This must be used each time before iterating a query.

Relation targets provided here are added to those specified with Filter8.Relations. Relation components must be in the filter's parameters or added via Filter8.With beforehand.

⚠️ The returned Query8 should not be stored, but used immediately and re-generated each time before query iteration. Otherwise, changes to the origin filter or calls to Filter8.Batch or Filter8.Query with different relationship targets may modify stored instances.

func (*Filter8[A, B, C, D, E, F, G, H]) Register

func (f *Filter8[A, B, C, D, E, F, G, H]) Register() *Filter8[A, B, C, D, E, F, G, H]

Register this filter to the world's filter cache.

Registering filters is optional. It avoids a potential slowdown that may be caused by a very high number of archetypes, like hundreds or thousands.

func (*Filter8[A, B, C, D, E, F, G, H]) Relations

func (f *Filter8[A, B, C, D, E, F, G, H]) Relations(rel ...Relation) *Filter8[A, B, C, D, E, F, G, H]

Relations sets permanent entity relation targets for this filter. Relation targets set here are included in filter caching. Contrary, relation targets specified in Filter8.Query or Filter8.Batch are not cached.

Relation components used here must be in the filter's parameters or added via Filter8.With beforehand.

Can be called multiple times in chains, or once with multiple arguments.

func (*Filter8[A, B, C, D, E, F, G, H]) Unregister

func (f *Filter8[A, B, C, D, E, F, G, H]) Unregister()

Unregister this filter from the world's filter cache.

func (*Filter8[A, B, C, D, E, F, G, H]) With

func (f *Filter8[A, B, C, D, E, F, G, H]) With(comps ...Comp) *Filter8[A, B, C, D, E, F, G, H]

With specifies additional components to filter for. Can be called multiple times in chains, or once with multiple arguments.

func (*Filter8[A, B, C, D, E, F, G, H]) Without

func (f *Filter8[A, B, C, D, E, F, G, H]) Without(comps ...Comp) *Filter8[A, B, C, D, E, F, G, H]

Without specifies components to exclude. Can be called multiple times in chains, or once with multiple arguments.

type ID

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

ID is the component identifier. It is not relevant when using the default generic API.

func ComponentID

func ComponentID[T any](w *World) ID

ComponentID returns the ID for a component type via generics. Registers the type if it is not already registered.

The number of unique component types per World is limited to 256 (64 with build tag ark_tiny).

Panics if called on a locked world and the type is not registered yet.

Note that type aliases are not considered separate component types. Type re-definitions, however, are separate types.

⚠️ Warning: Using IDs that are outside of the range of registered IDs anywhere in World or other places will result in undefined behavior!

func ComponentIDs

func ComponentIDs(w *World) []ID

ComponentIDs returns a list of all registered component IDs.

func TypeID

func TypeID(w *World, tp reflect.Type) ID

TypeID returns the ID for a component type. Registers the type if it is not already registered.

The number of unique component types per World is limited to 256 (64 with build tag ark_tiny).

func (ID) Index

func (id ID) Index() uint8

Index returns the internal component index of this component ID.

type IDs

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

IDs is an immutable list of ID values.

func (*IDs) Get

func (ids *IDs) Get(index int) ID

Get returns the ID at the given index.

func (*IDs) Len

func (ids *IDs) Len() int

Len returns the number of IDs.

type Map

type Map[T any] struct {
	// contains filtered or unexported fields
}

Map is a mapper to access and manipulate components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

Example
world := ecs.NewWorld()

// Create a component mapper.
mapper := ecs.NewMap[Position](&world)

// Create an entity.
entity := mapper.NewEntity(&Position{X: 100, Y: 100})

// Remove component from the entity.
mapper.Remove(entity)
// Add component to the entity.
mapper.Add(entity, &Position{X: 100, Y: 100})

func NewMap

func NewMap[T any](w *World) *Map[T]

NewMap creates a new Map.

func (*Map[T]) Add

func (m *Map[T]) Add(entity Entity, comp *T, target ...Entity)

Add the mapped component to the given entity.

If the mapped component is a relationship (see RelationMarker), a relation target entity must be provided.

func (*Map[T]) AddBatch

func (m *Map[T]) AddBatch(batch *Batch, comp *T, target ...Entity)

AddBatch adds the mapped component to all entities matching the given batch filter.

If the mapped component is a relationship (see RelationMarker), a relation target entity must be provided.

func (*Map[T]) AddBatchFn

func (m *Map[T]) AddBatchFn(batch *Batch, fn func(entity Entity, comp *T), target ...Entity)

AddBatchFn adds the mapped component to all entities matching the given batch filter, running the given function on each. The function can be nil.

If the mapped component is a relationship (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map[T]) AddFn

func (m *Map[T]) AddFn(entity Entity, fn func(a *T), target ...Entity)

AddFn adds the mapped component to the given entity and runs a callback instead of using a component for initialization. The callback can be nil.

If the mapped component is a relationship (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointer outside of the current context!

func (*Map[T]) Get

func (m *Map[T]) Get(entity Entity) *T

Get returns the mapped component for the given entity.

Returns nil if the entity does not have the mapped component.

⚠️ Do not store the obtained pointer outside of the current context!

func (*Map[T]) GetRelation

func (m *Map[T]) GetRelation(entity Entity) Entity

GetRelation returns the relation target for the entity and the mapped component.

func (*Map[T]) GetRelationUnchecked

func (m *Map[T]) GetRelationUnchecked(entity Entity) Entity

GetRelationUnchecked returns the relation target for the entity and the mapped component. In contrast to Map.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map[T]) GetUnchecked

func (m *Map[T]) GetUnchecked(entity Entity) *T

GetUnchecked returns the mapped component for the given entity. In contrast to Map.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Returns nil if the entity does not have the mapped component.

⚠️ Do not store the obtained pointer outside of the current context!

func (*Map[T]) Has

func (m *Map[T]) Has(entity Entity) bool

Has return whether the given entity has the mapped component.

Using Map.Get and checking for nil pointer may be faster than calling Map.Has and Map.Get subsequently.

func (*Map[T]) HasUnchecked

func (m *Map[T]) HasUnchecked(entity Entity) bool

HasUnchecked return whether the given entity has the mapped component. In contrast to Map.Has, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map[T]) NewBatch

func (m *Map[T]) NewBatch(count int, comp *T, target ...Entity)

NewBatch creates a batch of new entities with the mapped component.

If the mapped component is a relationship (see RelationMarker), a relation target entity must be provided.

func (*Map[T]) NewBatchFn

func (m *Map[T]) NewBatchFn(count int, fn func(entity Entity, comp *T), target ...Entity)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

If the mapped component is a relationship (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map[T]) NewEntity

func (m *Map[T]) NewEntity(comp *T, target ...Entity) Entity

NewEntity creates a new entity with the mapped component.

If the mapped component is a relationship (see RelationMarker), a relation target entity must be provided.

func (*Map[T]) NewEntityFn

func (m *Map[T]) NewEntityFn(fn func(a *T), target ...Entity) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

If the mapped component is a relationship (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointer outside of the current context!

func (*Map[T]) Remove

func (m *Map[T]) Remove(entity Entity)

Remove the mapped component from the given entity.

func (*Map[T]) RemoveBatch

func (m *Map[T]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped component from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map[T]) Set

func (m *Map[T]) Set(entity Entity, comp *T)

Set the mapped component of the given entity to the given values.

Requires the entity to already have the mapped component. This is not a component operation, so it can be performed on a locked world.

func (*Map[T]) SetRelation

func (m *Map[T]) SetRelation(entity Entity, target Entity)

SetRelation sets the relation target for the entity and the mapped component.

func (*Map[T]) SetRelationBatch

func (m *Map[T]) SetRelationBatch(batch *Batch, target Entity, fn func(entity Entity))

SetRelationBatch sets the relation target for all entities matching the given batch filter.

type Map1

type Map1[A any] struct {
	// contains filtered or unexported fields
}

Map1 is a mapper to access 1 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap1

func NewMap1[A any](world *World) *Map1[A]

NewMap1 creates a new Map1.

func (*Map1[A]) Add

func (m *Map1[A]) Add(entity Entity, a *A, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map1[A]) AddBatch

func (m *Map1[A]) AddBatch(batch *Batch, a *A, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map1[A]) AddBatchFn

func (m *Map1[A]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map1[A]) AddFn

func (m *Map1[A]) AddFn(entity Entity, fn func(a *A), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map1[A]) Get

func (m *Map1[A]) Get(entity Entity) *A

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map1[A]) GetRelation

func (m *Map1[A]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map1[A]) GetRelationUnchecked

func (m *Map1[A]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map1.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map1[A]) GetUnchecked

func (m *Map1[A]) GetUnchecked(entity Entity) *A

GetUnchecked returns the mapped components for the given entity. In contrast to Map1.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map1[A]) HasAll

func (m *Map1[A]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map1.Get and checking for nil pointer may be faster than calling Map1.HasAll and Map1.Get subsequently.

func (*Map1[A]) New

func (_ *Map1[A]) New(world *World) *Map1[A]

New creates a new Map1. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map1[A]) NewBatch

func (m *Map1[A]) NewBatch(count int, a *A, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map1[A]) NewBatchFn

func (m *Map1[A]) NewBatchFn(count int, fn func(entity Entity, a *A), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map1[A]) NewEntity

func (m *Map1[A]) NewEntity(a *A, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map1[A]) NewEntityFn

func (m *Map1[A]) NewEntityFn(fn func(a *A), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map1[A]) Remove

func (m *Map1[A]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map1[A]) RemoveBatch

func (m *Map1[A]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map1[A]) Set

func (m *Map1[A]) Set(entity Entity, a *A)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map1[A]) SetRelations

func (m *Map1[A]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map1[A]) SetRelationsBatch

func (m *Map1[A]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map10

type Map10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any] struct {
	// contains filtered or unexported fields
}

Map10 is a mapper to access 10 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap10

func NewMap10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](world *World) *Map10[A, B, C, D, E, F, G, H, I, J]

NewMap10 creates a new Map10.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) Add

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) AddBatch

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) AddBatchFn

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map10[A, B, C, D, E, F, G, H, I, J]) AddFn

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map10[A, B, C, D, E, F, G, H, I, J]) Get

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) Get(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H, *I, *J)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map10[A, B, C, D, E, F, G, H, I, J]) GetRelation

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) GetRelationUnchecked

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map10.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) GetUnchecked

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H, *I, *J)

GetUnchecked returns the mapped components for the given entity. In contrast to Map10.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map10[A, B, C, D, E, F, G, H, I, J]) HasAll

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map10.Get and checking for nil pointer may be faster than calling Map10.HasAll and Map10.Get subsequently.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) New

func (_ *Map10[A, B, C, D, E, F, G, H, I, J]) New(world *World) *Map10[A, B, C, D, E, F, G, H, I, J]

New creates a new Map10. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) NewBatch

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) NewBatchFn

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map10[A, B, C, D, E, F, G, H, I, J]) NewEntity

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) NewEntityFn

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) NewEntityFn(fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map10[A, B, C, D, E, F, G, H, I, J]) Remove

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) RemoveBatch

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) Set

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) Set(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) SetRelations

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map10[A, B, C, D, E, F, G, H, I, J]) SetRelationsBatch

func (m *Map10[A, B, C, D, E, F, G, H, I, J]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map11

type Map11[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any, K any] struct {
	// contains filtered or unexported fields
}

Map11 is a mapper to access 11 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap11

func NewMap11[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any, K any](world *World) *Map11[A, B, C, D, E, F, G, H, I, J, K]

NewMap11 creates a new Map11.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) Add

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) AddBatch

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) AddBatchFn

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) AddFn

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) Get

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) Get(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H, *I, *J, *K)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) GetRelation

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) GetRelationUnchecked

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map11.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) GetUnchecked

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H, *I, *J, *K)

GetUnchecked returns the mapped components for the given entity. In contrast to Map11.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) HasAll

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map11.Get and checking for nil pointer may be faster than calling Map11.HasAll and Map11.Get subsequently.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) New

func (_ *Map11[A, B, C, D, E, F, G, H, I, J, K]) New(world *World) *Map11[A, B, C, D, E, F, G, H, I, J, K]

New creates a new Map11. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) NewBatch

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) NewBatchFn

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) NewEntity

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) NewEntityFn

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) NewEntityFn(fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) Remove

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) RemoveBatch

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) Set

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) Set(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) SetRelations

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map11[A, B, C, D, E, F, G, H, I, J, K]) SetRelationsBatch

func (m *Map11[A, B, C, D, E, F, G, H, I, J, K]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map12

type Map12[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any, K any, L any] struct {
	// contains filtered or unexported fields
}

Map12 is a mapper to access 12 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap12

func NewMap12[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any, K any, L any](world *World) *Map12[A, B, C, D, E, F, G, H, I, J, K, L]

NewMap12 creates a new Map12.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) Add

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) AddBatch

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) AddBatchFn

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) AddFn

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) Get

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) Get(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H, *I, *J, *K, *L)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) GetRelation

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) GetRelationUnchecked

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map12.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) GetUnchecked

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H, *I, *J, *K, *L)

GetUnchecked returns the mapped components for the given entity. In contrast to Map12.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) HasAll

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map12.Get and checking for nil pointer may be faster than calling Map12.HasAll and Map12.Get subsequently.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) New

func (_ *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) New(world *World) *Map12[A, B, C, D, E, F, G, H, I, J, K, L]

New creates a new Map12. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) NewBatch

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) NewBatchFn

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) NewEntity

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) NewEntityFn

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) NewEntityFn(fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) Remove

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) RemoveBatch

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) Set

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) Set(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, j *J, k *K, l *L)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) SetRelations

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map12[A, B, C, D, E, F, G, H, I, J, K, L]) SetRelationsBatch

func (m *Map12[A, B, C, D, E, F, G, H, I, J, K, L]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map2

type Map2[A any, B any] struct {
	// contains filtered or unexported fields
}

Map2 is a mapper to access 2 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

Example
world := ecs.NewWorld()

// Create a component mapper.
mapper := ecs.NewMap2[Position, Velocity](&world)

// Create an entity.
entity := mapper.NewEntity(&Position{X: 100, Y: 100}, &Velocity{X: 1, Y: -1})

// Remove components from the entity.
mapper.Remove(entity)
// Add components to the entity.
mapper.Add(entity, &Position{X: 100, Y: 100}, &Velocity{X: 1, Y: -1})

func NewMap2

func NewMap2[A any, B any](world *World) *Map2[A, B]

NewMap2 creates a new Map2.

func (*Map2[A, B]) Add

func (m *Map2[A, B]) Add(entity Entity, a *A, b *B, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map2[A, B]) AddBatch

func (m *Map2[A, B]) AddBatch(batch *Batch, a *A, b *B, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map2[A, B]) AddBatchFn

func (m *Map2[A, B]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map2[A, B]) AddFn

func (m *Map2[A, B]) AddFn(entity Entity, fn func(a *A, b *B), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map2[A, B]) Get

func (m *Map2[A, B]) Get(entity Entity) (*A, *B)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map2[A, B]) GetRelation

func (m *Map2[A, B]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map2[A, B]) GetRelationUnchecked

func (m *Map2[A, B]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map2.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map2[A, B]) GetUnchecked

func (m *Map2[A, B]) GetUnchecked(entity Entity) (*A, *B)

GetUnchecked returns the mapped components for the given entity. In contrast to Map2.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map2[A, B]) HasAll

func (m *Map2[A, B]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map2.Get and checking for nil pointer may be faster than calling Map2.HasAll and Map2.Get subsequently.

func (*Map2[A, B]) New

func (_ *Map2[A, B]) New(world *World) *Map2[A, B]

New creates a new Map2. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

Example
world := ecs.NewWorld()

// Declare the mapper, e.g. in your system struct.
var mapper *ecs.Map2[Position, Velocity]

// Construct the mapper, avoiding repeated listing of generics.
mapper = mapper.New(&world)

func (*Map2[A, B]) NewBatch

func (m *Map2[A, B]) NewBatch(count int, a *A, b *B, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map2[A, B]) NewBatchFn

func (m *Map2[A, B]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map2[A, B]) NewEntity

func (m *Map2[A, B]) NewEntity(a *A, b *B, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map2[A, B]) NewEntityFn

func (m *Map2[A, B]) NewEntityFn(fn func(a *A, b *B), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map2[A, B]) Remove

func (m *Map2[A, B]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map2[A, B]) RemoveBatch

func (m *Map2[A, B]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map2[A, B]) Set

func (m *Map2[A, B]) Set(entity Entity, a *A, b *B)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map2[A, B]) SetRelations

func (m *Map2[A, B]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map2[A, B]) SetRelationsBatch

func (m *Map2[A, B]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map3

type Map3[A any, B any, C any] struct {
	// contains filtered or unexported fields
}

Map3 is a mapper to access 3 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap3

func NewMap3[A any, B any, C any](world *World) *Map3[A, B, C]

NewMap3 creates a new Map3.

func (*Map3[A, B, C]) Add

func (m *Map3[A, B, C]) Add(entity Entity, a *A, b *B, c *C, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map3[A, B, C]) AddBatch

func (m *Map3[A, B, C]) AddBatch(batch *Batch, a *A, b *B, c *C, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map3[A, B, C]) AddBatchFn

func (m *Map3[A, B, C]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map3[A, B, C]) AddFn

func (m *Map3[A, B, C]) AddFn(entity Entity, fn func(a *A, b *B, c *C), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map3[A, B, C]) Get

func (m *Map3[A, B, C]) Get(entity Entity) (*A, *B, *C)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map3[A, B, C]) GetRelation

func (m *Map3[A, B, C]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map3[A, B, C]) GetRelationUnchecked

func (m *Map3[A, B, C]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map3.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map3[A, B, C]) GetUnchecked

func (m *Map3[A, B, C]) GetUnchecked(entity Entity) (*A, *B, *C)

GetUnchecked returns the mapped components for the given entity. In contrast to Map3.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map3[A, B, C]) HasAll

func (m *Map3[A, B, C]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map3.Get and checking for nil pointer may be faster than calling Map3.HasAll and Map3.Get subsequently.

func (*Map3[A, B, C]) New

func (_ *Map3[A, B, C]) New(world *World) *Map3[A, B, C]

New creates a new Map3. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map3[A, B, C]) NewBatch

func (m *Map3[A, B, C]) NewBatch(count int, a *A, b *B, c *C, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map3[A, B, C]) NewBatchFn

func (m *Map3[A, B, C]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map3[A, B, C]) NewEntity

func (m *Map3[A, B, C]) NewEntity(a *A, b *B, c *C, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map3[A, B, C]) NewEntityFn

func (m *Map3[A, B, C]) NewEntityFn(fn func(a *A, b *B, c *C), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map3[A, B, C]) Remove

func (m *Map3[A, B, C]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map3[A, B, C]) RemoveBatch

func (m *Map3[A, B, C]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map3[A, B, C]) Set

func (m *Map3[A, B, C]) Set(entity Entity, a *A, b *B, c *C)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map3[A, B, C]) SetRelations

func (m *Map3[A, B, C]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map3[A, B, C]) SetRelationsBatch

func (m *Map3[A, B, C]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map4

type Map4[A any, B any, C any, D any] struct {
	// contains filtered or unexported fields
}

Map4 is a mapper to access 4 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap4

func NewMap4[A any, B any, C any, D any](world *World) *Map4[A, B, C, D]

NewMap4 creates a new Map4.

func (*Map4[A, B, C, D]) Add

func (m *Map4[A, B, C, D]) Add(entity Entity, a *A, b *B, c *C, d *D, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map4[A, B, C, D]) AddBatch

func (m *Map4[A, B, C, D]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map4[A, B, C, D]) AddBatchFn

func (m *Map4[A, B, C, D]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map4[A, B, C, D]) AddFn

func (m *Map4[A, B, C, D]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map4[A, B, C, D]) Get

func (m *Map4[A, B, C, D]) Get(entity Entity) (*A, *B, *C, *D)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map4[A, B, C, D]) GetRelation

func (m *Map4[A, B, C, D]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map4[A, B, C, D]) GetRelationUnchecked

func (m *Map4[A, B, C, D]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map4.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map4[A, B, C, D]) GetUnchecked

func (m *Map4[A, B, C, D]) GetUnchecked(entity Entity) (*A, *B, *C, *D)

GetUnchecked returns the mapped components for the given entity. In contrast to Map4.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map4[A, B, C, D]) HasAll

func (m *Map4[A, B, C, D]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map4.Get and checking for nil pointer may be faster than calling Map4.HasAll and Map4.Get subsequently.

func (*Map4[A, B, C, D]) New

func (_ *Map4[A, B, C, D]) New(world *World) *Map4[A, B, C, D]

New creates a new Map4. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map4[A, B, C, D]) NewBatch

func (m *Map4[A, B, C, D]) NewBatch(count int, a *A, b *B, c *C, d *D, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map4[A, B, C, D]) NewBatchFn

func (m *Map4[A, B, C, D]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map4[A, B, C, D]) NewEntity

func (m *Map4[A, B, C, D]) NewEntity(a *A, b *B, c *C, d *D, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map4[A, B, C, D]) NewEntityFn

func (m *Map4[A, B, C, D]) NewEntityFn(fn func(a *A, b *B, c *C, d *D), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map4[A, B, C, D]) Remove

func (m *Map4[A, B, C, D]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map4[A, B, C, D]) RemoveBatch

func (m *Map4[A, B, C, D]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map4[A, B, C, D]) Set

func (m *Map4[A, B, C, D]) Set(entity Entity, a *A, b *B, c *C, d *D)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map4[A, B, C, D]) SetRelations

func (m *Map4[A, B, C, D]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map4[A, B, C, D]) SetRelationsBatch

func (m *Map4[A, B, C, D]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map5

type Map5[A any, B any, C any, D any, E any] struct {
	// contains filtered or unexported fields
}

Map5 is a mapper to access 5 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap5

func NewMap5[A any, B any, C any, D any, E any](world *World) *Map5[A, B, C, D, E]

NewMap5 creates a new Map5.

func (*Map5[A, B, C, D, E]) Add

func (m *Map5[A, B, C, D, E]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map5[A, B, C, D, E]) AddBatch

func (m *Map5[A, B, C, D, E]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map5[A, B, C, D, E]) AddBatchFn

func (m *Map5[A, B, C, D, E]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map5[A, B, C, D, E]) AddFn

func (m *Map5[A, B, C, D, E]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map5[A, B, C, D, E]) Get

func (m *Map5[A, B, C, D, E]) Get(entity Entity) (*A, *B, *C, *D, *E)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map5[A, B, C, D, E]) GetRelation

func (m *Map5[A, B, C, D, E]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map5[A, B, C, D, E]) GetRelationUnchecked

func (m *Map5[A, B, C, D, E]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map5.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map5[A, B, C, D, E]) GetUnchecked

func (m *Map5[A, B, C, D, E]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E)

GetUnchecked returns the mapped components for the given entity. In contrast to Map5.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map5[A, B, C, D, E]) HasAll

func (m *Map5[A, B, C, D, E]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map5.Get and checking for nil pointer may be faster than calling Map5.HasAll and Map5.Get subsequently.

func (*Map5[A, B, C, D, E]) New

func (_ *Map5[A, B, C, D, E]) New(world *World) *Map5[A, B, C, D, E]

New creates a new Map5. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map5[A, B, C, D, E]) NewBatch

func (m *Map5[A, B, C, D, E]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map5[A, B, C, D, E]) NewBatchFn

func (m *Map5[A, B, C, D, E]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map5[A, B, C, D, E]) NewEntity

func (m *Map5[A, B, C, D, E]) NewEntity(a *A, b *B, c *C, d *D, e *E, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map5[A, B, C, D, E]) NewEntityFn

func (m *Map5[A, B, C, D, E]) NewEntityFn(fn func(a *A, b *B, c *C, d *D, e *E), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map5[A, B, C, D, E]) Remove

func (m *Map5[A, B, C, D, E]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map5[A, B, C, D, E]) RemoveBatch

func (m *Map5[A, B, C, D, E]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map5[A, B, C, D, E]) Set

func (m *Map5[A, B, C, D, E]) Set(entity Entity, a *A, b *B, c *C, d *D, e *E)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map5[A, B, C, D, E]) SetRelations

func (m *Map5[A, B, C, D, E]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map5[A, B, C, D, E]) SetRelationsBatch

func (m *Map5[A, B, C, D, E]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map6

type Map6[A any, B any, C any, D any, E any, F any] struct {
	// contains filtered or unexported fields
}

Map6 is a mapper to access 6 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap6

func NewMap6[A any, B any, C any, D any, E any, F any](world *World) *Map6[A, B, C, D, E, F]

NewMap6 creates a new Map6.

func (*Map6[A, B, C, D, E, F]) Add

func (m *Map6[A, B, C, D, E, F]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map6[A, B, C, D, E, F]) AddBatch

func (m *Map6[A, B, C, D, E, F]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map6[A, B, C, D, E, F]) AddBatchFn

func (m *Map6[A, B, C, D, E, F]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map6[A, B, C, D, E, F]) AddFn

func (m *Map6[A, B, C, D, E, F]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map6[A, B, C, D, E, F]) Get

func (m *Map6[A, B, C, D, E, F]) Get(entity Entity) (*A, *B, *C, *D, *E, *F)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map6[A, B, C, D, E, F]) GetRelation

func (m *Map6[A, B, C, D, E, F]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map6[A, B, C, D, E, F]) GetRelationUnchecked

func (m *Map6[A, B, C, D, E, F]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map6.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map6[A, B, C, D, E, F]) GetUnchecked

func (m *Map6[A, B, C, D, E, F]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F)

GetUnchecked returns the mapped components for the given entity. In contrast to Map6.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map6[A, B, C, D, E, F]) HasAll

func (m *Map6[A, B, C, D, E, F]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map6.Get and checking for nil pointer may be faster than calling Map6.HasAll and Map6.Get subsequently.

func (*Map6[A, B, C, D, E, F]) New

func (_ *Map6[A, B, C, D, E, F]) New(world *World) *Map6[A, B, C, D, E, F]

New creates a new Map6. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map6[A, B, C, D, E, F]) NewBatch

func (m *Map6[A, B, C, D, E, F]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map6[A, B, C, D, E, F]) NewBatchFn

func (m *Map6[A, B, C, D, E, F]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map6[A, B, C, D, E, F]) NewEntity

func (m *Map6[A, B, C, D, E, F]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map6[A, B, C, D, E, F]) NewEntityFn

func (m *Map6[A, B, C, D, E, F]) NewEntityFn(fn func(a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map6[A, B, C, D, E, F]) Remove

func (m *Map6[A, B, C, D, E, F]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map6[A, B, C, D, E, F]) RemoveBatch

func (m *Map6[A, B, C, D, E, F]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map6[A, B, C, D, E, F]) Set

func (m *Map6[A, B, C, D, E, F]) Set(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map6[A, B, C, D, E, F]) SetRelations

func (m *Map6[A, B, C, D, E, F]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map6[A, B, C, D, E, F]) SetRelationsBatch

func (m *Map6[A, B, C, D, E, F]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map7

type Map7[A any, B any, C any, D any, E any, F any, G any] struct {
	// contains filtered or unexported fields
}

Map7 is a mapper to access 7 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap7

func NewMap7[A any, B any, C any, D any, E any, F any, G any](world *World) *Map7[A, B, C, D, E, F, G]

NewMap7 creates a new Map7.

func (*Map7[A, B, C, D, E, F, G]) Add

func (m *Map7[A, B, C, D, E, F, G]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map7[A, B, C, D, E, F, G]) AddBatch

func (m *Map7[A, B, C, D, E, F, G]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map7[A, B, C, D, E, F, G]) AddBatchFn

func (m *Map7[A, B, C, D, E, F, G]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map7[A, B, C, D, E, F, G]) AddFn

func (m *Map7[A, B, C, D, E, F, G]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map7[A, B, C, D, E, F, G]) Get

func (m *Map7[A, B, C, D, E, F, G]) Get(entity Entity) (*A, *B, *C, *D, *E, *F, *G)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map7[A, B, C, D, E, F, G]) GetRelation

func (m *Map7[A, B, C, D, E, F, G]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map7[A, B, C, D, E, F, G]) GetRelationUnchecked

func (m *Map7[A, B, C, D, E, F, G]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map7.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map7[A, B, C, D, E, F, G]) GetUnchecked

func (m *Map7[A, B, C, D, E, F, G]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F, *G)

GetUnchecked returns the mapped components for the given entity. In contrast to Map7.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map7[A, B, C, D, E, F, G]) HasAll

func (m *Map7[A, B, C, D, E, F, G]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map7.Get and checking for nil pointer may be faster than calling Map7.HasAll and Map7.Get subsequently.

func (*Map7[A, B, C, D, E, F, G]) New

func (_ *Map7[A, B, C, D, E, F, G]) New(world *World) *Map7[A, B, C, D, E, F, G]

New creates a new Map7. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map7[A, B, C, D, E, F, G]) NewBatch

func (m *Map7[A, B, C, D, E, F, G]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map7[A, B, C, D, E, F, G]) NewBatchFn

func (m *Map7[A, B, C, D, E, F, G]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map7[A, B, C, D, E, F, G]) NewEntity

func (m *Map7[A, B, C, D, E, F, G]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map7[A, B, C, D, E, F, G]) NewEntityFn

func (m *Map7[A, B, C, D, E, F, G]) NewEntityFn(fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map7[A, B, C, D, E, F, G]) Remove

func (m *Map7[A, B, C, D, E, F, G]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map7[A, B, C, D, E, F, G]) RemoveBatch

func (m *Map7[A, B, C, D, E, F, G]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map7[A, B, C, D, E, F, G]) Set

func (m *Map7[A, B, C, D, E, F, G]) Set(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map7[A, B, C, D, E, F, G]) SetRelations

func (m *Map7[A, B, C, D, E, F, G]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map7[A, B, C, D, E, F, G]) SetRelationsBatch

func (m *Map7[A, B, C, D, E, F, G]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map8

type Map8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
	// contains filtered or unexported fields
}

Map8 is a mapper to access 8 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap8

func NewMap8[A any, B any, C any, D any, E any, F any, G any, H any](world *World) *Map8[A, B, C, D, E, F, G, H]

NewMap8 creates a new Map8.

func (*Map8[A, B, C, D, E, F, G, H]) Add

func (m *Map8[A, B, C, D, E, F, G, H]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map8[A, B, C, D, E, F, G, H]) AddBatch

func (m *Map8[A, B, C, D, E, F, G, H]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map8[A, B, C, D, E, F, G, H]) AddBatchFn

func (m *Map8[A, B, C, D, E, F, G, H]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map8[A, B, C, D, E, F, G, H]) AddFn

func (m *Map8[A, B, C, D, E, F, G, H]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map8[A, B, C, D, E, F, G, H]) Get

func (m *Map8[A, B, C, D, E, F, G, H]) Get(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map8[A, B, C, D, E, F, G, H]) GetRelation

func (m *Map8[A, B, C, D, E, F, G, H]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map8[A, B, C, D, E, F, G, H]) GetRelationUnchecked

func (m *Map8[A, B, C, D, E, F, G, H]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map8.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map8[A, B, C, D, E, F, G, H]) GetUnchecked

func (m *Map8[A, B, C, D, E, F, G, H]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H)

GetUnchecked returns the mapped components for the given entity. In contrast to Map8.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map8[A, B, C, D, E, F, G, H]) HasAll

func (m *Map8[A, B, C, D, E, F, G, H]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map8.Get and checking for nil pointer may be faster than calling Map8.HasAll and Map8.Get subsequently.

func (*Map8[A, B, C, D, E, F, G, H]) New

func (_ *Map8[A, B, C, D, E, F, G, H]) New(world *World) *Map8[A, B, C, D, E, F, G, H]

New creates a new Map8. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map8[A, B, C, D, E, F, G, H]) NewBatch

func (m *Map8[A, B, C, D, E, F, G, H]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map8[A, B, C, D, E, F, G, H]) NewBatchFn

func (m *Map8[A, B, C, D, E, F, G, H]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map8[A, B, C, D, E, F, G, H]) NewEntity

func (m *Map8[A, B, C, D, E, F, G, H]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map8[A, B, C, D, E, F, G, H]) NewEntityFn

func (m *Map8[A, B, C, D, E, F, G, H]) NewEntityFn(fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map8[A, B, C, D, E, F, G, H]) Remove

func (m *Map8[A, B, C, D, E, F, G, H]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map8[A, B, C, D, E, F, G, H]) RemoveBatch

func (m *Map8[A, B, C, D, E, F, G, H]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map8[A, B, C, D, E, F, G, H]) Set

func (m *Map8[A, B, C, D, E, F, G, H]) Set(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map8[A, B, C, D, E, F, G, H]) SetRelations

func (m *Map8[A, B, C, D, E, F, G, H]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map8[A, B, C, D, E, F, G, H]) SetRelationsBatch

func (m *Map8[A, B, C, D, E, F, G, H]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Map9

type Map9[A any, B any, C any, D any, E any, F any, G any, H any, I any] struct {
	// contains filtered or unexported fields
}

Map9 is a mapper to access 9 components of an entity.

Instances should be created during initialization and stored, e.g. in systems.

See Map2 for a usage example.

func NewMap9

func NewMap9[A any, B any, C any, D any, E any, F any, G any, H any, I any](world *World) *Map9[A, B, C, D, E, F, G, H, I]

NewMap9 creates a new Map9.

func (*Map9[A, B, C, D, E, F, G, H, I]) Add

func (m *Map9[A, B, C, D, E, F, G, H, I]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, rel ...Relation)

Add the mapped components to the given entity.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map9[A, B, C, D, E, F, G, H, I]) AddBatch

func (m *Map9[A, B, C, D, E, F, G, H, I]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, rel ...Relation)

AddBatch adds the mapped components to all entities matching the given batch filter.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

func (*Map9[A, B, C, D, E, F, G, H, I]) AddBatchFn

func (m *Map9[A, B, C, D, E, F, G, H, I]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I), rel ...Relation)

AddBatchFn adds the mapped components to all entities matching the given batch filter, running the given function on each. The function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map9[A, B, C, D, E, F, G, H, I]) AddFn

func (m *Map9[A, B, C, D, E, F, G, H, I]) AddFn(entity Entity, fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I), rel ...Relation)

AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map9[A, B, C, D, E, F, G, H, I]) Get

func (m *Map9[A, B, C, D, E, F, G, H, I]) Get(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H, *I)

Get returns the mapped components for the given entity.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map9[A, B, C, D, E, F, G, H, I]) GetRelation

func (m *Map9[A, B, C, D, E, F, G, H, I]) GetRelation(entity Entity, index int) Entity

GetRelation returns the relation target of an entity for the component at the given index.

func (*Map9[A, B, C, D, E, F, G, H, I]) GetRelationUnchecked

func (m *Map9[A, B, C, D, E, F, G, H, I]) GetRelationUnchecked(entity Entity, index int) Entity

GetRelationUnchecked returns the relation target of an entity for the component at the given index. In contrast to Map9.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (*Map9[A, B, C, D, E, F, G, H, I]) GetUnchecked

func (m *Map9[A, B, C, D, E, F, G, H, I]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H, *I)

GetUnchecked returns the mapped components for the given entity. In contrast to Map9.Get, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

Return nil for components the entity is missing.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map9[A, B, C, D, E, F, G, H, I]) HasAll

func (m *Map9[A, B, C, D, E, F, G, H, I]) HasAll(entity Entity) bool

HasAll return whether the given entity has all mapped components.

Using Map9.Get and checking for nil pointer may be faster than calling Map9.HasAll and Map9.Get subsequently.

func (*Map9[A, B, C, D, E, F, G, H, I]) New

func (_ *Map9[A, B, C, D, E, F, G, H, I]) New(world *World) *Map9[A, B, C, D, E, F, G, H, I]

New creates a new Map9. It is safe to call on `nil` instance. It is a helper method, intended to avoid repeated listing of type parameters.

See Map2.New for an example.

func (*Map9[A, B, C, D, E, F, G, H, I]) NewBatch

func (m *Map9[A, B, C, D, E, F, G, H, I]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, rel ...Relation)

NewBatch creates a batch of new entities with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map9[A, B, C, D, E, F, G, H, I]) NewBatchFn

func (m *Map9[A, B, C, D, E, F, G, H, I]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I), rel ...Relation)

NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each. The initializer function can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map9[A, B, C, D, E, F, G, H, I]) NewEntity

func (m *Map9[A, B, C, D, E, F, G, H, I]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I, rel ...Relation) Entity

NewEntity creates a new entity with the mapped components.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

func (*Map9[A, B, C, D, E, F, G, H, I]) NewEntityFn

func (m *Map9[A, B, C, D, E, F, G, H, I]) NewEntityFn(fn func(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I), rel ...Relation) Entity

NewEntityFn creates a new entity with the mapped component and runs a callback instead of using a component for initialization. The callback can be nil.

For each mapped component that is a relationships (see RelationMarker), a relation target entity must be provided via the variadic arguments.

⚠️ Do not store the obtained pointers outside of the current context!

func (*Map9[A, B, C, D, E, F, G, H, I]) Remove

func (m *Map9[A, B, C, D, E, F, G, H, I]) Remove(entity Entity)

Remove the mapped components from the given entity.

func (*Map9[A, B, C, D, E, F, G, H, I]) RemoveBatch

func (m *Map9[A, B, C, D, E, F, G, H, I]) RemoveBatch(batch *Batch, fn func(entity Entity))

RemoveBatch removes the mapped components from all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*Map9[A, B, C, D, E, F, G, H, I]) Set

func (m *Map9[A, B, C, D, E, F, G, H, I]) Set(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, i *I)

Set the mapped components of the given entity to the given values.

Requires the entity to already have all the mapped components. This is not a component operation, so it can be performed on a locked world.

func (*Map9[A, B, C, D, E, F, G, H, I]) SetRelations

func (m *Map9[A, B, C, D, E, F, G, H, I]) SetRelations(entity Entity, rel ...Relation)

SetRelations sets relation targets for the given entity.

func (*Map9[A, B, C, D, E, F, G, H, I]) SetRelationsBatch

func (m *Map9[A, B, C, D, E, F, G, H, I]) SetRelationsBatch(batch *Batch, fn func(entity Entity), rel ...Relation)

SetRelationsBatch sets relation targets for all entities matching the given batch filter.

type Query0

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

Query0 is a query for 0 components. Use a Filter0 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

See Query2 for a usage example.

func (*Query0) Close

func (q *Query0) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query0) Count

func (q *Query0) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

See Query2.Count for an example.

func (*Query0) Entity

func (q *Query0) Entity() Entity

Entity returns the current entity.

func (*Query0) EntityAt

func (q *Query0) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query0.Next instead.

Panics if the index is out of range, as indicated by Query0.Count.

See Query2.EntityAt for an example.

func (*Query0) Next

func (q *Query0) Next() bool

Next advances the query's cursor to the next entity.

type Query1

type Query1[A any] struct {
	// contains filtered or unexported fields
}

Query1 is a query for 1 components. Use a Filter1 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

See Query2 for a usage example.

func (*Query1[A]) Close

func (q *Query1[A]) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query1[A]) Count

func (q *Query1[A]) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

See Query2.Count for an example.

func (*Query1[A]) Entity

func (q *Query1[A]) Entity() Entity

Entity returns the current entity.

func (*Query1[A]) EntityAt

func (q *Query1[A]) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query1.Next instead.

Panics if the index is out of range, as indicated by Query1.Count.

See Query2.EntityAt for an example.

func (*Query1[A]) Get

func (q *Query1[A]) Get() *A

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointers outside of the current context (i.e. the query loop)!

func (*Query1[A]) GetRelation

func (q *Query1[A]) GetRelation(index int) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*Query1[A]) Next

func (q *Query1[A]) Next() bool

Next advances the query's cursor to the next entity.

type Query2

type Query2[A any, B any] struct {
	// contains filtered or unexported fields
}

Query2 is a query for 2 components. Use a Filter2 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

Example
world := ecs.NewWorld()

// A simple filter.
filter := ecs.NewFilter2[Position, Velocity](&world)

// Create a fresh query before iterating.
query := filter.Query()
for query.Next() {
	// Access components of the current entity.
	pos, vel := query.Get()
	// Access the current entity itself.
	entity := query.Entity()
	// ...
	_, _, _ = pos, vel, entity
}

func (*Query2[A, B]) Close

func (q *Query2[A, B]) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query2[A, B]) Count

func (q *Query2[A, B]) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

Example
world := ecs.NewWorld()

// Create a filter.
filter := ecs.NewFilter2[Position, Velocity](&world)

// Query the filter
query := filter.Query()

// Get the number of entities matching the query
count := query.Count()

// Close the query
// This is required if the query is not iterated
query.Close()

_ = count

func (*Query2[A, B]) Entity

func (q *Query2[A, B]) Entity() Entity

Entity returns the current entity.

func (*Query2[A, B]) EntityAt

func (q *Query2[A, B]) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query2.Next instead.

Panics if the index is out of range, as indicated by Query2.Count.

Example
world := ecs.NewWorld()

// Create a filter.
filter := ecs.NewFilter2[Position, Velocity](&world)

// Query the filter
query := filter.Query()

// Get the number of entities matching the query
count := query.Count()

// Get random entities from the query
e1 := query.EntityAt(rand.IntN(count))
e2 := query.EntityAt(rand.IntN(count))
e3 := query.EntityAt(rand.IntN(count))

// Close the query
// This is required if the query is not iterated
query.Close()

_, _, _ = e1, e2, e3

func (*Query2[A, B]) Get

func (q *Query2[A, B]) Get() (*A, *B)

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointers outside of the current context (i.e. the query loop)!

func (*Query2[A, B]) GetRelation

func (q *Query2[A, B]) GetRelation(index int) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*Query2[A, B]) Next

func (q *Query2[A, B]) Next() bool

Next advances the query's cursor to the next entity.

type Query3

type Query3[A any, B any, C any] struct {
	// contains filtered or unexported fields
}

Query3 is a query for 3 components. Use a Filter3 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

See Query2 for a usage example.

func (*Query3[A, B, C]) Close

func (q *Query3[A, B, C]) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query3[A, B, C]) Count

func (q *Query3[A, B, C]) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

See Query2.Count for an example.

func (*Query3[A, B, C]) Entity

func (q *Query3[A, B, C]) Entity() Entity

Entity returns the current entity.

func (*Query3[A, B, C]) EntityAt

func (q *Query3[A, B, C]) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query3.Next instead.

Panics if the index is out of range, as indicated by Query3.Count.

See Query2.EntityAt for an example.

func (*Query3[A, B, C]) Get

func (q *Query3[A, B, C]) Get() (*A, *B, *C)

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointers outside of the current context (i.e. the query loop)!

func (*Query3[A, B, C]) GetRelation

func (q *Query3[A, B, C]) GetRelation(index int) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*Query3[A, B, C]) Next

func (q *Query3[A, B, C]) Next() bool

Next advances the query's cursor to the next entity.

type Query4

type Query4[A any, B any, C any, D any] struct {
	// contains filtered or unexported fields
}

Query4 is a query for 4 components. Use a Filter4 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

See Query2 for a usage example.

func (*Query4[A, B, C, D]) Close

func (q *Query4[A, B, C, D]) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query4[A, B, C, D]) Count

func (q *Query4[A, B, C, D]) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

See Query2.Count for an example.

func (*Query4[A, B, C, D]) Entity

func (q *Query4[A, B, C, D]) Entity() Entity

Entity returns the current entity.

func (*Query4[A, B, C, D]) EntityAt

func (q *Query4[A, B, C, D]) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query4.Next instead.

Panics if the index is out of range, as indicated by Query4.Count.

See Query2.EntityAt for an example.

func (*Query4[A, B, C, D]) Get

func (q *Query4[A, B, C, D]) Get() (*A, *B, *C, *D)

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointers outside of the current context (i.e. the query loop)!

func (*Query4[A, B, C, D]) GetRelation

func (q *Query4[A, B, C, D]) GetRelation(index int) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*Query4[A, B, C, D]) Next

func (q *Query4[A, B, C, D]) Next() bool

Next advances the query's cursor to the next entity.

type Query5

type Query5[A any, B any, C any, D any, E any] struct {
	// contains filtered or unexported fields
}

Query5 is a query for 5 components. Use a Filter5 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

See Query2 for a usage example.

func (*Query5[A, B, C, D, E]) Close

func (q *Query5[A, B, C, D, E]) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query5[A, B, C, D, E]) Count

func (q *Query5[A, B, C, D, E]) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

See Query2.Count for an example.

func (*Query5[A, B, C, D, E]) Entity

func (q *Query5[A, B, C, D, E]) Entity() Entity

Entity returns the current entity.

func (*Query5[A, B, C, D, E]) EntityAt

func (q *Query5[A, B, C, D, E]) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query5.Next instead.

Panics if the index is out of range, as indicated by Query5.Count.

See Query2.EntityAt for an example.

func (*Query5[A, B, C, D, E]) Get

func (q *Query5[A, B, C, D, E]) Get() (*A, *B, *C, *D, *E)

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointers outside of the current context (i.e. the query loop)!

func (*Query5[A, B, C, D, E]) GetRelation

func (q *Query5[A, B, C, D, E]) GetRelation(index int) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*Query5[A, B, C, D, E]) Next

func (q *Query5[A, B, C, D, E]) Next() bool

Next advances the query's cursor to the next entity.

type Query6

type Query6[A any, B any, C any, D any, E any, F any] struct {
	// contains filtered or unexported fields
}

Query6 is a query for 6 components. Use a Filter6 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

See Query2 for a usage example.

func (*Query6[A, B, C, D, E, F]) Close

func (q *Query6[A, B, C, D, E, F]) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query6[A, B, C, D, E, F]) Count

func (q *Query6[A, B, C, D, E, F]) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

See Query2.Count for an example.

func (*Query6[A, B, C, D, E, F]) Entity

func (q *Query6[A, B, C, D, E, F]) Entity() Entity

Entity returns the current entity.

func (*Query6[A, B, C, D, E, F]) EntityAt

func (q *Query6[A, B, C, D, E, F]) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query6.Next instead.

Panics if the index is out of range, as indicated by Query6.Count.

See Query2.EntityAt for an example.

func (*Query6[A, B, C, D, E, F]) Get

func (q *Query6[A, B, C, D, E, F]) Get() (*A, *B, *C, *D, *E, *F)

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointers outside of the current context (i.e. the query loop)!

func (*Query6[A, B, C, D, E, F]) GetRelation

func (q *Query6[A, B, C, D, E, F]) GetRelation(index int) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*Query6[A, B, C, D, E, F]) Next

func (q *Query6[A, B, C, D, E, F]) Next() bool

Next advances the query's cursor to the next entity.

type Query7

type Query7[A any, B any, C any, D any, E any, F any, G any] struct {
	// contains filtered or unexported fields
}

Query7 is a query for 7 components. Use a Filter7 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

See Query2 for a usage example.

func (*Query7[A, B, C, D, E, F, G]) Close

func (q *Query7[A, B, C, D, E, F, G]) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query7[A, B, C, D, E, F, G]) Count

func (q *Query7[A, B, C, D, E, F, G]) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

See Query2.Count for an example.

func (*Query7[A, B, C, D, E, F, G]) Entity

func (q *Query7[A, B, C, D, E, F, G]) Entity() Entity

Entity returns the current entity.

func (*Query7[A, B, C, D, E, F, G]) EntityAt

func (q *Query7[A, B, C, D, E, F, G]) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query7.Next instead.

Panics if the index is out of range, as indicated by Query7.Count.

See Query2.EntityAt for an example.

func (*Query7[A, B, C, D, E, F, G]) Get

func (q *Query7[A, B, C, D, E, F, G]) Get() (*A, *B, *C, *D, *E, *F, *G)

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointers outside of the current context (i.e. the query loop)!

func (*Query7[A, B, C, D, E, F, G]) GetRelation

func (q *Query7[A, B, C, D, E, F, G]) GetRelation(index int) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*Query7[A, B, C, D, E, F, G]) Next

func (q *Query7[A, B, C, D, E, F, G]) Next() bool

Next advances the query's cursor to the next entity.

type Query8

type Query8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
	// contains filtered or unexported fields
}

Query8 is a query for 8 components. Use a Filter8 to create one.

Queries are one-time use iterators and must be re-created each time before iterating.

See Query2 for a usage example.

func (*Query8[A, B, C, D, E, F, G, H]) Close

func (q *Query8[A, B, C, D, E, F, G, H]) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*Query8[A, B, C, D, E, F, G, H]) Count

func (q *Query8[A, B, C, D, E, F, G, H]) Count() int

Count counts the entities matching this query.

Has some overhead of iterating through archetypes. However, this is still much faster than manual counting via iteration.

Does not iterate or close the query.

See Query2.Count for an example.

func (*Query8[A, B, C, D, E, F, G, H]) Entity

func (q *Query8[A, B, C, D, E, F, G, H]) Entity() Entity

Entity returns the current entity.

func (*Query8[A, B, C, D, E, F, G, H]) EntityAt

func (q *Query8[A, B, C, D, E, F, G, H]) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use Query8.Next instead.

Panics if the index is out of range, as indicated by Query8.Count.

See Query2.EntityAt for an example.

func (*Query8[A, B, C, D, E, F, G, H]) Get

func (q *Query8[A, B, C, D, E, F, G, H]) Get() (*A, *B, *C, *D, *E, *F, *G, *H)

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointers outside of the current context (i.e. the query loop)!

func (*Query8[A, B, C, D, E, F, G, H]) GetRelation

func (q *Query8[A, B, C, D, E, F, G, H]) GetRelation(index int) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*Query8[A, B, C, D, E, F, G, H]) Next

func (q *Query8[A, B, C, D, E, F, G, H]) Next() bool

Next advances the query's cursor to the next entity.

type Relation

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

Relation is the common type for specifying relationship targets. It can be created with Rel, RelIdx and RelID.

  • Rel is safe, but has some run-time overhead for component ID lookup.
  • RelIdx is fast but more error-prone.
  • RelID is used in the Unsafe API.

func Rel

func Rel[C any](target Entity) Relation

Rel creates a new Relation for a component type.

It can be used as a safer but slower alternative to RelIdx. Required a component ID lookup when used the first time. Un reuse, it is as fast as RelIdx.

Example
world := ecs.NewWorld()

// Create relation targets / parents
parent1 := world.NewEntity()
parent2 := world.NewEntity()

// Create a component mapper.
mapper := ecs.NewMap2[Position, ChildOf](&world)

// Create an entity, setting a relation target.
entity := mapper.NewEntity(&Position{}, &ChildOf{}, ecs.Rel[ChildOf](parent1))

// Change the entity's relation target.
mapper.SetRelations(entity, ecs.Rel[ChildOf](parent2))

func RelID

func RelID(id ID, target Entity) Relation

RelID creates a new Relation for a component ID.

It is used in Ark's unsafe, ID-based API.

func RelIdx

func RelIdx(index int, target Entity) Relation

RelIdx creates a new Relation for a component index.

It can be used as faster but less safe alternative to Rel.

Note that the index refers to the position of the component in the generics of e.g. a Map2 or Filter2. This should not be confused with component ID as obtained by ComponentID! For component IDs, use [RelationID].

Example
world := ecs.NewWorld()

// Create relation targets / parents
parent1 := world.NewEntity()
parent2 := world.NewEntity()

// Create a component mapper.
mapper := ecs.NewMap2[Position, ChildOf](&world)

// Create an entity, setting a relation target.
entity := mapper.NewEntity(&Position{}, &ChildOf{}, ecs.RelIdx(1, parent1))

// Change the entity's relation target.
mapper.SetRelations(entity, ecs.RelIdx(1, parent2))

type RelationMarker

type RelationMarker struct{}

RelationMarker is a marker for entity relation components. It must be embedded as first field of a component that represent an entity relationship (see the example).

Entity relations allow for fast queries using entity relationships. E.g. to iterate over all entities that are the child of a certain parent entity.

Example
package main

import (
	"fmt"

	"github.com/mlange-42/ark/ecs"
)

// ChildOf demonstrates how to define a relation component.
// There may be more fields _after_ the embed.
type ChildOf struct {
	ecs.RelationMarker
}

func main() {
	world := ecs.NewWorld()
	// Create a targets/parents entity for the relation.
	parent1 := world.NewEntity()
	parent2 := world.NewEntity()

	// Create a mapper for one or more components.
	mapper := ecs.NewMap1[ChildOf](&world)

	// Create a child entity with a relation to a parent.
	child1 := mapper.NewEntity(&ChildOf{}, ecs.RelIdx(0, parent1))
	// Create another child entity with a relation to a parent.
	// This version is slower than the above variant, but safer.
	_ = mapper.NewEntity(&ChildOf{}, ecs.Rel[ChildOf](parent2))

	// Set the relation target.
	mapper.SetRelations(child1, ecs.RelIdx(0, parent2))

	// Filter for the relation with a given target.
	filter := ecs.NewFilter1[ChildOf](&world)
	query := filter.Query(ecs.RelIdx(0, parent2))
	for query.Next() {
		fmt.Println(
			query.Entity(),
			query.GetRelation(0), // Get the relation target in a query
		)
	}
}
Output:

{5 0} {3 0}
{4 0} {3 0}

type ResID

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

ResID is the resource identifier. It is not relevant when using the default generic API.

func AddResource

func AddResource[T any](w *World, res *T) ResID

AddResource adds a resource to the world. Returns the ID for the added resource.

Panics if there is already such a resource.

Uses reflection. For more efficiency when used repeatedly, use Resource.

The number of resources per World is limited to 256 (64 with build tag ark_tiny).

See also GetResource.

Example
world := ecs.NewWorld()

gridResource := NewGrid(100, 100)
ecs.AddResource(&world, &gridResource)

func ResourceID

func ResourceID[T any](w *World) ResID

ResourceID returns the ResID for a resource type via generics. Registers the type if it is not already registered.

The number of resources per World is limited to 256 (64 with build tag ark_tiny).

func ResourceIDs

func ResourceIDs(w *World) []ResID

ResourceIDs returns a list of all registered resource IDs.

func ResourceTypeID

func ResourceTypeID(w *World, tp reflect.Type) ResID

ResourceTypeID returns the ResID for a resource type. Registers the type if it is not already registered.

See ResourceID for a more commonly used generic variant.

func (ResID) Index

func (id ResID) Index() uint8

Index returns the internal component index of this resource ID.

type Resource

type Resource[T any] struct {
	// contains filtered or unexported fields
}

Resource provides access to a world resource.

Create one with NewResource.

Example
// Create a world.
world := ecs.NewWorld()

// Create a resource.
gridResource := NewGrid(100, 100)
// Add it to the world.
ecs.AddResource(&world, &gridResource)

// Resource access in systems.
// Create and store a resource accessor.
gridAccess := ecs.NewResource[Grid](&world)

// Use the resource.
grid := gridAccess.Get()
entity := grid.Get(13, 42)
_ = entity

func NewResource

func NewResource[T any](w *World) Resource[T]

NewResource creates a new Resource mapper for a resource type. This does not add a resource to the world, but only creates a mapper for resource access!

See also World.Resources.

func (*Resource[T]) Add

func (g *Resource[T]) Add(res *T)

Add adds a resource to the world.

Panics if there is already a resource of the given type.

func (*Resource[T]) Get

func (g *Resource[T]) Get() *T

Get gets the resource of the given type.

Returns nil if there is no such resource.

func (*Resource[T]) Has

func (g *Resource[T]) Has() bool

Has returns whether the world has the resource type.

func (*Resource[T]) Remove

func (g *Resource[T]) Remove()

Remove removes a resource from the world.

Panics if there is no resource of the given type.

See also ecs.Resources.Remove.

type Resources

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

Resources manage a world's resources. Access it using World.Resources.

Although this type provides an ID-based API, the recommended usage is via Resource.

func (*Resources) Add

func (r *Resources) Add(id ResID, res any)

Add a resource to the world. The resource should always be a pointer.

Panics if there is already a resource of the given type.

See Resource.Add for the recommended type-safe way.

func (*Resources) Get

func (r *Resources) Get(id ResID) any

Get returns a pointer to the resource of the given type.

Returns nil if there is no such resource.

See Resource.Get for the recommended type-safe way.

func (*Resources) Has

func (r *Resources) Has(id ResID) bool

Has returns whether the world has the given resource.

See Resource.Has for the recommended type-safe way.

func (*Resources) Remove

func (r *Resources) Remove(id ResID)

Remove a resource from the world.

Panics if there is no resource of the given type.

See Resource.Remove for the recommended type-safe way.

type Unsafe

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

Unsafe provides access to Ark's unsafe ID-based API. Get an instance via World.Unsafe.

The unsafe API is significantly slower than the type-safe API, and should only be used when component types are not known at compile time.

func (Unsafe) Add

func (u Unsafe) Add(entity Entity, comp ...ID)

Add the given components to an entity.

func (Unsafe) AddRel

func (u Unsafe) AddRel(entity Entity, comps []ID, relations ...Relation)

AddRel adds the given components and relation targets to an entity.

func (Unsafe) DumpEntities

func (u Unsafe) DumpEntities() EntityDump

DumpEntities dumps entity information into an EntityDump object. This dump can be used with Unsafe.LoadEntities to set the World's entity state.

For world serialization with components and resources, see module github.com/mlange-42/ark-serde.

func (Unsafe) Exchange

func (u Unsafe) Exchange(entity Entity, add []ID, remove []ID, relations ...Relation)

Exchange the given components on entity.

func (Unsafe) Get

func (u Unsafe) Get(entity Entity, comp ID) unsafe.Pointer

Get returns a pointer to the given component of an Entity.

⚠️ Do not store the obtained pointer outside of the current context!

Panics if the entity does not have the given component. Panics when called for a removed (and potentially recycled) entity.

func (Unsafe) GetRelation

func (u Unsafe) GetRelation(entity Entity, comp ID) Entity

GetRelation returns the relation target for the entity and the mapped component.

func (Unsafe) GetRelationUnchecked

func (u Unsafe) GetRelationUnchecked(entity Entity, comp ID) Entity

GetRelationUnchecked returns the relation target for the entity and the mapped component. In contrast to Unsafe.GetRelation, it does not check whether the entity is alive. Can be used as an optimization when it is certain that the entity is alive.

func (Unsafe) GetUnchecked

func (u Unsafe) GetUnchecked(entity Entity, comp ID) unsafe.Pointer

GetUnchecked returns a pointer to the given component of an Entity. In contrast to Unsafe.Get, it does not check whether the entity is alive.

⚠️ Do not store the obtained pointer outside of the current context!

Panics if the entity does not have the given component.

func (Unsafe) Has

func (u Unsafe) Has(entity Entity, comp ID) bool

Has returns whether an Entity has the given component.

Panics when called for a removed (and potentially recycled) entity.

func (Unsafe) HasUnchecked

func (u Unsafe) HasUnchecked(entity Entity, comp ID) bool

HasUnchecked returns whether an Entity has the given component. In contrast to Unsafe.Has, it does not check whether the entity is alive.

Panics when called for a removed (and potentially recycled) entity.

func (Unsafe) IDs

func (u Unsafe) IDs(entity Entity) IDs

IDs returns all component IDs of an entity.

func (Unsafe) LoadEntities

func (u Unsafe) LoadEntities(data *EntityDump)

LoadEntities resets all entities to the state saved with Unsafe.DumpEntities.

Use this only on an empty world! Can be used after World.Reset.

The resulting world will have the same entities (in terms of ID, generation and alive state) as the original world. This is necessary for proper serialization of entity relations. However, the entities will not have any components.

Panics if the world has any dead or alive entities.

For world serialization with components and resources, see module github.com/mlange-42/ark-serde.

func (Unsafe) NewEntity

func (u Unsafe) NewEntity(ids ...ID) Entity

NewEntity creates a new entity with the given components.

func (Unsafe) NewEntityRel

func (u Unsafe) NewEntityRel(ids []ID, relations ...Relation) Entity

NewEntityRel creates a new entity with the given components and relation targets.

func (Unsafe) Remove

func (u Unsafe) Remove(entity Entity, comp ...ID)

Remove the given components from an entity.

func (Unsafe) SetRelations

func (u Unsafe) SetRelations(entity Entity, relations ...Relation)

SetRelations sets relation targets for an entity.

type UnsafeFilter

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

UnsafeFilter is a filter for components.

It is significantly slower than type-safe generic filters like Filter2, and should only be used when component types are not known at compile time.

func NewUnsafeFilter

func NewUnsafeFilter(world *World, ids ...ID) UnsafeFilter

NewUnsafeFilter creates a new UnsafeFilter matching the given components.

func (UnsafeFilter) Exclusive

func (f UnsafeFilter) Exclusive() UnsafeFilter

Exclusive makes the filter exclusive in the sense that the component composition is matched exactly, and no other components are allowed.

func (UnsafeFilter) Query

func (f UnsafeFilter) Query(relations ...Relation) UnsafeQuery

Query returns a new query matching this filter and the given entity relation targets.

func (UnsafeFilter) Without

func (f UnsafeFilter) Without(ids ...ID) UnsafeFilter

Without specifies components to exclude. Resets previous excludes.

type UnsafeQuery

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

UnsafeQuery is an unsafe query. It is significantly slower than type-safe generic queries like Query2, and should only be used when component types are not known at compile time.

func (*UnsafeQuery) Close

func (q *UnsafeQuery) Close()

Close closes the Query and unlocks the world.

Automatically called when iteration completes. Needs to be called only if breaking out of the query iteration or not iterating at all.

func (*UnsafeQuery) Count

func (q *UnsafeQuery) Count() int

Count returns the number of entities matching this query.

func (*UnsafeQuery) Entity

func (q *UnsafeQuery) Entity() Entity

Entity returns the current entity.

func (*UnsafeQuery) EntityAt

func (q *UnsafeQuery) EntityAt(index int) Entity

EntityAt returns the entity at a given index.

The method is particularly useful for random sampling of entities from a query. However, performance depends on the number of archetypes in the world and in the query. In worlds with many archetypes, it is recommended to use a registered/cached filter.

Do not use this to iterate a query! Use [Query.Next] instead.

Panics if the index is out of range, as indicated by [Query.Count].

func (*UnsafeQuery) Get

func (q *UnsafeQuery) Get(comp ID) unsafe.Pointer

Get returns the queried components of the current entity.

⚠️ Do not store the obtained pointer outside of the current context (i.e. the query loop)!

func (*UnsafeQuery) GetRelation

func (q *UnsafeQuery) GetRelation(comp ID) Entity

GetRelation returns the entity relation target of the component at the given index.

func (*UnsafeQuery) Has

func (q *UnsafeQuery) Has(comp ID) bool

Has returns whether the current entity has the given component.

func (*UnsafeQuery) IDs

func (q *UnsafeQuery) IDs() IDs

IDs returns the IDs of all component of the current [Entity]n.

func (*UnsafeQuery) Next

func (q *UnsafeQuery) Next() bool

Next advances the query's cursor to the next entity.

type World

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

World is the central type holding entity and component data, as well as resources.

func NewWorld

func NewWorld(initialCapacity ...int) World

NewWorld creates a new World.

Accepts zero, one or two arguments. The first argument is the initial capacity of the world, and of normal archetypes. The second argument is the initial capacity of relation archetypes. If only one argument is provided, it is used for both capacities. If no arguments are provided, the defaults are 1024 and 128, respectively.

func (*World) Alive

func (w *World) Alive(entity Entity) bool

Alive return whether the given entity is alive.

In Ark, entities are returned to a pool when they are removed from the world. These entities can be recycled, with the same ID (Entity.ID), but an incremented generation (Entity.Gen). This allows to determine whether an entity held by the user is still alive, despite it was potentially recycled.

func (*World) IsLocked

func (w *World) IsLocked() bool

IsLocked returns whether the world is locked by any queries.

func (*World) NewEntities

func (w *World) NewEntities(count int, fn func(entity Entity))

NewEntities creates a batch of new entities without any components, running the given callback function on each. The callback function can be nil.

func (*World) NewEntity

func (w *World) NewEntity() Entity

NewEntity creates a new Entity without any components.

func (*World) RemoveEntities

func (w *World) RemoveEntities(batch *Batch, fn func(entity Entity))

RemoveEntities removes all entities matching the given batch filter, running the given function on each. The function can be nil.

func (*World) RemoveEntity

func (w *World) RemoveEntity(entity Entity)

RemoveEntity removes the given entity from the world.

func (*World) Reset

func (w *World) Reset()

Reset removes all entities and resources from the world, and clears the filter cache.

Does NOT free reserved memory, remove archetypes, or clear the registry. However, it removes archetypes with a relation component.

Can be used to run systematic simulations without the need to re-allocate memory for each run. Accelerates re-populating the world by a factor of 2-3.

func (*World) Resources

func (w *World) Resources() *Resources

Resources of the world. Resources are component-like data that is not associated to an entity, but unique to the world.

See also Resource, AddResource and GetResource.

func (*World) Stats

func (w *World) Stats() *stats.World

Stats reports statistics for inspecting the World.

The underlying stats.World object is re-used and updated between calls. The returned pointer should thus not be stored for later analysis. Rather, the required data should be extracted immediately.

func (*World) Unsafe

func (w *World) Unsafe() Unsafe

Unsafe provides access to Ark's unsafe, ID-based API. For details, see Unsafe.

Directories

Path Synopsis
internal
generate command
Package generate contains code generation for queries and maps with a different number of generic parameters.
Package generate contains code generation for queries and maps with a different number of generic parameters.
Package stats provides the structs returned by ecs.World.Stats().
Package stats provides the structs returned by ecs.World.Stats().

Jump to

Keyboard shortcuts

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