Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
|
An object that stores and manages updates to all the component arrays instantiated for this ECS World. More...
#include <ecs_world.hpp>
Classes | |
struct | getComponentTypeName |
Helper function for retrieving the component type string defined as part of the component. More... | |
struct | getComponentTypeName< std::shared_ptr< TComponent > > |
A specialization of getComponentTypeName for components which are wrapped in shared pointers. More... | |
Public Member Functions | |
ComponentManager (std::weak_ptr< ECSWorld > world) | |
Construct a new Component Manager object. | |
Private Member Functions | |
ComponentManager | instantiate (std::weak_ptr< ECSWorld > world) const |
Constructs a new component manager and associates it with the world passed in as argument. Creates a fresh, but empty, set of component arrays. | |
template<typename TComponent> | |
void | registerComponentArray () |
A method to allow a new component type to register itself with the ECS system for this project. | |
template<typename TComponent> | |
std::shared_ptr< ComponentArray< TComponent > > | getComponentArray () const |
Get the (specialized) Component Array object. | |
std::shared_ptr< BaseComponentArray > | getComponentArray (const std::string &componentTypeName) const |
Get the Component Array object. | |
template<typename TComponent> | |
ComponentType | getComponentType () const |
Get the component type ID for a given component type. | |
ComponentType | getComponentType (const std::string &typeName) const |
Get the component type ID for a given component type string. | |
Signature | getSignature (EntityID entityID) |
Get the component signature for a given entity. | |
template<typename TComponent> | |
void | addComponent (EntityID entityID, const TComponent &component) |
Adds a component entry for this entity in the array specified. | |
void | addComponent (EntityID entityID, const nlohmann::json &jsonComponent) |
Adds a component entry for this entity in the array specified (in the JSON description). | |
template<typename TComponent> | |
void | removeComponent (EntityID entityID) |
Removes the component of the type specified from the entity. | |
void | removeComponent (EntityID entityID, const std::string &type) |
Removes the component of the type specified from the entity. | |
template<typename TComponent> | |
bool | hasComponent (EntityID entityID) const |
Tests whether an entity has a component of a particular type. | |
bool | hasComponent (EntityID entityID, const std::string &type) |
Tests whether an entity has a component of a particular type. | |
template<typename TComponent> | |
TComponent | getComponent (EntityID entityID, float simulationProgress=1.f) const |
Get the component value for this entity. | |
template<typename TComponent> | |
void | updateComponent (EntityID entityID, const TComponent &newValue) |
Updates a component belonging to an entity with its new value. | |
void | updateComponent (EntityID entityID, const nlohmann::json &componentProperties) |
Updates a component belonging to an entity with its new value(described in JSON). | |
template<typename TComponent> | |
void | copyComponent (EntityID to, EntityID from) |
Copies a component value from one component to another within the same component array. | |
void | copyComponents (EntityID to, EntityID from) |
Copies all components from one entity and updates or adds them to the other. | |
void | copyComponents (EntityID to, EntityID from, ComponentManager &other) |
Copies all components from one entity and updates or adds them to the other, where the source entity may belong to a different ECS World. | |
void | handleEntityDestroyed (EntityID entityID) |
Handles component arrays specific side effect of entity destruction. | |
void | handlePreSimulationStep () |
Callback for the start of a simulation step, where the contents of every component's next member is copied into its previous member. | |
void | unregisterAll () |
Unregisters all component arrays associated with this manager, as part of the destruction process for the world this component manager belongs to. | |
Private Attributes | |
std::unordered_map< std::string, std::size_t > | mNameToComponentHash {} |
Maps each component type name to its corresponding hash. | |
std::unordered_map< std::size_t, ComponentType > | mHashToComponentType {} |
Maps a component's type hash to its ComponentType. | |
std::unordered_map< std::size_t, std::shared_ptr< BaseComponentArray > > | mHashToComponentArray {} |
Maps the hash of a component type to its corresponding ComponentArray. | |
std::unordered_map< EntityID, Signature > | mEntityToSignature {} |
Stores the component signature of each entity. | |
std::weak_ptr< ECSWorld > | mWorld |
Holds a reference to the ECS world this component manager manages component arrays for. | |
Friends | |
class | ECSWorld |
An object that stores and manages updates to all the component arrays instantiated for this ECS World.
|
inlineexplicit |
Construct a new Component Manager object.
world | The world to which this component manager belongs. |
|
private |
Adds a component entry for this entity in the array specified (in the JSON description).
entityID | The entity to which the component is being added. |
jsonComponent | The value of the added component, described in JSON. |
|
private |
Adds a component entry for this entity in the array specified.
TComponent | The type of component being added. |
entityID | The entity to which the component is being added. |
component | The value of the added component. |
|
private |
Copies a component value from one component to another within the same component array.
TComponent | The type of component being copied. |
to | The entity to which the component is copied. |
from | The entity the component is copied from. |
Copies all components from one entity and updates or adds them to the other.
to | The entity to which the copied components will be added or updated. |
from | The entity from which the components will be copied. |
|
private |
Copies all components from one entity and updates or adds them to the other, where the source entity may belong to a different ECS World.
to | The entity to which the copied components will be added or updated. |
from | The entity from which components will be copied. |
other | The component manager belonging to the same world as from . |
|
private |
Get the component value for this entity.
TComponent | The type of component value to retrieve. |
entityID | The entity whose component is being retrieved. |
simulationProgress | Progress towards the next simulation tick, a value between 0.0 and 1.0. |
|
inlineprivate |
Get the (specialized) Component Array object.
TComponent | The type of component whose array is being retrieved. |
|
inlineprivate |
Get the Component Array object.
componentTypeName | The component type string for the desired component array. |
|
private |
Get the component type ID for a given component type.
TComponent | The type of the component type ID being retrieved. |
|
private |
Get the component type ID for a given component type string.
typeName | the component type string for the component type. |
Get the component signature for a given entity.
The component signature describes which components are present for a given object. The position of each bit in the signature corresponds to the ComponentType that that bit represents.
1
indicates that a component of that particular type is associated with the entity.0
indicates that there is no component of that type associated with the entity.entityID | The entity whose component signature is being retrieved. |
|
private |
Handles component arrays specific side effect of entity destruction.
Removes entry from every component array belonging to this entity.
entityID | The entity being destroyed. |
|
private |
Callback for the start of a simulation step, where the contents of every component's next
member is copied into its previous
member.
|
private |
Tests whether an entity has a component of a particular type.
TComponent | The type of component whose existence is being tested. |
entityID | The entity being queried. |
true | The component is present; |
false | The component is absent; |
|
private |
Tests whether an entity has a component of a particular type.
entityID | The entity being queried. |
type | The component type string of the component whose existence is being tested. |
true | The component is present; |
false | The component is absent; |
|
private |
Constructs a new component manager and associates it with the world passed in as argument. Creates a fresh, but empty, set of component arrays.
world | The world to which the new component manager will belong. |
|
private |
A method to allow a new component type to register itself with the ECS system for this project.
TComponent | The type of component being registered. |
|
private |
Removes the component of the type specified from the entity.
TComponent | The type of component being removed. |
entityID | The entity whose component is being removed. |
|
private |
Removes the component of the type specified from the entity.
entityID | The entity whose component is being removed. |
type | The component type string of the component being removed. |
|
private |
Updates a component belonging to an entity with its new value(described in JSON).
entityID | The entity whose component is being updated. |
componentProperties | The new value for the component, described in JSON. |
|
private |
Updates a component belonging to an entity with its new value.
TComponent | The type of component being updated. |
entityID | The entity whose component is being updated. |
newValue | The new value for the component. |
Stores the component signature of each entity.
The position of each bit in the signature corresponds to a ComponentType managed by the ComponentManager. A given entity either has or doesn't have a particular component according as the corresponding bit in the signature is set or unset.
|
private |
Maps a component's type hash to its ComponentType.
The hash of a component is provided by the STL type_traits library. The map allows us to retrieve the ECS Type ID (used in entity component signatures) for a type with a particular hash
|
private |
Maps each component type name to its corresponding hash.