Documentation
¶
Overview ¶
Package volt is an ECS for game development, based on the Archetype paradigm.
Index ¶
- Constants
- func AddComponent[T ComponentInterface](world *World, entityId EntityId, component T) error
- func AddComponents2[A, B ComponentInterface](world *World, entityId EntityId, a A, b B) error
- func AddComponents3[A, B, C ComponentInterface](world *World, entityId EntityId, a A, b B, c C) error
- func AddComponents4[A, B, C, D ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D) error
- func AddComponents5[A, B, C, D, E ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D, e E) error
- func AddComponents6[A, B, C, D, E, F ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D, e E, f F) error
- func AddComponents7[A, B, C, D, E, F, G ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D, e E, f F, g G) error
- func AddComponents8[A, B, C, D, E, F, G, H ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D, e E, f F, g G, h H) error
- func ConfigureComponent[T ComponentInterface](world *World, conf any) T
- func GetComponent[T ComponentInterface](world *World, entityId EntityId) *T
- func RegisterComponent[T ComponentInterface](world *World, config ComponentConfigInterface)
- func RemoveComponent[T ComponentInterface](world *World, entityId EntityId) error
- type ArchetypesComponentsEntities
- type ComponentBuilder
- type ComponentConfig
- type ComponentConfigInterface
- type ComponentId
- type ComponentIdConf
- type ComponentInterface
- type ComponentsRegister
- type ComponentsStorage
- type EntityId
- func CreateEntityWithComponents2[A, B ComponentInterface](world *World, name string, a A, b B) (EntityId, error)
- func CreateEntityWithComponents3[A, B, C ComponentInterface](world *World, name string, a A, b B, c C) (EntityId, error)
- func CreateEntityWithComponents4[A, B, C, D ComponentInterface](world *World, name string, a A, b B, c C, d D) (EntityId, error)
- func CreateEntityWithComponents5[A, B, C, D, E ComponentInterface](world *World, name string, a A, b B, c C, d D, e E) (EntityId, error)
- func CreateEntityWithComponents6[A, B, C, D, E, F ComponentInterface](world *World, name string, a A, b B, c C, d D, e E, f F) (EntityId, error)
- func CreateEntityWithComponents7[A, B, C, D, E, F, G ComponentInterface](world *World, name string, a A, b B, c C, d D, e E, f F, g G) (EntityId, error)
- func CreateEntityWithComponents8[A, B, C, D, E, F, G, H ComponentInterface](world *World, name string, a A, b B, c C, d D, e E, f F, g G, h H) (EntityId, error)
- type OptionalComponent
- type Query1
- func (query *Query1[A]) Count() int
- func (query *Query1[A]) Foreach(filterFn func(QueryResult1[A]) bool) iter.Seq[QueryResult1[A]]
- func (query *Query1[A]) ForeachChannel(chunkSize int, filterFn func(QueryResult1[A]) bool) <-chan iter.Seq[QueryResult1[A]]
- func (query *Query1[A]) GetComponentsIds() []ComponentId
- func (query *Query1[A]) GetEntitiesIds() []EntityId
- type Query2
- func (query *Query2[A, B]) Count() int
- func (query *Query2[A, B]) Foreach(filterFn func(QueryResult2[A, B]) bool) iter.Seq[QueryResult2[A, B]]
- func (query *Query2[A, B]) ForeachChannel(chunkSize int, filterFn func(QueryResult2[A, B]) bool) <-chan iter.Seq[QueryResult2[A, B]]
- func (query *Query2[A, B]) GetComponentsIds() []ComponentId
- func (query *Query2[A, B]) GetEntitiesIds() []EntityId
- type Query3
- func (query *Query3[A, B, C]) Count() int
- func (query *Query3[A, B, C]) Foreach(filterFn func(QueryResult3[A, B, C]) bool) iter.Seq[QueryResult3[A, B, C]]
- func (query *Query3[A, B, C]) ForeachChannel(chunkSize int, filterFn func(QueryResult3[A, B, C]) bool) <-chan iter.Seq[QueryResult3[A, B, C]]
- func (query *Query3[A, B, C]) GetComponentsIds() []ComponentId
- func (query *Query3[A, B, C]) GetEntitiesIds() []EntityId
- type Query4
- func (query *Query4[A, B, C, D]) Count() int
- func (query *Query4[A, B, C, D]) Foreach(filterFn func(QueryResult4[A, B, C, D]) bool) iter.Seq[QueryResult4[A, B, C, D]]
- func (query *Query4[A, B, C, D]) ForeachChannel(chunkSize int, filterFn func(QueryResult4[A, B, C, D]) bool) <-chan iter.Seq[QueryResult4[A, B, C, D]]
- func (query *Query4[A, B, C, D]) GetComponentsIds() []ComponentId
- func (query *Query4[A, B, C, D]) GetEntitiesIds() []EntityId
- type Query5
- func (query *Query5[A, B, C, D, E]) Count() int
- func (query *Query5[A, B, C, D, E]) Foreach(filterFn func(QueryResult5[A, B, C, D, E]) bool) iter.Seq[QueryResult5[A, B, C, D, E]]
- func (query *Query5[A, B, C, D, E]) ForeachChannel(chunkSize int, filterFn func(QueryResult5[A, B, C, D, E]) bool) <-chan iter.Seq[QueryResult5[A, B, C, D, E]]
- func (query *Query5[A, B, C, D, E]) GetComponentsIds() []ComponentId
- func (query *Query5[A, B, C, D, E]) GetEntitiesIds() []EntityId
- type Query6
- func (query *Query6[A, B, C, D, E, F]) Count() int
- func (query *Query6[A, B, C, D, E, F]) Foreach(filterFn func(QueryResult6[A, B, C, D, E, F]) bool) iter.Seq[QueryResult6[A, B, C, D, E, F]]
- func (query *Query6[A, B, C, D, E, F]) ForeachChannel(chunkSize int, filterFn func(QueryResult6[A, B, C, D, E, F]) bool) <-chan iter.Seq[QueryResult6[A, B, C, D, E, F]]
- func (query *Query6[A, B, C, D, E, F]) GetComponentsIds() []ComponentId
- func (query *Query6[A, B, C, D, E, F]) GetEntitiesIds() []EntityId
- type Query7
- func (query *Query7[A, B, C, D, E, F, G]) Count() int
- func (query *Query7[A, B, C, D, E, F, G]) Foreach(filterFn func(QueryResult7[A, B, C, D, E, F, G]) bool) iter.Seq[QueryResult7[A, B, C, D, E, F, G]]
- func (query *Query7[A, B, C, D, E, F, G]) ForeachChannel(chunkSize int, filterFn func(QueryResult7[A, B, C, D, E, F, G]) bool) <-chan iter.Seq[QueryResult7[A, B, C, D, E, F, G]]
- func (query *Query7[A, B, C, D, E, F, G]) GetComponentsIds() []ComponentId
- func (query *Query7[A, B, C, D, E, F, G]) GetEntitiesIds() []EntityId
- type Query8
- func (query *Query8[A, B, C, D, E, F, G, H]) Count() int
- func (query *Query8[A, B, C, D, E, F, G, H]) Foreach(filterFn func(QueryResult8[A, B, C, D, E, F, G, H]) bool) iter.Seq[QueryResult8[A, B, C, D, E, F, G, H]]
- func (query *Query8[A, B, C, D, E, F, G, H]) ForeachChannel(chunkSize int, filterFn func(QueryResult8[A, B, C, D, E, F, G, H]) bool) <-chan iter.Seq[QueryResult8[A, B, C, D, E, F, G, H]]
- func (query *Query8[A, B, C, D, E, F, G, H]) GetComponentsIds() []ComponentId
- func (query *Query8[A, B, C, D, E, F, G, H]) GetEntitiesIds() []EntityId
- type QueryConfiguration
- type QueryResult1
- type QueryResult2
- type QueryResult3
- type QueryResult4
- type QueryResult5
- type QueryResult6
- type QueryResult7
- type QueryResult8
- type TagId
- type World
- func (world *World) AddComponent(entityId EntityId, componentId ComponentId, conf any) error
- func (world *World) AddComponents(entityId EntityId, componentsIdsConfs ...ComponentIdConf) error
- func (world *World) AddTag(tagId TagId, entityId EntityId) error
- func (world *World) Count() int
- func (world *World) CreateEntity(name string) EntityId
- func (world *World) GetComponent(entityId EntityId, componentId ComponentId) (any, error)
- func (world *World) GetEntityName(entityId EntityId) string
- func (world *World) HasComponents(entityId EntityId, componentsIds ...ComponentId) bool
- func (world *World) HasTag(tagId TagId, entityId EntityId) bool
- func (world *World) PublishEntity(entityId EntityId)
- func (world *World) RemoveComponent(entityId EntityId, componentId ComponentId) error
- func (world *World) RemoveEntity(entityId EntityId)
- func (world *World) RemoveTag(tagId TagId, entityId EntityId) error
- func (world *World) SearchEntity(name string) EntityId
- func (world *World) SetComponentAddedFn(componentAddedFn func(entityId EntityId, componentId ComponentId))
- func (world *World) SetComponentRemovedFn(componentRemovedFn func(entityId EntityId, componentId ComponentId))
- func (world *World) SetEntityAddedFn(entityAddedFn func(entityId EntityId))
- func (world *World) SetEntityName(entityId EntityId, name string)
- func (world *World) SetEntityRemovedFn(entityRemovedFn func(entityId EntityId))
Constants ¶
const COMPONENTS_INDICES = 0
const TAGS_INDICES = 2048
Variables ¶
This section is empty.
Functions ¶
func AddComponent ¶
func AddComponent[T ComponentInterface](world *World, entityId EntityId, component T) error
AddComponent adds the component T to the existing EntityId.
It returns an error if:
- the entity does not exist
- the entity has the component
- an internal error occurs
func AddComponents2 ¶
func AddComponents2[A, B ComponentInterface](world *World, entityId EntityId, a A, b B) error
AddComponents2 adds the components A, B to the existing EntityId.
It returns an error if:
- the entity does not exist
- the entity has one of the component
- an internal error occurs
This solution is faster than an atomic solution.
func AddComponents3 ¶
func AddComponents3[A, B, C ComponentInterface](world *World, entityId EntityId, a A, b B, c C) error
AddComponents3 adds the components A, B, C to the existing EntityId.
It returns an error if:
- the entity does not exist
- the entity has one of the component
- an internal error occurs
This solution is faster than an atomic solution.
func AddComponents4 ¶
func AddComponents4[A, B, C, D ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D) error
AddComponents4 adds the components A, B, C, D to the existing EntityId.
It returns an error if:
- the entity does not exist
- the entity has one of the component
- an internal error occurs
This solution is faster than an atomic solution.
func AddComponents5 ¶
func AddComponents5[A, B, C, D, E ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D, e E) error
AddComponents5 adds the components A, B, C, D, E to the existing EntityId.
It returns an error if:
- the entity does not exist
- the entity has one of the component
- an internal error occurs
This solution is faster than an atomic solution.
func AddComponents6 ¶
func AddComponents6[A, B, C, D, E, F ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D, e E, f F) error
AddComponents6 adds the components A, B, C, D, E, F to the existing EntityId.
It returns an error if:
- the entity does not exist
- the entity has one of the component
- an internal error occurs
This solution is faster than an atomic solution.
func AddComponents7 ¶
func AddComponents7[A, B, C, D, E, F, G ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D, e E, f F, g G) error
AddComponents7 adds the components A, B, C, D, E, F, G to the existing EntityId.
It returns an error if:
- the entity does not exist
- the entity has one of the component
- an internal error occurs
This solution is faster than an atomic solution.
func AddComponents8 ¶
func AddComponents8[A, B, C, D, E, F, G, H ComponentInterface](world *World, entityId EntityId, a A, b B, c C, d D, e E, f F, g G, h H) error
AddComponents8 adds the components A, B, C, D, E, F, G, H to the existing EntityId.
It returns an error if:
- the entity does not exist
- the entity has one of the component
- an internal error occurs
This solution is faster than an atomic solution.
func ConfigureComponent ¶
func ConfigureComponent[T ComponentInterface](world *World, conf any) T
ConfigureComponent configures a Component of type T using the build function related to it.
The parameter conf contains all the data required for the configuration.
func GetComponent ¶
func GetComponent[T ComponentInterface](world *World, entityId EntityId) *T
GetComponent returns a pointer to the component T owned by the entity.
If the entity does not have the component, it returns nil
func RegisterComponent ¶
func RegisterComponent[T ComponentInterface](world *World, config ComponentConfigInterface)
RegisterComponent adds a component T to the registry of the given World.
Once the component is registered, it can be added to an entity.
func RemoveComponent ¶
func RemoveComponent[T ComponentInterface](world *World, entityId EntityId) error
RemoveComponent removes the component to EntityId.
It returns an error if the EntityId does not have the component.
Types ¶
type ArchetypesComponentsEntities ¶
type ArchetypesComponentsEntities[T ComponentInterface] map[archetypeId][]T
type ComponentBuilder ¶
ComponentBuilder is the function called to set the properties of a given component.
A type assertion is required on component and configuration parameters.
type ComponentConfig ¶
type ComponentConfig[T ComponentInterface] struct { BuilderFn ComponentBuilder // contains filtered or unexported fields }
Configuration for a component T.
BuilderFn defines the function called to set a new component.
type ComponentConfigInterface ¶
type ComponentConfigInterface interface {
// contains filtered or unexported methods
}
ComponentConfigInterface is the interface defining the method required to create a new Component.
type ComponentIdConf ¶ added in v1.6.0
type ComponentIdConf struct { ComponentId // contains filtered or unexported fields }
type ComponentInterface ¶
type ComponentInterface interface {
GetComponentId() ComponentId
}
ComponentInterface is the interface for all the Components.
It wraps the GetComponentId method, that returns a Component identifier.
type ComponentsRegister ¶
type ComponentsRegister map[ComponentId]ComponentConfigInterface
type ComponentsStorage ¶
type ComponentsStorage[T ComponentInterface] struct { // contains filtered or unexported fields }
type EntityId ¶
type EntityId id
Entity identifier in the world.
func CreateEntityWithComponents2 ¶
func CreateEntityWithComponents2[A, B ComponentInterface](world *World, name string, a A, b B) (EntityId, error)
CreateEntityWithComponents2 creates an entity in World; It sets the components A, B to the entity, for faster performances than the atomic version.
func CreateEntityWithComponents3 ¶
func CreateEntityWithComponents3[A, B, C ComponentInterface](world *World, name string, a A, b B, c C) (EntityId, error)
CreateEntityWithComponents3 creates an entity in World;
It sets the components A, B, C to the entity, for faster performances than the atomic version.
func CreateEntityWithComponents4 ¶
func CreateEntityWithComponents4[A, B, C, D ComponentInterface](world *World, name string, a A, b B, c C, d D) (EntityId, error)
CreateEntityWithComponents4 creates an entity in World;
It sets the components A, B, C, D to the entity, for faster performances than the atomic version.
func CreateEntityWithComponents5 ¶
func CreateEntityWithComponents5[A, B, C, D, E ComponentInterface](world *World, name string, a A, b B, c C, d D, e E) (EntityId, error)
CreateEntityWithComponents5 creates an entity in World;
It sets the components A, B, C, D, E to the entity, for faster performances than the atomic version.
func CreateEntityWithComponents6 ¶
func CreateEntityWithComponents6[A, B, C, D, E, F ComponentInterface](world *World, name string, a A, b B, c C, d D, e E, f F) (EntityId, error)
CreateEntityWithComponents6 creates an entity in World;
It sets the components A, B, C, D, E, F to the entity, for faster performances than the atomic version.
func CreateEntityWithComponents7 ¶
func CreateEntityWithComponents7[A, B, C, D, E, F, G ComponentInterface](world *World, name string, a A, b B, c C, d D, e E, f F, g G) (EntityId, error)
CreateEntityWithComponents7 creates an entity in World;
It sets the components A, B, C, D, E, F, G to the entity, for faster performances than the atomic version.
func CreateEntityWithComponents8 ¶
func CreateEntityWithComponents8[A, B, C, D, E, F, G, H ComponentInterface](world *World, name string, a A, b B, c C, d D, e E, f F, g G, h H) (EntityId, error)
CreateEntityWithComponents8 creates an entity in World;
It sets the components A, B, C, D, E, F, G, H to the entity, for faster performances than the atomic version.
type Query1 ¶
type Query1[A ComponentInterface] struct { World *World // contains filtered or unexported fields }
Query for 1 component type.
func CreateQuery1 ¶
func CreateQuery1[A ComponentInterface](world *World, queryConfiguration QueryConfiguration) Query1[A]
CreateQuery1 returns a new Query1, with component A.
func (*Query1[A]) Foreach ¶
func (query *Query1[A]) Foreach(filterFn func(QueryResult1[A]) bool) iter.Seq[QueryResult1[A]]
Foreach returns an iterator of QueryResult1 for all the entities with component A to which filterFn function returns true.
func (*Query1[A]) ForeachChannel ¶
func (query *Query1[A]) ForeachChannel(chunkSize int, filterFn func(QueryResult1[A]) bool) <-chan iter.Seq[QueryResult1[A]]
ForeachChannel returns a channel of iterators of QueryResult1 for all the entities with component A to which filterFn function returns true.
The parameter chunkSize defines the size of each iterators.
func (*Query1[A]) GetComponentsIds ¶
func (query *Query1[A]) GetComponentsIds() []ComponentId
func (*Query1[A]) GetEntitiesIds ¶
GetEntitiesIds returns a slice of all the EntityId fetched for Query1.
type Query2 ¶
type Query2[A, B ComponentInterface] struct { World *World // contains filtered or unexported fields }
Query for 2 components type.
func CreateQuery2 ¶
func CreateQuery2[A, B ComponentInterface](world *World, queryConfiguration QueryConfiguration) Query2[A, B]
CreateQuery2 returns a new Query2, with components A, B.
func (*Query2[A, B]) Foreach ¶
func (query *Query2[A, B]) Foreach(filterFn func(QueryResult2[A, B]) bool) iter.Seq[QueryResult2[A, B]]
Foreach returns an iterator of QueryResult2 for all the entities with components A, B to which filterFn function returns true.
func (*Query2[A, B]) ForeachChannel ¶
func (query *Query2[A, B]) ForeachChannel(chunkSize int, filterFn func(QueryResult2[A, B]) bool) <-chan iter.Seq[QueryResult2[A, B]]
ForeachChannel returns a channel of iterators of QueryResult2 for all the entities with components A, B to which filterFn function returns true.
The parameter chunkSize defines the size of each iterators.
func (*Query2[A, B]) GetComponentsIds ¶
func (query *Query2[A, B]) GetComponentsIds() []ComponentId
func (*Query2[A, B]) GetEntitiesIds ¶
GetEntitiesIds returns a slice of all the EntityId fetched for Query2.
type Query3 ¶
type Query3[A, B, C ComponentInterface] struct { World *World // contains filtered or unexported fields }
Query for 3 components type.
func CreateQuery3 ¶
func CreateQuery3[A, B, C ComponentInterface](world *World, queryConfiguration QueryConfiguration) Query3[A, B, C]
CreateQuery3 returns a new Query3, with components A, B, C.
func (*Query3[A, B, C]) Foreach ¶
func (query *Query3[A, B, C]) Foreach(filterFn func(QueryResult3[A, B, C]) bool) iter.Seq[QueryResult3[A, B, C]]
Foreach returns an iterator of QueryResult3 for all the entities with components A, B, C to which filterFn function returns true.
func (*Query3[A, B, C]) ForeachChannel ¶
func (query *Query3[A, B, C]) ForeachChannel(chunkSize int, filterFn func(QueryResult3[A, B, C]) bool) <-chan iter.Seq[QueryResult3[A, B, C]]
ForeachChannel returns a channel of iterators of QueryResult3 for all the entities with components A, B, C to which filterFn function returns true.
The parameter chunkSize defines the size of each iterators.
func (*Query3[A, B, C]) GetComponentsIds ¶
func (query *Query3[A, B, C]) GetComponentsIds() []ComponentId
func (*Query3[A, B, C]) GetEntitiesIds ¶
GetEntitiesIds returns a slice of all the EntityId fetched for Query3.
type Query4 ¶
type Query4[A, B, C, D ComponentInterface] struct { World *World // contains filtered or unexported fields }
Query for 4 components type.
func CreateQuery4 ¶
func CreateQuery4[A, B, C, D ComponentInterface](world *World, queryConfiguration QueryConfiguration) Query4[A, B, C, D]
CreateQuery4 returns a new Query4, with components A, B, C, D.
func (*Query4[A, B, C, D]) Foreach ¶
func (query *Query4[A, B, C, D]) Foreach(filterFn func(QueryResult4[A, B, C, D]) bool) iter.Seq[QueryResult4[A, B, C, D]]
Foreach returns an iterator of QueryResult4 for all the entities with components A, B, C, D to which filterFn function returns true.
func (*Query4[A, B, C, D]) ForeachChannel ¶
func (query *Query4[A, B, C, D]) ForeachChannel(chunkSize int, filterFn func(QueryResult4[A, B, C, D]) bool) <-chan iter.Seq[QueryResult4[A, B, C, D]]
ForeachChannel returns a channel of iterators of QueryResult4 for all the entities with components A, B, C, D to which filterFn function returns true.
The parameter chunkSize defines the size of each iterators.
func (*Query4[A, B, C, D]) GetComponentsIds ¶
func (query *Query4[A, B, C, D]) GetComponentsIds() []ComponentId
func (*Query4[A, B, C, D]) GetEntitiesIds ¶
GetEntitiesIds returns a slice of all the EntityId fetched for Query4.
type Query5 ¶
type Query5[A, B, C, D, E ComponentInterface] struct { World *World // contains filtered or unexported fields }
Query for 5 components type.
func CreateQuery5 ¶
func CreateQuery5[A, B, C, D, E ComponentInterface](world *World, queryConfiguration QueryConfiguration) Query5[A, B, C, D, E]
CreateQuery5 returns a new Query5, with components A, B, C, D, E.
func (*Query5[A, B, C, D, E]) Foreach ¶
func (query *Query5[A, B, C, D, E]) Foreach(filterFn func(QueryResult5[A, B, C, D, E]) bool) iter.Seq[QueryResult5[A, B, C, D, E]]
Foreach returns an iterator of QueryResult5 for all the entities with components A, B, C, D, E to which filterFn function returns true.
func (*Query5[A, B, C, D, E]) ForeachChannel ¶
func (query *Query5[A, B, C, D, E]) ForeachChannel(chunkSize int, filterFn func(QueryResult5[A, B, C, D, E]) bool) <-chan iter.Seq[QueryResult5[A, B, C, D, E]]
ForeachChannel returns a channel of iterators of QueryResult5 for all the entities with components A, B, C, D, E to which filterFn function returns true.
The parameter chunkSize defines the size of each iterators.
func (*Query5[A, B, C, D, E]) GetComponentsIds ¶
func (query *Query5[A, B, C, D, E]) GetComponentsIds() []ComponentId
func (*Query5[A, B, C, D, E]) GetEntitiesIds ¶
GetEntitiesIds returns a slice of all the EntityId fetched for Query5.
type Query6 ¶
type Query6[A, B, C, D, E, F ComponentInterface] struct { World *World // contains filtered or unexported fields }
Query for 6 components type.
func CreateQuery6 ¶
func CreateQuery6[A, B, C, D, E, F ComponentInterface](world *World, queryConfiguration QueryConfiguration) Query6[A, B, C, D, E, F]
CreateQuery6 returns a new Query6, with components A, B, C, D, E, F.
func (*Query6[A, B, C, D, E, F]) Foreach ¶
func (query *Query6[A, B, C, D, E, F]) Foreach(filterFn func(QueryResult6[A, B, C, D, E, F]) bool) iter.Seq[QueryResult6[A, B, C, D, E, F]]
Foreach returns an iterator of QueryResult6 for all the entities with components A, B, C, D, E, F to which filterFn function returns true.
func (*Query6[A, B, C, D, E, F]) ForeachChannel ¶
func (query *Query6[A, B, C, D, E, F]) ForeachChannel(chunkSize int, filterFn func(QueryResult6[A, B, C, D, E, F]) bool) <-chan iter.Seq[QueryResult6[A, B, C, D, E, F]]
ForeachChannel returns a channel of iterators of QueryResult6 for all the entities with components A, B, C, D, E, F to which filterFn function returns true.
The parameter chunkSize defines the size of each iterators.
func (*Query6[A, B, C, D, E, F]) GetComponentsIds ¶
func (query *Query6[A, B, C, D, E, F]) GetComponentsIds() []ComponentId
func (*Query6[A, B, C, D, E, F]) GetEntitiesIds ¶
GetEntitiesIds returns a slice of all the EntityId fetched for Query6.
type Query7 ¶
type Query7[A, B, C, D, E, F, G ComponentInterface] struct { World *World // contains filtered or unexported fields }
Query for 7 components type.
func CreateQuery7 ¶
func CreateQuery7[A, B, C, D, E, F, G ComponentInterface](world *World, queryConfiguration QueryConfiguration) Query7[A, B, C, D, E, F, G]
CreateQuery7 returns a new Query7, with components A, B, C, D, E, F, G.
func (*Query7[A, B, C, D, E, F, G]) Foreach ¶
func (query *Query7[A, B, C, D, E, F, G]) Foreach(filterFn func(QueryResult7[A, B, C, D, E, F, G]) bool) iter.Seq[QueryResult7[A, B, C, D, E, F, G]]
Foreach returns an iterator of QueryResult7 for all the entities with components A, B, C, D, E, F, G to which filterFn function returns true.
func (*Query7[A, B, C, D, E, F, G]) ForeachChannel ¶
func (query *Query7[A, B, C, D, E, F, G]) ForeachChannel(chunkSize int, filterFn func(QueryResult7[A, B, C, D, E, F, G]) bool) <-chan iter.Seq[QueryResult7[A, B, C, D, E, F, G]]
ForeachChannel returns a channel of iterators of QueryResult7 for all the entities with components A, B, C, D, E, F, G to which filterFn function returns true.
The parameter chunkSize defines the size of each iterators.
func (*Query7[A, B, C, D, E, F, G]) GetComponentsIds ¶
func (query *Query7[A, B, C, D, E, F, G]) GetComponentsIds() []ComponentId
func (*Query7[A, B, C, D, E, F, G]) GetEntitiesIds ¶
GetEntitiesIds returns a slice of all the EntityId fetched for Query7.
type Query8 ¶
type Query8[A, B, C, D, E, F, G, H ComponentInterface] struct { World *World // contains filtered or unexported fields }
Query for 8 components type.
func CreateQuery8 ¶
func CreateQuery8[A, B, C, D, E, F, G, H ComponentInterface](world *World, queryConfiguration QueryConfiguration) Query8[A, B, C, D, E, F, G, H]
CreateQuery8 returns a new Query8, with components A, B, C, D, E, F, G, H.
func (*Query8[A, B, C, D, E, F, G, H]) Count ¶
Count returns the total of entities fetched for Query8.
func (*Query8[A, B, C, D, E, F, G, H]) Foreach ¶
func (query *Query8[A, B, C, D, E, F, G, H]) Foreach(filterFn func(QueryResult8[A, B, C, D, E, F, G, H]) bool) iter.Seq[QueryResult8[A, B, C, D, E, F, G, H]]
Foreach returns an iterator of QueryResult8 for all the entities with components A, B, C, D, E, F, G, H to which filterFn function returns true.
func (*Query8[A, B, C, D, E, F, G, H]) ForeachChannel ¶
func (query *Query8[A, B, C, D, E, F, G, H]) ForeachChannel(chunkSize int, filterFn func(QueryResult8[A, B, C, D, E, F, G, H]) bool) <-chan iter.Seq[QueryResult8[A, B, C, D, E, F, G, H]]
ForeachChannel returns a channel of iterators of QueryResult8 for all the entities with components A, B, C, D, E, F, G, H to which filterFn function returns true.
The parameter chunkSize defines the size of each iterators.
func (*Query8[A, B, C, D, E, F, G, H]) GetComponentsIds ¶
func (query *Query8[A, B, C, D, E, F, G, H]) GetComponentsIds() []ComponentId
func (*Query8[A, B, C, D, E, F, G, H]) GetEntitiesIds ¶
GetEntitiesIds returns a slice of all the EntityId fetched for Query8.
type QueryConfiguration ¶ added in v1.4.0
type QueryConfiguration struct { Tags []TagId OptionalComponents []OptionalComponent }
type QueryResult1 ¶
type QueryResult1[A ComponentInterface] struct { EntityId EntityId A *A }
Result returned for Query1.
type QueryResult2 ¶
type QueryResult2[A, B ComponentInterface] struct { EntityId EntityId A *A B *B }
Result returned for Query2.
type QueryResult3 ¶
type QueryResult3[A, B, C ComponentInterface] struct { EntityId EntityId A *A B *B C *C }
Result returned for Query3.
type QueryResult4 ¶
type QueryResult4[A, B, C, D ComponentInterface] struct { EntityId EntityId A *A B *B C *C D *D }
Result returned for Query4.
type QueryResult5 ¶
type QueryResult5[A, B, C, D, E ComponentInterface] struct { EntityId EntityId A *A B *B C *C D *D E *E }
Result returned for Query5.
type QueryResult6 ¶
type QueryResult6[A, B, C, D, E, F ComponentInterface] struct { EntityId EntityId A *A B *B C *C D *D E *E F *F }
Result returned for Query6.
type QueryResult7 ¶
type QueryResult7[A, B, C, D, E, F, G ComponentInterface] struct { EntityId EntityId A *A B *B C *C D *D E *E F *F G *G }
Result returned for Query7.
type QueryResult8 ¶
type QueryResult8[A, B, C, D, E, F, G, H ComponentInterface] struct { EntityId EntityId A *A B *B C *C D *D E *E F *F G *G H *H }
Result returned for Query8.
type TagId ¶ added in v1.4.0
type TagId = ComponentId
type World ¶
type World struct {
// contains filtered or unexported fields
}
World representation, container of all the data related to entities and their Components.
func CreateWorld ¶
CreateWorld returns a pointer to a new World.
It preallocates initialCapacity in memory.
func (*World) AddComponent ¶
func (world *World) AddComponent(entityId EntityId, componentId ComponentId, conf any) error
AddComponent adds the component with ComponentId to the EntityId.
This non-generic version is adapted for when generics are not available, though might be slower. It returns an error if:
- the entity already has the componentId
- the componentId is not registered in the World
- an internal error occurs
func (*World) AddComponents ¶ added in v1.6.0
func (world *World) AddComponents(entityId EntityId, componentsIdsConfs ...ComponentIdConf) error
AddComponents adds variadic components to the EntityId.
This non-generic version is adapted for when generics are not available, though might be slower. It returns an error if:
- the entity already has the components Ids
- the componentsIds are not registered in the World
- an internal error occurs
func (*World) AddTag ¶ added in v1.4.0
AddTag adds a TagId to a given EntityId. This function returns an error if: - The id is lower than the valid range (< TAGS_INDICES) - The Tag is already owned
func (*World) CreateEntity ¶
CreateEntity creates a new Entity in World; It is linked to no Component.
func (*World) GetComponent ¶
func (world *World) GetComponent(entityId EntityId, componentId ComponentId) (any, error)
GetComponent returns the component with ComponentId for EntityId.
This non-generic version is adapted for when generics are not available, though might be slower and requires a type assertion. It returns an error if:
- the ComponentId is not registered in the World
- the entity does not have the component
func (*World) GetEntityName ¶
GetEntityName returns the name of an EntityId. If not found, returns an empty string.
func (*World) HasComponents ¶
func (world *World) HasComponents(entityId EntityId, componentsIds ...ComponentId) bool
HasComponents returns whether the entity has the given variadic list of ComponentId.
It returns false if at least one ComponentId is not owned.
func (*World) HasTag ¶ added in v1.4.0
HasTag returns a boolean, to check if an EntityId owns a Tag.
func (*World) PublishEntity ¶
PublishEntity calls the callback setted in SetEntityAddedFn.
func (*World) RemoveComponent ¶
func (world *World) RemoveComponent(entityId EntityId, componentId ComponentId) error
RemoveComponent removes the component with ComponentId from the EntityId.
This non-generic version is adapted for when generics are not available, though might be slower. It returns an error if:
- the entity does not have the component
- the ComponentId is not registered in the World
func (*World) RemoveEntity ¶
RemoveEntity removes all the data related to an Entity.
It calls the callback setted in SetEntityRemovedFn beforehand, so that the callback still has access to the data.
func (*World) RemoveTag ¶ added in v1.4.0
RemoveTags removes a Tag for a given EntityId. It returns an error if: - The entity does not exists. - The entity already owns the Tag.
func (*World) SearchEntity ¶
SearchEntity returns the EntityId named by name. If not found, returns 0.
func (*World) SetComponentAddedFn ¶
func (world *World) SetComponentAddedFn(componentAddedFn func(entityId EntityId, componentId ComponentId))
SetComponentAddedFn sets a callback for when a component is added to an entity.
func (*World) SetComponentRemovedFn ¶
func (world *World) SetComponentRemovedFn(componentRemovedFn func(entityId EntityId, componentId ComponentId))
SetComponentRemovedFn sets a callback for when a component is removed.
func (*World) SetEntityAddedFn ¶
SetEntityAddedFn sets a callback for when a new entity is added.
func (*World) SetEntityName ¶
SetEntityName sets the name for an EntityId.
func (*World) SetEntityRemovedFn ¶
SetEntityRemovedFn sets a callback for when an entity is removed.