Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::Entity Class Reference

The Entity is a wrapper on an entity ID, used as the primary interface between an application and the engine's ECS system. More...

#include <ecs_world.hpp>

Public Member Functions

 Entity (const Entity &other)
 Construct a new Entity object.
 
 Entity (Entity &&other) noexcept
 Construct a new Entity object.
 
Entityoperator= (const Entity &other)
 Copies an Entity object, replacing any component values currently present on this one.
 
Entityoperator= (Entity &&other) noexcept
 Moves other's resources into this object, while destroying previously held resources associated with this.
 
 ~Entity ()
 Destroy the Entity object.
 
EntityID getID ()
 Gets the ID associated with this Entity.
 
void copy (const Entity &other)
 Copies component values from another entity into this one.
 
template<typename TComponent>
void addComponent (const TComponent &component)
 Adds a new component to this Entity.
 
void addComponent (const nlohmann::json &jsonComponent)
 Adds a new component to this Entity based on its JSON description.
 
template<typename TComponent>
void removeComponent ()
 Removes a component from an entity.
 
void removeComponent (const std::string &typeName)
 Removes a component from an entity.
 
template<typename TComponent>
bool hasComponent () const
 Tests whether this entity has a particular component.
 
bool hasComponent (const std::string &typeName) const
 Tests whether this entity has a particular component.
 
template<typename TComponent>
TComponent getComponent (float simulationProgress=1.f) const
 Get the value of the component at a specific time this frame.
 
template<typename TComponent>
void updateComponent (const TComponent &newValue)
 Updates the value of a component belonging to this Entity.
 
void updateComponent (const nlohmann::json &jsonValue)
 Updates the value of a component belonging to this Entity.
 
template<typename TSystem>
bool isEnabled () const
 Tests whether this entity is enabled for a particular system.
 
template<typename TSystem>
bool isRegistered () const
 Tests whether this entity is eligible for participation with a given system.
 
template<typename TSystem>
void enableSystem ()
 Enables this Entity for a particular System.
 
template<typename TSystem>
void disableSystem ()
 Disables this entity for a particular system.
 
void disableSystems ()
 Disables this entity's participation in all systems.
 
void enableSystems (Signature systemMask)
 Enables this entity's participation in a set of systems.
 
std::weak_ptr< ECSWorldgetWorld ()
 Get the ECSWorld object this Entity belongs to.
 
void joinWorld (ECSWorld &world)
 Removes this Entity from its current ECS world, and moves it to the new one.
 

Private Member Functions

 Entity (EntityID entityID, std::shared_ptr< ECSWorld > world)
 Construct a new Entity object, with a new ID as a member of a new ECSWorld.
 

Private Attributes

EntityID mID
 The ID of this entity within its owning ECSWorld.
 
std::weak_ptr< ECSWorldmWorld
 The world this Entity belongs to.
 

Friends

class ECSWorld
 

Detailed Description

The Entity is a wrapper on an entity ID, used as the primary interface between an application and the engine's ECS system.

Holds an entity ID, and has several methods for querying and changing components, participation in different systems belonging to its ECSWorld.

Constructor & Destructor Documentation

◆ Entity() [1/3]

Entity::Entity ( const Entity & other)

Construct a new Entity object.

Parameters
otherThe entity whose components will be copied to create this one.

◆ Entity() [2/3]

Entity::Entity ( Entity && other)
noexcept

Construct a new Entity object.

Parameters
otherSoon to be destroyed entity whose resources this object will now own.

◆ Entity() [3/3]

ToyMaker::Entity::Entity ( EntityID entityID,
std::shared_ptr< ECSWorld > world )
inlineprivate

Construct a new Entity object, with a new ID as a member of a new ECSWorld.

Parameters
entityIDThe ID of the new Entity.
worldThe ECSWorld the Entity belongs to.

Member Function Documentation

◆ addComponent() [1/2]

void Entity::addComponent ( const nlohmann::json & jsonComponent)

Adds a new component to this Entity based on its JSON description.

Parameters
jsonComponentA description of the new component, including its type and initial value.
See also
ECSWorld::addComponent()

◆ addComponent() [2/2]

template<typename TComponent>
void ToyMaker::Entity::addComponent ( const TComponent & component)

Adds a new component to this Entity.

Template Parameters
TComponentThe type of component being added.
Parameters
componentThe initial value of the component when added.
See also
ECSWorld::addComponent()

◆ copy()

void Entity::copy ( const Entity & other)

Copies component values from another entity into this one.

Parameters
otherThe Entity being copied from
See also
ECSWorld::copyComponents()

◆ disableSystem()

template<typename TSystem>
void ToyMaker::Entity::disableSystem ( )

