Documentation
¶
Overview ¶
entity component system that is performant an easy to use.
The heart of this ECS is the memory pool Think of the pool like a database. On the Y axis (columns) there are arrays of components We use a struct called storage to hold the components arrays components can be any data type, but they cannot be interfaces These arrays are pre-allocated to a fixed size provided by the user an entity is just an index into these arrays So on the X axis there are entities which are just indexes The storage struct also has a bitset. each bit in the bitset corresponds to an entity the bitset is used for maintaining a record of which entity has the component the storage is storing The pool also has its own bitset that tracks which entities are alive there is also a map from entities to a slice of component storages we update this map when an entity has a component added to it we use this map to go into every storage and zero out the component when an entity is killed
Index ¶
- func Add[Component any](p *Pool, e Entity, c Component)
- func Add2[A any, B any](p *Pool, e Entity, c1 A, c2 B)
- func Add3[A any, B any, C any](p *Pool, e Entity, c1 A, c2 B, c3 C)
- func Add4[A any, B any, C any, D any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D)
- func Add5[A any, B any, C any, D any, E any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E)
- func Add6[A any, B any, C any, D any, E any, F any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E, c6 F)
- func Add7[A any, B any, C any, D any, E any, F any, G any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E, c6 F, c7 G)
- func Add8[A any, B any, C any, D any, E any, F any, G any, H any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E, c6 F, c7 G, c8 H)
- func Add9[A any, B any, C any, D any, E any, F any, G any, H any, I any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E, c6 F, c7 G, c8 H, c9 I)
- func GetGeneration(p *Pool, e Entity) uint32
- func GetStorage2[A any, B any](p *Pool) (*Storage[A], *Storage[B])
- func GetStorage3[A any, B any, C any](p *Pool) (*Storage[A], *Storage[B], *Storage[C])
- func GetStorage4[A any, B any, C any, D any](p *Pool) (*Storage[A], *Storage[B], *Storage[C], *Storage[D])
- func GetStorage5[A any, B any, C any, D any, E any](p *Pool) (*Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E])
- func GetStorage6[A any, B any, C any, D any, E any, F any](p *Pool) (*Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], *Storage[F])
- func GetStorage7[A any, B any, C any, D any, E any, F any, G any](p *Pool) (*Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], *Storage[F], ...)
- func GetStorage8[A any, B any, C any, D any, E any, F any, G any, H any](p *Pool) (*Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], *Storage[F], ...)
- func GetStorage9[A any, B any, C any, D any, E any, F any, G any, H any, I any](p *Pool) (*Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], *Storage[F], ...)
- func IsAlive(p *Pool, e Entity) bool
- func IsAliveWithGeneration(p *Pool, e Entity, generation Generation) bool
- func Kill(p *Pool, entities ...Entity)
- func Remove[Component any](p *Pool, e Entity)
- type Entity
- type Generation
- type Pool
- type Storage
- func (s *Storage[Component]) All() []Entity
- func (s *Storage[Component]) And(others ...storage) []Entity
- func (s *Storage[Component]) ButNot(others ...storage) []Entity
- func (s *Storage[Component]) EntityHasComponent(e Entity) bool
- func (s *Storage[Component]) Get(e Entity) Component
- func (s *Storage[Component]) Or(others ...storage) []Entity
- func (s *Storage[Component]) Update(e Entity, c Component)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add a component to an entity.
adding to a dead entity is a no-op. but note that this does not validate generations
func Add2 ¶
add 2 components to an entity automatically register component if ecs.AutoRegisterComponents is true (default) This is just a wrapper arround calling ecs.Add multiple times
func Add3 ¶
add 3 components to an entity automatically register component if ecs.AutoRegisterComponents is true (default) This is just a wrapper arround calling ecs.Add multiple times
func Add4 ¶ added in v1.3.1
add 4 components to an entity automatically register component if ecs.AutoRegisterComponents is true (default) This is just a wrapper arround calling ecs.Add multiple times
func Add5 ¶ added in v1.3.1
add 5 components to an entity automatically register component if ecs.AutoRegisterComponents is true (default) This is just a wrapper arround calling ecs.Add multiple times
func Add6 ¶ added in v1.3.1
func Add6[A any, B any, C any, D any, E any, F any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E, c6 F, )
add 6 components to an entity automatically register component if ecs.AutoRegisterComponents is true (default) This is just a wrapper arround calling ecs.Add multiple times
func Add7 ¶ added in v1.3.1
func Add7[A any, B any, C any, D any, E any, F any, G any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E, c6 F, c7 G, )
add 7 components to an entity automatically register component if ecs.AutoRegisterComponents is true (default) This is just a wrapper arround calling ecs.Add multiple times
func Add8 ¶ added in v1.3.1
func Add8[A any, B any, C any, D any, E any, F any, G any, H any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E, c6 F, c7 G, c8 H, )
add 8 components to an entity automatically register component if ecs.AutoRegisterComponents is true (default) This is just a wrapper arround calling ecs.Add multiple times
func Add9 ¶ added in v1.3.1
func Add9[A any, B any, C any, D any, E any, F any, G any, H any, I any](p *Pool, e Entity, c1 A, c2 B, c3 C, c4 D, c5 E, c6 F, c7 G, c8 H, c9 I, )
add 9 components to an entity automatically register component if ecs.AutoRegisterComponents is true (default) This is just a wrapper arround calling ecs.Add multiple times
func GetGeneration ¶ added in v1.2.5
You only need this if you are storing Entities within components
func GetStorage2 ¶
storage contains all components of a type This is just a wrapper arround calling ecs.GetStorage multiple times
func GetStorage3 ¶
storage contains all components of a type This is just a wrapper arround calling ecs.GetStorage multiple times
func GetStorage4 ¶
func GetStorage4[A any, B any, C any, D any](p *Pool) ( *Storage[A], *Storage[B], *Storage[C], *Storage[D], )
storage contains all components of a type This is just a wrapper arround calling ecs.GetStorage multiple times
func GetStorage5 ¶
func GetStorage5[A any, B any, C any, D any, E any](p *Pool) ( *Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], )
storage contains all components of a type This is just a wrapper arround calling ecs.GetStorage multiple times
func GetStorage6 ¶
func GetStorage6[A any, B any, C any, D any, E any, F any](p *Pool) ( *Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], *Storage[F])
storage contains all components of a type This is just a wrapper arround calling ecs.GetStorage multiple times
func GetStorage7 ¶
func GetStorage7[A any, B any, C any, D any, E any, F any, G any](p *Pool) ( *Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], *Storage[F], *Storage[G], )
storage contains all components of a type This is just a wrapper arround calling ecs.GetStorage multiple times
func GetStorage8 ¶
func GetStorage8[A any, B any, C any, D any, E any, F any, G any, H any](p *Pool) ( *Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], *Storage[F], *Storage[G], *Storage[H], )
storage contains all components of a type This is just a wrapper arround calling ecs.GetStorage multiple times
func GetStorage9 ¶
func GetStorage9[A any, B any, C any, D any, E any, F any, G any, H any, I any](p *Pool) ( *Storage[A], *Storage[B], *Storage[C], *Storage[D], *Storage[E], *Storage[F], *Storage[G], *Storage[H], *Storage[I], )
storage contains all components of a type This is just a wrapper arround calling ecs.GetStorage multiple times
func IsAlive ¶ added in v1.2.4
Check if an entity is alive.
This is not enough if you are storing entities within components
func IsAliveWithGeneration ¶ added in v1.2.7
func IsAliveWithGeneration(p *Pool, e Entity, generation Generation) bool
Check if internal generation for this Entity matches the generation you are storing
You only need this if you are storing entities
Types ¶
type Entity ¶
type Entity = uint32
An entity is just an integer. But if you are storing entities within components, then do not forget to also store their generation, and verify them using IsAliveWithGeneration before looping over said components
type Generation ¶ added in v1.4.0
type Generation = uint32
type Pool ¶
type Pool struct {
TotalEntities uint32
// contains filtered or unexported fields
}
The pool holds Component slices within storages and tracks entity lifetimes
type Storage ¶
A storage holds a slice of components
func GetStorage ¶
Get a component storage, allocate it if not already
func (*Storage[Component]) And ¶ added in v1.2.0
All entities that have this component and the other components
func (*Storage[Component]) ButNot ¶ added in v1.2.0
All entities that have this component but not the other components
func (*Storage[Component]) EntityHasComponent ¶
func (*Storage[Component]) Get ¶
get a copy of a component this does not check if the entity is alive