class
#include <core/ecs/world.hpp>
World Holds entities, their components and resources.
Public types
Constructors, destructors, conversion operators
- World()
- Constructs.
- Components(World& world, Entity entity)
- Constructs.
- ConstComponents(const World& world, Entity entity)
- Constructs.
- Relations(World& world, Entity entity, bool from)
- Constructs.
- ConstRelations(const World& world, Entity entity, bool from)
- Constructs.
- Iterator(Components& components, bool end)
- Constructs.
- Iterator(const Iterator& other) defaulted
- Copy constructs.
- Iterator(const ConstComponents& components, bool end)
- Constructs.
- Iterator(const Iterator& other) defaulted
- Copy constructs.
- Iterator(Relations& relations, bool end)
- Constructs.
- Iterator(const Iterator& other) defaulted
- Copy constructs.
- Iterator(ConstRelations& relations, bool end)
- Constructs.
- Iterator(const Iterator& other) defaulted
- Copy constructs.
Public functions
- void reset()
- Resets the world to its initial state.
-
void registerResource(const reflection::
Type& type) - Registers a resource type.
-
template<typename T>void registerResource()
- Registers a resource type.
-
void registerComponent(const reflection::
Type& type) - Registers a component type.
-
template<typename T>void registerComponent()
- Registers a component type.
-
void registerRelation(const reflection::
Type& type) - Registers a relation type.
-
template<typename T>void registerRelation()
- Registers a relation type.
-
void unregister(const reflection::
Type& type) - Unregisters a type.
- auto types() -> Types&
- Returns the types registry of the world.
- auto types() const -> const Types&
- Returns the types registry of the world.
- auto tables() -> Tables&
- Returns the tables of the world.
- auto tables() const -> const Tables&
- Returns the tables of the world.
- auto archetypeGraph() -> ArchetypeGraph&
- Returns the archetype graph of the world.
- auto archetypeGraph() const -> const ArchetypeGraph&
- Returns the archetype graph of the world.
- auto observers() -> Observers&
- Returns the observers of the world.
- auto observers() const -> const Observers&
- Returns the observers of the world.
-
void insertResource(memory::
AnyValue value) - Inserts a new resource into the world.
-
template<typename T>void insertResource(T value)
- Inserts a new resource into the world.
-
auto eraseResource(const reflection::
Type& type) -> bool - Erases a new resource from the world.
-
template<typename T>auto eraseResource() -> bool
- Erases a new resource from the world.
-
auto hasResource(const reflection::
Type& type) const -> bool - Checks if a resource is present.
-
template<typename T>auto hasResource() const -> bool
- Checks if a resource is present.
-
auto resource(const reflection::
Type& type) -> void* - Returns a pointer to a resource.
-
template<typename T>auto resource() -> T&
- Returns a reference to a resource.
-
auto resource(const reflection::
Type& type) const -> const void* - Returns a pointer to a resource.
-
template<typename T>auto resource() const -> const T&
- Returns a reference to a resource.
- auto create() -> Entity
- Creates a new entity.
- void createAt(Entity entity)
- Creates a new entity with the given identifier.
- auto reserve() -> Entity
- Reserves an entity identifier, without actually creating an entity.
- void destroy(Entity entity)
- Destroys an entity.
- auto generation(uint32_t index) const -> uint32_t
- Gets the generation of the entity with the given index.
- auto archetype(Entity entity) const -> ArchetypeId
- Gets the archetype of the given entity.
- auto isAlive(Entity entity) const -> bool
- Checks if an entity is still alive.
- auto components(Entity entity) -> Components
- Creates a components view for the given entity.
- auto components(Entity entity) const -> ConstComponents
- Creates a components view for the given entity.
- auto relationsFrom(Entity entity) -> Relations
- Creates a view for relations coming from the given entity.
- auto relationsFrom(Entity entity) const -> ConstRelations
- Creates a view for relations coming from the given entity.
- auto relationsTo(Entity entity) -> Relations
- Creates a view for relations going into the given entity.
- auto relationsTo(Entity entity) const -> ConstRelations
- Creates a view for relations going into the given entity.
-
void relate(Entity from,
Entity to,
const reflection::
Type& type, void* value) - Inserts a relation between the two given entities.
-
template<typename T>void relate(Entity from, Entity to, T value)
- Inserts a relation between the two given entities.
-
void unrelate(Entity from,
Entity to,
const reflection::
Type& type) - Removes the relation, if there's any, between the two given entities.
-
template<typename T>void unrelate(Entity from, Entity to)
- Removes the relation, if there's any, between the two given entities.
-
auto related(Entity from,
Entity to,
const reflection::
Type& type) const -> bool - Checks if there's a relation of the given type between the two given entities.
-
template<typename T>auto related(Entity from, Entity to) const -> bool
- Checks if there's a relation of the given type between the two given entities.
-
auto relation(Entity from,
Entity to,
const reflection::
Type& type) -> void* - Gets a pointer to the relation value between the two given entities.
-
auto relation(Entity from,
Entity to,
const reflection::
Type& type) const -> const void* - Gets a pointer to the relation value between the two given entities.
-
template<typename T>auto relation(Entity from, Entity to) -> T&
- Gets a reference to the relation value between the two given entities.
-
template<typename T>auto relation(Entity from, Entity to) const -> const T&
- Gets a reference to the relation value between the two given entities.
- auto entityCount() const -> std::size_t
- Gets the number of alive entities.
-
auto has(const reflection::
Type& type) const -> bool - Checks if the given component is present.
-
template<typename T>auto has() const -> bool
- Checks if the given component is present.
-
auto get(const reflection::
Type& type) -> void* - Returns a pointer to the component with the given type.
-
template<typename T>auto get() -> T&
- Returns a pointer to the component with the given type.
- auto begin() -> Iterator
- Returns an iterator to the first component.
- auto end() -> Iterator
- Returns an iterator to the entry after the last component.
-
auto add(const reflection::
Type& type, void* value) -> Components& - Adds a component to the entity.
-
template<typename T>auto add(T&& value) -> Components&
- Adds a component to the entity.
-
auto remove(const reflection::
Type& type) -> Components& - Removes a component from the entity.
-
template<typename T>auto remove() -> Components&
- Removes a component from the entity.
-
auto has(const reflection::
Type& type) const -> bool - Checks if the given component is present.
-
template<typename T>auto has() const -> bool
- Checks if the given component is present.
-
auto get(const reflection::
Type& type) const -> const void* - Returns a pointer to the component with the given type.
-
template<typename T>auto get() const -> const T&
- Returns a pointer to the component with the given type.
- auto begin() const -> Iterator
- Returns an iterator to the first component.
- auto end() const -> Iterator
- Returns an iterator to the entry after the last component.
-
auto has(const reflection::
Type& type, Entity entity) const -> bool - Checks if the entity is related to another entity with the given type.
-
template<typename T>auto has(Entity entity) const -> bool
- Checks if the entity is related to another entity with the given type.
-
auto get(const reflection::
Type& type, Entity entity) -> void* - Returns a pointer to the given relation.
-
template<typename T>auto get(Entity entity) -> T&
- Returns a pointer to the given relation.
- auto begin() -> Iterator
- Returns an iterator to the first relation.
- auto end() -> Iterator
- Returns an iterator to the entry after the last relation.
-
auto has(const reflection::
Type& type, Entity entity) const -> bool - Checks if the entity is related to another entity with the given type.
-
template<typename T>auto has(Entity entity) const -> bool
- Checks if the entity is related to another entity with the given type.
-
auto get(const reflection::
Type& type, Entity entity) -> const void* - Returns a pointer to the given relation.
-
template<typename T>auto get(Entity entity) -> const T&
- Returns a pointer to the given relation.
- auto begin() -> Iterator
- Returns an iterator to the first relation.
- auto end() -> Iterator
- Returns an iterator to the entry after the last relation.
- auto operator==(const Iterator& other) const -> bool
- Compares two iterators.
- auto operator*() const -> const Component&
- Accesses the component referenced by this iterator.
- auto operator->() const -> const Component*
- Accesses the component referenced by this iterator.
- auto operator++() -> Iterator&
- Advances the iterator.
- auto operator==(const Iterator& other) const -> bool
- Compares two iterators.
- auto operator*() const -> const Component&
- Accesses the component referenced by this iterator.
- auto operator->() const -> const Component*
- Accesses the component referenced by this iterator.
- auto operator++() -> Iterator&
- Advances the iterator.
- auto operator==(const Iterator& other) const -> bool
- Compares two iterators.
- auto operator*() const -> const Relation&
- Accesses the relation referenced by this iterator.
- auto operator->() const -> const Relation*
- Accesses the relation referenced by this iterator.
- auto operator++() -> Iterator&
- Advances the iterator.
- auto operator==(const Iterator& other) const -> bool
- Compares two iterators.
- auto operator*() const -> const Relation&
- Accesses the relation referenced by this iterator.
- auto operator->() const -> const Relation*
- Accesses the relation referenced by this iterator.
- auto operator++() -> Iterator&
- Advances the iterator.
Function documentation
cubos:: core:: ecs:: World:: Components(World& world,
Entity entity)
Constructs.
Parameters | |
---|---|
world | World. |
entity | Entity. |
cubos:: core:: ecs:: World:: ConstComponents(const World& world,
Entity entity)
Constructs.
Parameters | |
---|---|
world | World. |
entity | Entity. |
cubos:: core:: ecs:: World:: ConstRelations(const World& world,
Entity entity,
bool from)
Constructs.
Parameters | |
---|---|
world | World. |
entity | Entity. |
from | Whether the relations are from or to the entity. |
cubos:: core:: ecs:: World:: Iterator(Components& components,
bool end)
Constructs.
Parameters | |
---|---|
components | Components view. |
end | Whether the iterator represents the end or the beginning. |
cubos:: core:: ecs:: World:: Iterator(const Iterator& other) defaulted
Copy constructs.
Parameters | |
---|---|
other | Other iterator. |
cubos:: core:: ecs:: World:: Iterator(const ConstComponents& components,
bool end)
Constructs.
Parameters | |
---|---|
components | Components view. |
end | Whether the iterator represents the end or the beginning. |
cubos:: core:: ecs:: World:: Iterator(const Iterator& other) defaulted
Copy constructs.
Parameters | |
---|---|
other | Other iterator. |
cubos:: core:: ecs:: World:: Iterator(const Iterator& other) defaulted
Copy constructs.
Parameters | |
---|---|
other | Other iterator. |
cubos:: core:: ecs:: World:: Iterator(ConstRelations& relations,
bool end)
Constructs.
Parameters | |
---|---|
relations | Relations view. |
end | Whether the iterator represents the end or the beginning. |
cubos:: core:: ecs:: World:: Iterator(const Iterator& other) defaulted
Copy constructs.
Parameters | |
---|---|
other | Other iterator. |
void cubos:: core:: ecs:: World:: reset()
Resets the world to its initial state.
Equivalent to constructing a new world. Previously returned entity identifiers become invalid, as they might be reused.
void cubos:: core:: ecs:: World:: registerResource(const reflection:: Type& type)
Registers a resource type.
Parameters | |
---|---|
type | Resource type. |
template<typename T>
void cubos:: core:: ecs:: World:: registerResource()
Registers a resource type.
Template parameters | |
---|---|
T | Resource type. |
void cubos:: core:: ecs:: World:: registerComponent(const reflection:: Type& type)
Registers a component type.
Parameters | |
---|---|
type | Component type. |
template<typename T>
void cubos:: core:: ecs:: World:: registerComponent()
Registers a component type.
Template parameters | |
---|---|
T | Component type. |
void cubos:: core:: ecs:: World:: registerRelation(const reflection:: Type& type)
Registers a relation type.
Parameters | |
---|---|
type | Relation type. |
template<typename T>
void cubos:: core:: ecs:: World:: registerRelation()
Registers a relation type.
Template parameters | |
---|---|
T | Relation type. |
void cubos:: core:: ecs:: World:: unregister(const reflection:: Type& type)
Unregisters a type.
Parameters | |
---|---|
type | Rype |
ArchetypeGraph& cubos:: core:: ecs:: World:: archetypeGraph()
Returns the archetype graph of the world.
Returns | Archetype graph. |
---|
const ArchetypeGraph& cubos:: core:: ecs:: World:: archetypeGraph() const
Returns the archetype graph of the world.
Returns | Archetype graph. |
---|
void cubos:: core:: ecs:: World:: insertResource(memory:: AnyValue value)
Inserts a new resource into the world.
Parameters | |
---|---|
value | Resource value. |
template<typename T>
void cubos:: core:: ecs:: World:: insertResource(T value)
Inserts a new resource into the world.
Template parameters | |
---|---|
T | Resource type. |
Parameters | |
value | Resource value. |
bool cubos:: core:: ecs:: World:: eraseResource(const reflection:: Type& type)
Erases a new resource from the world.
Parameters | |
---|---|
type | Resource type. |
Returns | Whether there was such a resource. |
template<typename T>
bool cubos:: core:: ecs:: World:: eraseResource()
Erases a new resource from the world.
Template parameters | |
---|---|
T | Resource type. |
Returns | Whether there was such a resource. |
bool cubos:: core:: ecs:: World:: hasResource(const reflection:: Type& type) const
Checks if a resource is present.
Parameters | |
---|---|
type | Resource type. |
Returns | Whether the resource is present. |
template<typename T>
bool cubos:: core:: ecs:: World:: hasResource() const
Checks if a resource is present.
Template parameters | |
---|---|
T | Resource type. |
Returns | Whether the resource is present. |
void* cubos:: core:: ecs:: World:: resource(const reflection:: Type& type)
Returns a pointer to a resource.
Parameters | |
---|---|
type | Resource type. |
Returns | Resource. |
template<typename T>
T& cubos:: core:: ecs:: World:: resource()
Returns a reference to a resource.
Template parameters | |
---|---|
T | Resource type. |
Returns | Resource. |
const void* cubos:: core:: ecs:: World:: resource(const reflection:: Type& type) const
Returns a pointer to a resource.
Parameters | |
---|---|
type | Resource type. |
Returns | Resource. |
template<typename T>
const T& cubos:: core:: ecs:: World:: resource() const
Returns a reference to a resource.
Template parameters | |
---|---|
T | Resource type. |
Returns | Resource. |
Entity cubos:: core:: ecs:: World:: reserve()
Reserves an entity identifier, without actually creating an entity.
Returns | Entity identifier. |
---|
The entity can be later created with a call to createAt().
uint32_t cubos:: core:: ecs:: World:: generation(uint32_t index) const
Gets the generation of the entity with the given index.
Parameters | |
---|---|
index | Entity index. |
Returns | Entity generation. |
ArchetypeId cubos:: core:: ecs:: World:: archetype(Entity entity) const
Gets the archetype of the given entity.
Parameters | |
---|---|
entity | Entity. |
Returns | Archetype identifier. |
Components cubos:: core:: ecs:: World:: components(Entity entity)
Creates a components view for the given entity.
Parameters | |
---|---|
entity | Entity. |
Returns | Components view. |
The given entity
must be alive.
ConstComponents cubos:: core:: ecs:: World:: components(Entity entity) const
Creates a components view for the given entity.
Parameters | |
---|---|
entity | Entity. |
Returns | Components view. |
The given entity
must be alive.
Relations cubos:: core:: ecs:: World:: relationsFrom(Entity entity)
Creates a view for relations coming from the given entity.
Parameters | |
---|---|
entity | From entity. |
Returns | Relations view. |
The given entity
must be alive.
ConstRelations cubos:: core:: ecs:: World:: relationsFrom(Entity entity) const
Creates a view for relations coming from the given entity.
Parameters | |
---|---|
entity | From entity. |
Returns | Relations view. |
The given entity
must be alive.
Relations cubos:: core:: ecs:: World:: relationsTo(Entity entity)
Creates a view for relations going into the given entity.
Parameters | |
---|---|
entity | To entity. |
Returns | Relations view. |
The given entity
must be alive.
ConstRelations cubos:: core:: ecs:: World:: relationsTo(Entity entity) const
Creates a view for relations going into the given entity.
Parameters | |
---|---|
entity | To entity. |
Returns | Relations view. |
The given entity
must be alive.
void cubos:: core:: ecs:: World:: unrelate(Entity from,
Entity to,
const reflection:: Type& type)
Removes the relation, if there's any, between the two given entities.
Parameters | |
---|---|
from | From entity. |
to | To entity. |
type | Relation type. |
bool cubos:: core:: ecs:: World:: related(Entity from,
Entity to,
const reflection:: Type& type) const
Checks if there's a relation of the given type between the two given entities.
Parameters | |
---|---|
from | From entity. |
to | To entity. |
type | Relation type. |
Returns | Whether the relation exists. |
template<typename T>
const T& cubos:: core:: ecs:: World:: relation(Entity from,
Entity to) const
Gets a reference to the relation value between the two given entities.
Template parameters | |
---|---|
T | Relation type. |
Parameters | |
from | From entity. |
to | To entity. |
Returns | Reference to relation value. |
The relation must exist.
std::size_t cubos:: core:: ecs:: World:: entityCount() const
Gets the number of alive entities.
Returns | Number of alive entities. |
---|
bool cubos:: core:: ecs:: World:: has(const reflection:: Type& type) const
Checks if the given component is present.
Parameters | |
---|---|
type | Component type. |
Returns | Whether the component is present. |
void* cubos:: core:: ecs:: World:: get(const reflection:: Type& type)
Returns a pointer to the component with the given type.
Parameters | |
---|---|
type | Component type. |
Returns | Pointer to component. |
The entity must have a component with the given type
.
Components& cubos:: core:: ecs:: World:: add(const reflection:: Type& type,
void* value)
Adds a component to the entity.
Parameters | |
---|---|
type | Component type. |
value | Component value to move. |
Returns | Reference to this. |
If the entity already has the component, its value is overwritten.
template<typename T>
Components& cubos:: core:: ecs:: World:: add(T&& value)
Adds a component to the entity.
Template parameters | |
---|---|
T | Component type. |
Parameters | |
value | Component value to move. |
Returns | Reference to this. |
If the entity already has the component, its value is overwritten.
Components& cubos:: core:: ecs:: World:: remove(const reflection:: Type& type)
Removes a component from the entity.
Parameters | |
---|---|
type | Component type. |
Returns | Reference to this. |
If the entity doesn't have the component, nothing happens.
template<typename T>
Components& cubos:: core:: ecs:: World:: remove()
Removes a component from the entity.
Template parameters | |
---|---|
T | Component type. |
Returns | Reference to this. |
If the entity doesn't have the component, nothing happens.
bool cubos:: core:: ecs:: World:: has(const reflection:: Type& type) const
Checks if the given component is present.
Parameters | |
---|---|
type | Component type. |
Returns | Whether the component is present. |
const void* cubos:: core:: ecs:: World:: get(const reflection:: Type& type) const
Returns a pointer to the component with the given type.
Parameters | |
---|---|
type | Component type. |
Returns | Pointer to component. |
The entity must have a component with the given type
.
bool cubos:: core:: ecs:: World:: has(const reflection:: Type& type,
Entity entity) const
Checks if the entity is related to another entity with the given type.
Parameters | |
---|---|
type | Relation type. |
entity | Entity. |
Returns | Whether the relation is present. |
void* cubos:: core:: ecs:: World:: get(const reflection:: Type& type,
Entity entity)
Returns a pointer to the given relation.
Parameters | |
---|---|
type | Relation type. |
entity | Entity. |
Returns | Pointer to relation. |
The entity must be related with the given entity
and with the given type
.
bool cubos:: core:: ecs:: World:: has(const reflection:: Type& type,
Entity entity) const
Checks if the entity is related to another entity with the given type.
Parameters | |
---|---|
type | Relation type. |
entity | Entity. |
Returns | Whether the relation is present. |
const void* cubos:: core:: ecs:: World:: get(const reflection:: Type& type,
Entity entity)
Returns a pointer to the given relation.
Parameters | |
---|---|
type | Relation type. |
entity | Entity. |
Returns | Pointer to relation. |
The entity must be related with the given entity
and with the given type
.
bool cubos:: core:: ecs:: World:: operator==(const Iterator& other) const
Compares two iterators.
Parameters | |
---|---|
other | Other iterator. |
Returns | Whether the iterators point to the same component. |
const Component* cubos:: core:: ecs:: World:: operator->() const
Accesses the component referenced by this iterator.
Returns | Entry. |
---|
bool cubos:: core:: ecs:: World:: operator==(const Iterator& other) const
Compares two iterators.
Parameters | |
---|---|
other | Other iterator. |
Returns | Whether the iterators point to the same component. |
const Component* cubos:: core:: ecs:: World:: operator->() const
Accesses the component referenced by this iterator.
Returns | Entry. |
---|
bool cubos:: core:: ecs:: World:: operator==(const Iterator& other) const
Compares two iterators.
Parameters | |
---|---|
other | Other iterator. |
Returns | Whether the iterators point to the same relation. |
const Relation* cubos:: core:: ecs:: World:: operator->() const
Accesses the relation referenced by this iterator.
Returns | Entry. |
---|
bool cubos:: core:: ecs:: World:: operator==(const Iterator& other) const
Compares two iterators.
Parameters | |
---|---|
other | Other iterator. |
Returns | Whether the iterators point to the same relation. |
const Relation* cubos:: core:: ecs:: World:: operator->() const
Accesses the relation referenced by this iterator.
Returns | Entry. |
---|