A class that implements BaseComponentArray specializing it for a component of type TComponent
.
More...
#include <ecs_world.hpp>
|
| ComponentArray (std::weak_ptr< ECSWorld > world) |
| Construct a new Component Array object.
|
|
| BaseComponentArray (std::weak_ptr< ECSWorld > world) |
| Construct a new Base Component Array object.
|
|
virtual | ~BaseComponentArray ()=default |
| Destroy the Base Component Array object.
|
|
|
std::shared_ptr< BaseComponentArray > | instantiate (std::weak_ptr< ECSWorld > world) const override |
| Creates a new component array of the same type as this and associated with a new World.
|
|
void | addComponent (EntityID entityID, const TComponent &component) |
| Adds a component belonging to this entity to this array.
|
|
void | addComponent (EntityID entityID, const nlohmann::json &componentJSON) override |
| Adds a component belonging to this entity to this array based on its JSON description.
|
|
void | removeComponent (EntityID entityID) override |
| Removes the component associated with a specific entity, maintaining packing but not order.
|
|
TComponent | getComponent (EntityID entityID, float simulationProgress=1.f) const |
| Get the component object.
|
|
bool | hasComponent (EntityID entityID) const override |
| Tests whether an entry for a component belonging to this entity is present.
|
|
void | updateComponent (EntityID entityID, const TComponent &newValue) |
| Updates the value of the component belonging to this entity.
|
|
void | updateComponent (EntityID entityID, const nlohmann::json &value) override |
| Updates the value of the component belonging to this entity based on a JSON description of the new value.
|
|
virtual void | handleEntityDestroyed (EntityID entityID) override |
| A callback to handle the side effect of the destruction of an entity. Here: deletion of the component associated with it.
|
|
virtual void | handlePreSimulationStep () override |
| A callback for the start of a simulation step.
|
|
virtual void | copyComponent (EntityID to, EntityID from) override |
| Handles the copying of a component belonging to one entity to another.
|
|
virtual void | copyComponent (EntityID to, EntityID from, BaseComponentArray &other) override |
| Handles the copying of a component belonging to one entity to another.
|
|
|
std::vector< TComponent > | mComponentsNext {} |
| An array containing the state of each entity's component as will be seen at the start of the next simulation tick.
|
|
std::vector< TComponent > | mComponentsPrevious {} |
| An array containing the state of each entity's component as seen in the last simulation tick.
|
|
std::unordered_map< EntityID, std::size_t > | mEntityToComponentIndex {} |
| A mapping from the ID of an entity to the index in the component array that stores the entity's component.
|
|
std::unordered_map< std::size_t, EntityID > | mComponentToEntity {} |
| A mapping from the index of a component to the ID of the entity that owns that component.
|
|
|
std::weak_ptr< ECSWorld > | mWorld {} |
| A reference to the world to which this component array belongs.
|
|
template<typename TComponent>
class ToyMaker::ComponentArray< TComponent >
A class that implements BaseComponentArray specializing it for a component of type TComponent
.
- Template Parameters
-
TComponent | The type of component the array is being made for. |
- See also
- ECSWorld::registerComponentTypes()
◆ ComponentArray()
template<typename TComponent>
Construct a new Component Array object.
- Parameters
-
world | The world to which this component array will belong. |
◆ addComponent() [1/2]
template<typename TComponent>
Adds a component belonging to this entity to this array based on its JSON description.
- Parameters
-
entityID | The entity to which the component will belong |
componentJSON | A JSON description of the value of the component |
Implements ToyMaker::BaseComponentArray.
◆ addComponent() [2/2]
template<typename TComponent>
Adds a component belonging to this entity to this array.
- Parameters
-
entityID | The entity to which the component will belong |
component | The value of the component |
◆ copyComponent() [1/2]
template<typename TComponent>
Handles the copying of a component belonging to one entity to another.
- Parameters
-
to | The entity to which the copied component goes |
from | The entity from which the component is copied, belonging to the same ComponentArray<T> |
Implements ToyMaker::BaseComponentArray.
◆ copyComponent() [2/2]
template<typename TComponent>
Handles the copying of a component belonging to one entity to another.
- Parameters
-
to | The entity to which the copied component goes |
from | The entity from which the component is copied |
other | The ComponentArray<T> which holds the component belonging to from |
Implements ToyMaker::BaseComponentArray.
◆ getComponent()
template<typename TComponent>
Get the component object.
- Parameters
-
entityID | The entity to whom the component belongs |
simulationProgress | Progress towards the next simulation tick. By default 1.0, where the latest version of the component is retrieved. |
- Returns
- TComponent The (interpolated) component
◆ handleEntityDestroyed()
template<typename TComponent>
A callback to handle the side effect of the destruction of an entity. Here: deletion of the component associated with it.
- Parameters
-
entityID | The entity being destroyed |
Implements ToyMaker::BaseComponentArray.
◆ handlePreSimulationStep()
template<typename TComponent>
A callback for the start of a simulation step.
This is where the next
member array is copied into the previous
member array.
Implements ToyMaker::BaseComponentArray.
◆ hasComponent()
template<typename TComponent>
Tests whether an entry for a component belonging to this entity is present.
- Parameters
-
entityID | The entity being tested. |
- Return values
-
true | Component belonging to the entity is present; |
false | Component belonging to the entity is absent; |
Implements ToyMaker::BaseComponentArray.
◆ instantiate()
template<typename TComponent>
Creates a new component array of the same type as this and associated with a new World.
- Parameters
-
world | The world to which the newly constructed ComponentArray will belong |
- Returns
- std::shared_ptr<BaseComponentArray> A shared pointer to the new component array
Implements ToyMaker::BaseComponentArray.
◆ removeComponent()
template<typename TComponent>
Removes the component associated with a specific entity, maintaining packing but not order.
- Parameters
-
entityID | The entity associated with the component being removed |
Implements ToyMaker::BaseComponentArray.
◆ updateComponent() [1/2]
template<typename TComponent>
Updates the value of the component belonging to this entity based on a JSON description of the new value.
- Parameters
-
entityID | The ID of the entity whose component is being updated |
value | The value to which the component will be updated, described in JSON |
Implements ToyMaker::BaseComponentArray.
◆ updateComponent() [2/2]
template<typename TComponent>
Updates the value of the component belonging to this entity.
- Parameters
-
entityID | The ID of the entity whose component is being updated |
newValue | The value to which the component will be updated |
◆ mComponentToEntity
template<typename TComponent>
A mapping from the index of a component to the ID of the entity that owns that component.
- See also
- mEntityToComponentIndex
◆ mEntityToComponentIndex
template<typename TComponent>
A mapping from the ID of an entity to the index in the component array that stores the entity's component.
- See also
- mComponentToEntity
The documentation for this class was generated from the following file: