Documentation ¶
Overview ¶
Package ecs contains all of Arche's API.
Index ¶
- Constants
- func Add[A any](w *World, entity Entity) *A
- func Add2[A any, B any](w *World, entity Entity) (*A, *B)
- func Add3[A any, B any, C any](w *World, entity Entity) (*A, *B, *C)
- func Add4[A any, B any, C any, D any](w *World, entity Entity) (*A, *B, *C, *D)
- func Add5[A any, B any, C any, D any, E any](w *World, entity Entity) (*A, *B, *C, *D, *E)
- func Assign[A any](w *World, entity Entity, a *A) *A
- func Assign2[A any, B any](w *World, entity Entity, a *A, b *B) (*A, *B)
- func Assign3[A any, B any, C any](w *World, entity Entity, a *A, b *B, c *C) (*A, *B, *C)
- func Assign4[A any, B any, C any, D any](w *World, entity Entity, a *A, b *B, c *C, d *D) (*A, *B, *C, *D)
- func Assign5[A any, B any, C any, D any, E any](w *World, entity Entity, a *A, b *B, c *C, d *D, e *E) (*A, *B, *C, *D, *E)
- func Remove[A any](w *World, entity Entity)
- func Remove2[A any, B any](w *World, entity Entity)
- func Remove3[A any, B any, C any](w *World, entity Entity)
- func Remove4[A any, B any, C any, D any](w *World, entity Entity)
- func Remove5[A any, B any, C any, D any, E any](w *World, entity Entity)
- type Component
- type Config
- type Entity
- type ID
- type Map
- type Q1
- type Q2
- type Q3
- type Q4
- type Q5
- type Q6
- func (q *Q6[A, B, C, D, E, F]) Get1() *A
- func (q *Q6[A, B, C, D, E, F]) Get2() *B
- func (q *Q6[A, B, C, D, E, F]) Get3() *C
- func (q *Q6[A, B, C, D, E, F]) Get4() *D
- func (q *Q6[A, B, C, D, E, F]) Get5() *E
- func (q *Q6[A, B, C, D, E, F]) Get6() *F
- func (q *Q6[A, B, C, D, E, F]) GetAll() (*A, *B, *C, *D, *E, *F)
- type Q7
- func (q *Q7[A, B, C, D, E, F, G]) Get1() *A
- func (q *Q7[A, B, C, D, E, F, G]) Get2() *B
- func (q *Q7[A, B, C, D, E, F, G]) Get3() *C
- func (q *Q7[A, B, C, D, E, F, G]) Get4() *D
- func (q *Q7[A, B, C, D, E, F, G]) Get5() *E
- func (q *Q7[A, B, C, D, E, F, G]) Get6() *F
- func (q *Q7[A, B, C, D, E, F, G]) Get7() *G
- func (q *Q7[A, B, C, D, E, F, G]) GetAll() (*A, *B, *C, *D, *E, *F, *G)
- type Q8
- func (q *Q8[A, B, C, D, E, F, G, H]) Get1() *A
- func (q *Q8[A, B, C, D, E, F, G, H]) Get2() *B
- func (q *Q8[A, B, C, D, E, F, G, H]) Get3() *C
- func (q *Q8[A, B, C, D, E, F, G, H]) Get4() *D
- func (q *Q8[A, B, C, D, E, F, G, H]) Get5() *E
- func (q *Q8[A, B, C, D, E, F, G, H]) Get6() *F
- func (q *Q8[A, B, C, D, E, F, G, H]) Get7() *G
- func (q *Q8[A, B, C, D, E, F, G, H]) Get8() *H
- func (q *Q8[A, B, C, D, E, F, G, H]) GetAll() (*A, *B, *C, *D, *E, *F, *G, *H)
- type Query
- type World
- func (w *World) Add(entity Entity, comps ...ID)
- func (w *World) Alive(entity Entity) bool
- func (w *World) Assign(entity Entity, id ID, comp interface{}) unsafe.Pointer
- func (w *World) AssignN(entity Entity, comps ...Component)
- func (w *World) Exchange(entity Entity, add []ID, rem []ID)
- func (w *World) Get(entity Entity, comp ID) unsafe.Pointer
- func (w *World) Has(entity Entity, comp ID) bool
- func (w *World) IsLocked() bool
- func (w *World) NewEntity() Entity
- func (w *World) Query(comps ...ID) Query
- func (w *World) RemEntity(entity Entity)
- func (w *World) Remove(entity Entity, comps ...ID)
- func (w *World) Set(entity Entity, id ID, comp interface{}) unsafe.Pointer
Constants ¶
const MaskTotalBits = 64
MaskTotalBits is the size of Mask in bits.
It is the maximum number of component types that may exist in any World.
Variables ¶
This section is empty.
Functions ¶
func Assign ¶ added in v0.3.0
Assign adds a components to an entity.
See also World.Assign and World.AssignN.
func Assign2 ¶ added in v0.3.0
Assign2 adds two components to an entity.
See also World.Assign and World.AssignN.
func Assign3 ¶ added in v0.3.0
Assign3 adds three components to an entity.
See also World.Assign and World.AssignN.
func Assign4 ¶ added in v0.3.0
func Assign4[A any, B any, C any, D any](w *World, entity Entity, a *A, b *B, c *C, d *D) (*A, *B, *C, *D)
Assign4 adds four components to an entity.
See also World.Assign and World.AssignN.
func Assign5 ¶ added in v0.3.0
func Assign5[A any, B any, C any, D any, E any](w *World, entity Entity, a *A, b *B, c *C, d *D, e *E) (*A, *B, *C, *D, *E)
Assign5 adds four components to an entity.
See also World.Assign and World.AssignN.
func Remove2 ¶ added in v0.3.0
Remove2 removes two components from an entity.
See also World.Remove.
func Remove3 ¶ added in v0.3.0
Remove3 removes three components from an entity.
See also World.Remove.
func Remove4 ¶ added in v0.3.0
Remove4 removes four components from an entity.
See also World.Remove.
Types ¶
type Component ¶ added in v0.2.0
type Component struct { ID Component interface{} }
Component is a Component ID/Component pointer pair
type Config ¶ added in v0.1.3
type Config struct {
CapacityIncrement int
}
Config provides configuration for an ECS World.
func NewConfig ¶ added in v0.1.3
func NewConfig() Config
NewConfig creates a new default World config.
func (Config) WithCapacityIncrement ¶ added in v0.1.3
WithCapacityIncrement return a new Config with CapacityIncrement set. Use with method chaining.
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
Entity identifier. Holds an entity ID and it's generation for recycling.
Entities should only be created via the World, using World.NewEntity.
type ID ¶
type ID uint8
ID is the component identifier type
func ComponentID ¶
ComponentID returns the ID for a component type. Registers the type if it is not already registered.
type Map ¶ added in v0.3.0
type Map[T any] struct { // contains filtered or unexported fields }
Map provides a type-safe way to access a component type by entity ID.
Create one with NewMap.
func NewMap ¶ added in v0.3.0
NewMap creates a new Map for a component type.
Map provides a type-safe way to access a component type by entity ID.
func (*Map[T]) Get ¶ added in v0.3.0
Get gets the component for the given entity.
See also World.Get.
type Q1 ¶ added in v0.3.0
Q1 is a generic query for one component.
Create one with Query1
func Query1 ¶ added in v0.3.0
Query1 creates a generic query for one component.
See also World.Query.
type Q2 ¶ added in v0.3.0
Q2 is a generic query for two components.
Create one with Query2
func Query2 ¶ added in v0.3.0
Query2 creates a generic query for two components.
See also World.Query.
func (*Q2[A, B]) Get1 ¶ added in v0.3.0
func (q *Q2[A, B]) Get1() *A
Get1 returns the first queried component for the current query position
type Q3 ¶ added in v0.3.0
Q3 is a generic query for three components.
Create one with Query3
func Query3 ¶ added in v0.3.0
Query3 creates a generic query for three components.
See also World.Query.
func (*Q3[A, B, C]) Get1 ¶ added in v0.3.0
func (q *Q3[A, B, C]) Get1() *A
Get1 returns the first queried component for the current query position
func (*Q3[A, B, C]) Get2 ¶ added in v0.3.0
func (q *Q3[A, B, C]) Get2() *B
Get2 returns the second queried component for the current query position
type Q4 ¶ added in v0.3.0
Q4 is a generic query for four components.
Create one with Query4
func Query4 ¶ added in v0.3.0
Query4 creates a generic query for four components.
See also World.Query.
func (*Q4[A, B, C, D]) Get1 ¶ added in v0.3.0
func (q *Q4[A, B, C, D]) Get1() *A
Get1 returns the first queried component for the current query position
func (*Q4[A, B, C, D]) Get2 ¶ added in v0.3.0
func (q *Q4[A, B, C, D]) Get2() *B
Get2 returns the second queried component for the current query position
func (*Q4[A, B, C, D]) Get3 ¶ added in v0.3.0
func (q *Q4[A, B, C, D]) Get3() *C
Get3 returns the third queried component for the current query position
type Q5 ¶ added in v0.3.0
type Q5[A any, B any, C any, D any, E any] struct { Query // contains filtered or unexported fields }
Q5 is a generic query for five components.
Create one with Query5
func Query5 ¶ added in v0.3.0
Query5 creates a generic query for five components.
See also World.Query.
func (*Q5[A, B, C, D, E]) Get1 ¶ added in v0.3.0
func (q *Q5[A, B, C, D, E]) Get1() *A
Get1 returns the first queried component for the current query position
func (*Q5[A, B, C, D, E]) Get2 ¶ added in v0.3.0
func (q *Q5[A, B, C, D, E]) Get2() *B
Get2 returns the second queried component for the current query position
func (*Q5[A, B, C, D, E]) Get3 ¶ added in v0.3.0
func (q *Q5[A, B, C, D, E]) Get3() *C
Get3 returns the third queried component for the current query position
func (*Q5[A, B, C, D, E]) Get4 ¶ added in v0.3.0
func (q *Q5[A, B, C, D, E]) Get4() *D
Get4 returns the fourth queried component for the current query position
type Q6 ¶ added in v0.3.0
type Q6[A any, B any, C any, D any, E any, F any] struct { Query // contains filtered or unexported fields }
Q6 is a generic query for six components.
Create one with Query6
func Query6 ¶ added in v0.3.0
Query6 creates a generic query for six components.
See also World.Query.
func (*Q6[A, B, C, D, E, F]) Get1 ¶ added in v0.3.0
func (q *Q6[A, B, C, D, E, F]) Get1() *A
Get1 returns the first queried component for the current query position
func (*Q6[A, B, C, D, E, F]) Get2 ¶ added in v0.3.0
func (q *Q6[A, B, C, D, E, F]) Get2() *B
Get2 returns the second queried component for the current query position
func (*Q6[A, B, C, D, E, F]) Get3 ¶ added in v0.3.0
func (q *Q6[A, B, C, D, E, F]) Get3() *C
Get3 returns the third queried component for the current query position
func (*Q6[A, B, C, D, E, F]) Get4 ¶ added in v0.3.0
func (q *Q6[A, B, C, D, E, F]) Get4() *D
Get4 returns the fourth queried component for the current query position
func (*Q6[A, B, C, D, E, F]) Get5 ¶ added in v0.3.0
func (q *Q6[A, B, C, D, E, F]) Get5() *E
Get5 returns the fifth queried component for the current query position
type Q7 ¶ added in v0.3.0
type Q7[A any, B any, C any, D any, E any, F any, G any] struct { Query // contains filtered or unexported fields }
Q7 is a generic query for seven components.
Create one with Query7
func Query7 ¶ added in v0.3.0
Query7 creates a generic query for seven components.
See also World.Query.
func (*Q7[A, B, C, D, E, F, G]) Get1 ¶ added in v0.3.0
func (q *Q7[A, B, C, D, E, F, G]) Get1() *A
Get1 returns the first queried component for the current query position
func (*Q7[A, B, C, D, E, F, G]) Get2 ¶ added in v0.3.0
func (q *Q7[A, B, C, D, E, F, G]) Get2() *B
Get2 returns the second queried component for the current query position
func (*Q7[A, B, C, D, E, F, G]) Get3 ¶ added in v0.3.0
func (q *Q7[A, B, C, D, E, F, G]) Get3() *C
Get3 returns the third queried component for the current query position
func (*Q7[A, B, C, D, E, F, G]) Get4 ¶ added in v0.3.0
func (q *Q7[A, B, C, D, E, F, G]) Get4() *D
Get4 returns the fourth queried component for the current query position
func (*Q7[A, B, C, D, E, F, G]) Get5 ¶ added in v0.3.0
func (q *Q7[A, B, C, D, E, F, G]) Get5() *E
Get5 returns the fifth queried component for the current query position
func (*Q7[A, B, C, D, E, F, G]) Get6 ¶ added in v0.3.0
func (q *Q7[A, B, C, D, E, F, G]) Get6() *F
Get6 returns the sixth queried component for the current query position
type Q8 ¶ added in v0.3.0
type Q8[A any, B any, C any, D any, E any, F any, G any, H any] struct { Query // contains filtered or unexported fields }
Q8 is a generic query for seven components.
Create one with Query8
func Query8 ¶ added in v0.3.0
func Query8[A any, B any, C any, D any, E any, F any, G any, H any](w *World) Q8[A, B, C, D, E, F, G, H]
Query8 creates a generic query for seven components.
See also World.Query.
func (*Q8[A, B, C, D, E, F, G, H]) Get1 ¶ added in v0.3.0
func (q *Q8[A, B, C, D, E, F, G, H]) Get1() *A
Get1 returns the first queried component for the current query position
func (*Q8[A, B, C, D, E, F, G, H]) Get2 ¶ added in v0.3.0
func (q *Q8[A, B, C, D, E, F, G, H]) Get2() *B
Get2 returns the second queried component for the current query position
func (*Q8[A, B, C, D, E, F, G, H]) Get3 ¶ added in v0.3.0
func (q *Q8[A, B, C, D, E, F, G, H]) Get3() *C
Get3 returns the third queried component for the current query position
func (*Q8[A, B, C, D, E, F, G, H]) Get4 ¶ added in v0.3.0
func (q *Q8[A, B, C, D, E, F, G, H]) Get4() *D
Get4 returns the fourth queried component for the current query position
func (*Q8[A, B, C, D, E, F, G, H]) Get5 ¶ added in v0.3.0
func (q *Q8[A, B, C, D, E, F, G, H]) Get5() *E
Get5 returns the fifth queried component for the current query position
func (*Q8[A, B, C, D, E, F, G, H]) Get6 ¶ added in v0.3.0
func (q *Q8[A, B, C, D, E, F, G, H]) Get6() *F
Get6 returns the sixth queried component for the current query position
func (*Q8[A, B, C, D, E, F, G, H]) Get7 ¶ added in v0.3.0
func (q *Q8[A, B, C, D, E, F, G, H]) Get7() *G
Get7 returns the seventh queried component for the current query position
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is an iterator to iterate entities.
Create queries through the World using World.Query. See also the generic variants Query1, Query2, Query3, ...
Example: ¶
query := world.Query(posID, rotID) for query.Next() { pos := (*position)(query.Get(posID)) pos.X += 1.0 }
func (*Query) Close ¶ added in v0.1.2
func (q *Query) Close()
Close closes the Query and unlocks the world.
Automatically called when iteration finishes. Needs to be called only if breaking out of the query iteration.
type World ¶
type World struct {
// contains filtered or unexported fields
}
World is the central type holding Entity and component data.
func FromConfig ¶ added in v0.1.3
func (*World) Add ¶
Add adds components to an Entity.
Panics when called on a locked world or for an already removed entity. Do not use during Query iteration!
func (*World) Assign ¶ added in v0.2.0
Assign assigns a component to an Entity, using a given pointer for the content. See also World.AssignN.
The passed component must be a pointer. Returns a pointer to the assigned memory. The passed in pointer is not a valid reference to that memory!
Panics when called on a locked world or for an already removed entity. Do not use during Query iteration!
func (*World) AssignN ¶ added in v0.2.0
AssignN assigns multiple components to an Entity, using pointers for the content. See also World.Assign.
The passed components must be pointers. The passed in pointers are no valid references to the assigned memory!
Panics when called on a locked world or for an already removed entity. Do not use during Query iteration!
func (*World) Exchange ¶ added in v0.2.0
Exchange adds and removes components in one pass
Panics when called on a locked world or for an already removed entity. Do not use during Query iteration!
func (*World) Get ¶
Get returns a pointer th the given component of an Entity.
Returns `nil` if the entity has no such component. Panics when called for an already removed entity.
See also Map.Get for a generic variant.
func (*World) Has ¶
Has returns whether an Entity has a given component.
Panics when called for an already removed entity.
See also Map.Has for a generic variant.
func (*World) IsLocked ¶ added in v0.1.2
IsLocked returns whether the world is locked by any queries.
func (*World) NewEntity ¶
NewEntity returns a new or recycled Entity.
Panics when called on a locked world. Do not use during Query iteration!
func (*World) Query ¶
Query creates a Query iterator for the given components.
Locks the world to prevent changes to component compositions.
func (*World) RemEntity ¶
RemEntity removes and recycles an Entity.
Panics when called on a locked world or for an already removed entity. Do not use during Query iteration!
func (*World) Remove ¶
Remove removes components from an entity.
Panics when called on a locked world or for an already removed entity.
Do not use during Query iteration!
func (*World) Set ¶ added in v0.3.0
Set overwrites a component for an Entity, using a given pointer for the content.
The passed component must be a pointer. Returns a pointer to the assigned memory. The passed in pointer is not a valid reference to that memory!
Panics when called on a locked world or for an already removed entity. Do not use during Query iteration!
Panics if the entity does not have a component of that type.
See also Map.Set for a generic variant.