Disables this entity for a particular system.

Template Parameters
TSystemThe System this entity is being disabled on.
See also
ECSWorld::disableEntity()

◆ disableSystems()

void Entity::disableSystems ( )

Disables this entity's participation in all systems.

See also
ECSWorld::disableEntity()

◆ enableSystem()

template<typename TSystem>
void ToyMaker::Entity::enableSystem ( )

Enables this Entity for a particular System.

Template Parameters
TSystemThe System this entity is being enabled for.
See also
ECSWorld::enableEntity()

◆ enableSystems()

void Entity::enableSystems ( Signature systemMask)

Enables this entity's participation in a set of systems.

Parameters
systemMaskA bitset, each position of which corresponds to a SystemType for which activation is to be attempted.

◆ getComponent()

template<typename TComponent>
TComponent ToyMaker::Entity::getComponent ( float simulationProgress = 1.f) const

Get the value of the component at a specific time this frame.

Template Parameters
TComponentThe type of component being retrieved.
Parameters
simulationProgressProgress towards the next simulation step from the last one, a value between 0 and 1.
Returns
TComponent The component value retrieved.
See also
ECSWorld::getComponent()

◆ getID()

EntityID ToyMaker::Entity::getID ( )
inline

Gets the ID associated with this Entity.

Returns
EntityID The ID of this Entity.

◆ getWorld()

std::weak_ptr< ECSWorld > ToyMaker::Entity::getWorld ( )
inline

Get the ECSWorld object this Entity belongs to.

Returns
std::weak_ptr<ECSWorld> A reference to the ECSWorld this entity belongs to.

◆ hasComponent() [1/2]

template<typename TComponent>
bool ToyMaker::Entity::hasComponent ( ) const

Tests whether this entity has a particular component.

Template Parameters
TComponentThe type of component whose existence is being tested.
Return values
trueThe component is present;
falseThe component is absent;
See also
ECSWorld::hasComponent()

◆ hasComponent() [2/2]

bool Entity::hasComponent ( const std::string & typeName) const

Tests whether this entity has a particular component.

Parameters
typeNameThe component type string of the component being tested.
Return values
trueThe component is present;
falseThe component is absent;
See also
ECSWorld::hasComponent()

◆ isEnabled()

template<typename TSystem>
bool ToyMaker::Entity::isEnabled ( ) const

Tests whether this entity is enabled for a particular system.

Template Parameters
TSystemThe System being queried.
Return values
trueThis entity is active on the system;
falseThis entity is not active on the system;
See also
ECSWorld::isEnabled()

◆ isRegistered()

template<typename TSystem>
bool ToyMaker::Entity::isRegistered ( ) const

Tests whether this entity is eligible for participation with a given system.

Template Parameters
TSystemThe System being queried.
Return values
trueThis entity fulfills participation prerequisites;
falseThis entity fails participation prerequisites;
See also
ECSWorld::isRegistered()

◆ joinWorld()

void Entity::joinWorld ( ECSWorld & world)

Removes this Entity from its current ECS world, and moves it to the new one.

Parameters
worldThe ECSWorld this Entity will belong to.

◆ operator=() [1/2]

Entity & Entity::operator= ( const Entity & other)

Copies an Entity object, replacing any component values currently present on this one.

Parameters
otherThe entity whose components will be copied.
Returns
Entity& A reference to this entity after its components have been updated.

◆ operator=() [2/2]

Entity & Entity::operator= ( Entity && other)
noexcept

Moves other's resources into this object, while destroying previously held resources associated with this.

Parameters
otherSoon to be destroyed Entity.
Returns
Entity& A reference to this object, post-move.

◆ removeComponent() [1/2]

template<typename TComponent>
void ToyMaker::Entity::removeComponent ( )

Removes a component from an entity.

Template Parameters
TComponentThe type of component being retrieved.
See also
ECSWorld::removeComponent()

◆ removeComponent() [2/2]

void Entity::removeComponent ( const std::string & typeName)

Removes a component from an entity.

Parameters
typeNameThe component type string of the component being removed.
See also
ECSWorld::removeComponent()

◆ updateComponent() [1/2]

void Entity::updateComponent ( const nlohmann::json & jsonValue)

Updates the value of a component belonging to this Entity.

Parameters
jsonValueA json description of the value, which also includes its type.
See also
ECSWorld::updateComponent()

◆ updateComponent() [2/2]

template<typename TComponent>
void ToyMaker::Entity::updateComponent ( const TComponent & newValue)

Updates the value of a component belonging to this Entity.

Template Parameters
TComponentThe type of component being updated.
Parameters
newValueThe new value of the component.
See also
ECSWorld::updateComponent()

The documentation for this class was generated from the following files: