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::BaseComponentArray Class Referenceabstract

An abstract base class for all ECS component arrays. More...

#include <ecs_world.hpp>

Inheritance diagram for ToyMaker::BaseComponentArray:
ToyMaker::ComponentArray< TComponent >

Public Member Functions

 BaseComponentArray (std::weak_ptr< ECSWorld > world)
 Construct a new Base Component Array object.
 
virtual ~BaseComponentArray ()=default
 Destroy the Base Component Array object.
 
virtual void handleEntityDestroyed (EntityID entityID)=0
 A virtual function that handles the side-effect of destroying an entity, i.e., deleting its component in this array.
 
virtual void handlePreSimulationStep ()=0
 An unimplemented callback for a step that occurs before each simulation step.
 
virtual void copyComponent (EntityID to, EntityID from)=0
 Handles the copying of a component from one entity to another within the same array.
 
virtual void copyComponent (EntityID to, EntityID from, BaseComponentArray &other)=0
 Handles the copying of a component from one entity to another, where the other entity belongs to another ECS World.
 
virtual void addComponent (EntityID to, const nlohmann::json &jsonComponent)=0
 Constructs and adds a component to an array based on its json description.
 
virtual void updateComponent (EntityID to, const nlohmann::json &jsonComponent)=0
 Updates the component associated with an entity based on a json description of a new component.
 
virtual bool hasComponent (EntityID entityID) const =0
 Tests whether this array has an entry for this entity.
 
virtual void removeComponent (EntityID entityID)=0
 Removes the component associated with this entity, if present.
 
virtual std::shared_ptr< BaseComponentArrayinstantiate (std::weak_ptr< ECSWorld > world) const =0
 Creates a fresh, empty component array and associates it with a new World.
 

Protected Attributes

std::weak_ptr< ECSWorldmWorld {}
 A reference to the world to which this component array belongs.
 

Detailed Description

An abstract base class for all ECS component arrays.

A component array is a table containing a mapping from an entity to its component, whose type is defined in a subclass of BaseComponentArray

Constructor & Destructor Documentation

◆ BaseComponentArray()

ToyMaker::BaseComponentArray::BaseComponentArray ( std::weak_ptr< ECSWorld > world)
inlineexplicit

Construct a new Base Component Array object.

Parameters
worlda pointer to the this array will belong to once constructed

Member Function Documentation

◆ addComponent()

virtual void ToyMaker::BaseComponentArray::addComponent ( EntityID to,
const nlohmann::json & jsonComponent )
pure virtual

Constructs and adds a component to an array based on its json description.

Parameters
toThe entity to which the new component will be associated
jsonComponentThe component's description in json

Implemented in ToyMaker::ComponentArray< TComponent >.

◆ copyComponent() [1/2]

virtual void ToyMaker::BaseComponentArray::copyComponent ( EntityID to,
EntityID from )
pure virtual

Handles the copying of a component from one entity to another within the same array.

Parameters
toThe entity which will receive the copied component
fromThe entity whose component is being copied

Implemented in ToyMaker::ComponentArray< TComponent >.

◆ copyComponent() [2/2]

virtual void ToyMaker::BaseComponentArray::copyComponent ( EntityID to,
EntityID from,
BaseComponentArray & other )
pure virtual

Handles the copying of a component from one entity to another, where the other entity belongs to another ECS World.

Parameters
toThe entity which will receive the copied component
fromThe entity whose component is being copied
otherThe source component array which the entity from belongs to

Implemented in ToyMaker::ComponentArray< TComponent >.

◆ handleEntityDestroyed()

virtual void ToyMaker::BaseComponentArray::handleEntityDestroyed ( EntityID entityID)
pure virtual

A virtual function that handles the side-effect of destroying an entity, i.e., deleting its component in this array.

Parameters
entityIDthe ID of the entity being destroyed

Implemented in ToyMaker::ComponentArray< TComponent >.

◆ handlePreSimulationStep()

virtual void ToyMaker::BaseComponentArray::handlePreSimulationStep ( )
pure virtual

An unimplemented callback for a step that occurs before each simulation step.

For component arrays, this is when you can expect the component values from the next member array to be copied over into previous.

Implemented in ToyMaker::ComponentArray< TComponent >.

◆ hasComponent()

virtual bool ToyMaker::BaseComponentArray::hasComponent ( EntityID entityID) const
pure virtual

Tests whether this array has an entry for this entity.

Parameters
entityIDThe entity whose component is being queried
Return values
trueThe component is present;
falseThe component is absent;

Implemented in ToyMaker::ComponentArray< TComponent >.

◆ instantiate()

virtual std::shared_ptr< BaseComponentArray > ToyMaker::BaseComponentArray::instantiate ( std::weak_ptr< ECSWorld > world) const
pure virtual

Creates a fresh, empty component array and associates it with a new World.

Parameters
worldA pointer to the world the new component array will belong to
Returns
std::shared_ptr<BaseComponentArray> A new component array

Implemented in ToyMaker::ComponentArray< TComponent >.

◆ removeComponent()

virtual void ToyMaker::BaseComponentArray::removeComponent ( EntityID entityID)
pure virtual

Removes the component associated with this entity, if present.

Parameters
entityIDThe entity whose component is being removed

Implemented in ToyMaker::ComponentArray< TComponent >.

◆ updateComponent()

virtual void ToyMaker::BaseComponentArray::updateComponent ( EntityID to,
const nlohmann::json & jsonComponent )
pure virtual

Updates the component associated with an entity based on a json description of a new component.

Parameters
toThe entity whose component is updated
jsonComponentThe component's description in json

Implemented in ToyMaker::ComponentArray< TComponent >.


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