Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
|
A class that represents a set of systems, entities, and components, that are all interrelated, but isolated from other similar sets. More...
#include <ecs_world.hpp>
Classes | |
struct | SystemRegistrationArgs |
Prevents the use of the unspecialized version of SystemRegistrationArgs. More... | |
struct | SystemRegistrationArgs< TSystemDerived, std::tuple< TListenedForComponents... >, std::tuple< TRequiredComponents... > > |
The partially specialized version of SystemRegistrationArgs, with its latter 2 template parameters being tuples of components. More... | |
Public Member Functions | |
std::shared_ptr< ECSWorld > | instantiate () const |
Creates a new ECSWorld using the systems and component arrays present in this one as a template. | |
template<typename TSystem> | |
std::shared_ptr< TSystem > | getSystem () |
Get the system object of a specific type belonging to this ECSWorld. | |
template<typename TSystem> | |
SystemType | getSystemType () |
Get the SystemType id for a particular system. | |
template<typename TSystem> | |
bool | isEnabled (EntityID entityID) |
Tests whether a particular entity is enabled for a particular system. | |
template<typename TSystem> | |
bool | isRegistered (EntityID entityID) |
Tests whether an entity is eligible for membership with a system, per its component signature. | |
template<typename ... TComponents> | |
Entity | createEntity (TComponents...components) |
Creates a new entity that will exist in this ECSWorld. | |
void | initialize () |
Runs the initialization step for this world and the systems that belong to it. | |
void | activateSimulation () |
Marks this world as an active one, calling the activation callbacks of systems that belong to it. | |
void | deactivateSimulation () |
Marks ths world as an inactive one, and suspends operation for its member systems. | |
void | simulationPreStep (uint32_t simStepMillis) |
Runs callbacks associated with the start of a simulation update. | |
void | simulationStep (uint32_t simStepMillis) |
Runs callbacks associated with the simulation step. | |
void | simulationPostStep (uint32_t simStepMillis) |
Runs calbacks associated with the end of the simulation step. | |
void | postTransformUpdate (uint32_t timeStepMillis) |
Runs callbacks associated with the end of transform updates. | |
void | variableStep (float simulationProgress, uint32_t variableStepMillis) |
Runs callbacks associated with the variable step of the game loop. | |
void | preRenderStep (float simulationProgress) |
Runs callbacks associated with the start of the rendering step. | |
void | postRenderStep (float simulationProgress) |
Runs callbacks associated with the end of the rendering step. | |
void | cleanup () |
Loses references to member systems, component arrays, and entities, resulting in their destruction. | |
WorldID | getID () const |
Gets the ID associated with this world. | |
template<typename TSystem, typename ... TListenedForComponents, typename ... TRequiredComponents> | |
void | registerSystem (ECSWorld::SystemRegistrationArgs< TSystem, std::tuple< TListenedForComponents... >, std::tuple< TRequiredComponents... > >) |
Static Public Member Functions | |
static std::weak_ptr< const ECSWorld > | getPrototype () |
Get the prototype ECSWorld. | |
template<typename ... TComponent> | |
static void | registerComponentTypes () |
Registers ComponentArrays for each type of component present in the component type list, if required. | |
template<typename TSystemDerived, typename ... TListenedForComponents, typename ... TRequiredComponents> | |
static void | registerSystem (SystemRegistrationArgs< TSystemDerived, std::tuple< TListenedForComponents... >, std::tuple< TRequiredComponents... > >) |
Registers a System with the ECS System for this project. | |
template<typename TSystem> | |
static std::shared_ptr< TSystem > | getSystemPrototype () |
Get the system object of a specific type belonging to the prototype ECSWorld. | |
template<typename TSingletonSystem> | |
static std::shared_ptr< TSingletonSystem > | getSingletonSystem () |
Get a system that has been marked as a singleton System. | |
template<typename ... TComponents> | |
static Entity | createEntityPrototype (TComponents...components) |
Create a prototype entity object. | |
Private Member Functions | |
ECSWorld ()=default | |
Construct a new ECSWorld object. | |
void | copyComponents (EntityID to, EntityID from) |
Copies components from one entity to another within a single ECSWorld. | |
void | copyComponents (EntityID to, EntityID from, ECSWorld &other) |
Copies components from one entity to another, where the source entity may be from another ECSWorld. | |
void | relocateEntity (Entity &entity) |
Moves an entity from one ECSWorld to this one. | |
template<typename ... TComponents> | |
Entity | privateCreateEntity (TComponents...components) |
Creates a new entity and assigns it the components specified as arguments. | |
void | destroyEntity (EntityID entityID) |
Destroys an Entity with a specific ID. | |
template<typename TSystem> | |
void | enableEntity (EntityID entityID) |
Enables an entity for a specific system. | |
void | enableEntity (EntityID entityID, Signature systemMask=Signature{}.set()) |
Enables an entity for multiple systems, restricted by its component signature and its system mask. | |
template<typename TSystem> | |
void | disableEntity (EntityID entityID) |
Disables an entity on a particular system. | |
void | disableEntity (EntityID entityID) |
Disables an entity for all systems. | |
template<typename TComponent> | |
void | addComponent (EntityID entityID, const TComponent &component) |
Adds a new component to the entity. | |
void | addComponent (EntityID entityID, const nlohmann::json &jsonComponent) |
Adds a new component to an entity based on its description in JSON. | |
template<typename TComponent> | |
TComponent | getComponent (EntityID entityID, float simulationProgress=1.f) const |
Get a component associated with an entity. | |
template<typename TComponent, typename TSystem> | |
TComponent | getComponent (EntityID entityID, float simulationProgress=1.f) const |
Get a component associated with an entity, specialized for Systems. | |
template<typename TComponent> | |
bool | hasComponent (EntityID entityID) const |
Tests whether an entity has a component of a specific type. | |
bool | hasComponent (EntityID entityID, const std::string &typeName) const |
Tests whether an entity has a component of a specific type. | |
template<typename TComponent> | |
void | updateComponent (EntityID entityID, const TComponent &newValue) |
Updates a component belonging to an entity with a new value. | |
void | updateComponent (EntityID entityID, const nlohmann::json &newValue) |
Updates a component belonging to an entity with a new value, based on its JSON description. | |
template<typename TComponent, typename TSystem> | |
void | updateComponent (EntityID entityID, const TComponent &newValue) |
Updates a component belonging to an entity with a new value, noting the System causing the update. | |
template<typename TSystem> | |
void | updateComponent (EntityID entityID, const nlohmann::json &newValue) |
Updates a component belonging to an entity with a new value, noting the system causing the update. | |
template<typename TComponent> | |
void | removeComponent (EntityID entityID) |
Removes a component from an entity. | |
void | removeComponent (EntityID entityID, const std::string &typeName) |
Removes a component from an entity based on its component type string. | |
void | removeComponentsAll (EntityID entityID) |
Removes all components associated with an entity. | |
Static Private Member Functions | |
static std::shared_ptr< ECSWorld > | createWorld () |
Creates an ECSWorld. | |
static std::weak_ptr< ECSWorld > | getInstance () |
Creates an instance of the prototype ECSWorld, and returns a reference to it. | |
Private Attributes | |
std::unique_ptr< ComponentManager > | mComponentManager {nullptr} |
A reference to this world's ComponentManager. | |
std::unique_ptr< SystemManager > | mSystemManager {nullptr} |
A reference to this world SystemManager. | |
std::vector< EntityID > | mDeletedIDs {} |
A list of previously existing entity IDs that were since retired and are available to be used again. | |
EntityID | mNextEntity {} |
A new EntityID that has never been created before in this world. | |
WorldID | mID {0} |
The unique ID associated with this ECSWorld. | |
Static Private Attributes | |
static WorldID | s_nextWorld { 0 } |
The ID the next ECSWorld to be instantiated will receive. | |
Friends | |
class | Entity |
class | BaseSystem |
A class that represents a set of systems, entities, and components, that are all interrelated, but isolated from other similar sets.
A single such set is called an ECSWorld. Each ECSWorld is comprised of a list of entities, a system manager, and a component manager of its own. Entities, systems, and components belonging to one world are not visible to systems in other worlds, or to any other ECSWorld.
|
private |
Adds a new component to an entity based on its description in JSON.
entityID | The entity to which the component is being added. |
jsonComponent | The initial value of the component, described in JSON. |
|
private |
Adds a new component to the entity.
TComponent | The type of component being added. |
entityID | The entity to which the component is being added. |
component | The initial value of the component. |
Copies components from one entity to another within a single ECSWorld.
to | The entity which will receive the copied components. |
from | The entity from whose components will be copied. |
Copies components from one entity to another, where the source entity may be from another ECSWorld.
to | The destination entity, belonging to this world. |
from | The source entity whose components will be copied. |
other | The world that owns the source entity. |
Entity ToyMaker::ECSWorld::createEntity | ( | TComponents... | components | ) |
Creates a new entity that will exist in this ECSWorld.
This mainly means that a new EntityID is created and stored from a list of previously retired IDs or a completely new EntityID. In the same step, and if desired, new components belonging to the entity can be initialized and stored as entries in their respective component arrays.
TComponents | Components to initialize and store right after the entity is created. |
components | The initial values of the components being stored. |
|
static |
Create a prototype entity object.
This is an entity whose components and system membership are stored in the prototype ECSWorld, until it is moved to its actual ECSWorld.
TComponents | Components to initialize and store right after the entity is created. |
components | The initial values of the components being stored. |
|
staticprivate |
Creates an ECSWorld.
|
private |
|
private |
Disables an entity on a particular system.
TSystem | The system for which the entity is being deactivated. |
entityID | The entity being deactivated. |
|
private |
Disables an entity for all systems.
entityID | The entity being deactivated. |
|
private |
Enables an entity for a specific system.
TSystem | The system the entity will be influenced by post-activation. |
entityID | The entity being enabled. |
Enables an entity for multiple systems, restricted by its component signature and its system mask.
entityID | The entity being activated. |
systemMask | Bitset representing which systems the entity is allowed to be activated for. |
|
private |
Get a component associated with an entity.
TComponent | The type of component being retrieved. |
entityID | The entity whose component is being retrieved. |
simulationProgress | The progress since the last simulation step towards the next simulation step, represented as a number between 0 and 1. |
|
private |
Get a component associated with an entity, specialized for Systems.
TComponent | The type of component being retrieved. |
TSystem | The system requesting the component. |
entityID | The entity whose component is being retrieved. |
simulationProgress | The progress since the last simulation step towards the next simulation step, represented as a number between 0 and 1. |
|
inline |
Gets the ID associated with this world.
|
staticprivate |
|
static |
Get the prototype ECSWorld.
The prototype ECSWorld is the first ECSWorld created in a project. All systems and components that register themselves to this module will be registered with this Prototype ECSWorld during the static initialization of the program.
The prototype is then used as a blueprint for instantiating more ECSWorlds, and populating them with the necessary component arrays and systems.
The prototype ECSWorld is also where a newly loaded scene node's components are stored, before it is made a member of the ECSWorld where it actually belongs.
|
static |
Get a system that has been marked as a singleton System.
A singleton System is a system that has no real entities or components of its own, and does not technically belong to any ECSWorld. How it tracks active entities is up to the System's implementation.
Such a system can be assumed to preside over eligible entities across several world. The SceneSystem is one such system.
TSingletonSystem | The type of the singleton System being retrieved. |
std::shared_ptr< TSystem > ToyMaker::ECSWorld::getSystem | ( | ) |
|
static |
Get the system object of a specific type belonging to the prototype ECSWorld.
TSystem | The type of system being retrieved. |
SystemType ToyMaker::ECSWorld::getSystemType | ( | ) |
Get the SystemType id for a particular system.
The SystemType of a system corresponds to a position in the bitset of an entity's system mask, or other system related signatures. Its meaning varies depending on the usage of the bitset.
For the system mask, as seen in a call to SystemManager::enableEntity(), it indicates which systems the manager is expected to activate the entity for.
TSystem | The system whose SystemType id is being retrieved. |
|
private |
Tests whether an entity has a component of a specific type.
TComponent | The type of component being tested. |
entityID | The entity being queried. |
true | Indicates the entity has such a component; |
false | Indicates the entity doesn't have such a component; |
|
private |
Tests whether an entity has a component of a specific type.
entityID | The entity being queried. |
typeName | the component type string of the component being tested. |
true | Indicates the entity has such a component; |
false | Indicates the entity doesn't have such a component; |
std::shared_ptr< ECSWorld > ECSWorld::instantiate | ( | ) | const |
bool ToyMaker::ECSWorld::isEnabled | ( | EntityID | entityID | ) |
Tests whether a particular entity is enabled for a particular system.
TSystem | The system being queried. |
entityID | The entity whose activation is being tested. |
true | Indicates that the entity is enabled for a system; |
false | Indicates that the entity is disabled for a system; |
bool ToyMaker::ECSWorld::isRegistered | ( | EntityID | entityID | ) |
Tests whether an entity is eligible for membership with a system, per its component signature.
TSystem | The system being queried. |
entityID | The entity whose eligibility is being tested. |
true | Indicates the entity is eligible; |
false | Indicates the entity is ineligible. |
void ECSWorld::postRenderStep | ( | float | simulationProgress | ) |
Runs callbacks associated with the end of the rendering step.
simulationProgress | The progress towards the next simulation step since the previous one, represented as a number between 0 and 1. |
void ECSWorld::postTransformUpdate | ( | uint32_t | timeStepMillis | ) |
Runs callbacks associated with the end of transform updates.
timeStepMillis | The time, in milliseconds, since the end of the last transform update. |
void ECSWorld::preRenderStep | ( | float | simulationProgress | ) |
Runs callbacks associated with the start of the rendering step.
simulationProgress | The progress towards the next simulation step since the previous one, represented as a number between 0 and 1. |
|
private |
Creates a new entity and assigns it the components specified as arguments.
TComponents | The types of components to initialize with the entity. |
components | The initial values of the components of the entity. |
|
static |
Registers ComponentArrays for each type of component present in the component type list, if required.
TComponent | The component type(s) being registered. |
|
static |
Registers a System with the ECS System for this project.
This registration occurs at static initialization against the prototype ECSWorld. All other ECSWorlds for a project are derived from the prototype.
Such a system has access to the project's ECS callbacks, and will be notified when any update to one of the entities it manages occurs.
TSystemDerived | The new System being registered. |
TListenedForComponents | A tuple of component types, indicating which component updates the system wants callbacks for. |
TRequiredComponents | A tuple of component types, indicating what components an entity needs to be eligible for management by this system. |
|
private |
|
private |
Removes a component from an entity.
TComponent | The type of component being removed. |
entityID | The entity being updated. |
|
private |
Removes a component from an entity based on its component type string.
entityID | The entity being updated. |
typeName | The component type string of the component being removed. |
|
private |
Removes all components associated with an entity.
entityID | The entity whose components are being removed. |
void ECSWorld::simulationPostStep | ( | uint32_t | simStepMillis | ) |
Runs calbacks associated with the end of the simulation step.
simStepMillis | The time in milliseconds that the simulation will be advanced by. |
void ECSWorld::simulationPreStep | ( | uint32_t | simStepMillis | ) |
Runs callbacks associated with the start of a simulation update.
simStepMillis | The time in milliseconds that the simulation will be advanced by. |
void ECSWorld::simulationStep | ( | uint32_t | simStepMillis | ) |
Runs callbacks associated with the simulation step.
simStepMillis | The time in milliseconds that the simulation will be advanced by. |
|
private |
Updates a component belonging to an entity with a new value, based on its JSON description.
entityID | The entity being updated. |
newValue | The type and new value of the component, described in JSON. |
|
private |
Updates a component belonging to an entity with a new value, noting the system causing the update.
TSystem | The system causing the update. |
entityID | The entity being updated. |
newValue | The new value for the component. |
|
private |
Updates a component belonging to an entity with a new value.
TComponent | The type of component receiving an update. |
entityID | The entity whose component is being updated. |
newValue | The new value the component will have post update. |
|
private |
Updates a component belonging to an entity with a new value, noting the System causing the update.
TComponent | The component being updated. |
TSystem | The system causing the update. |
entityID | The entity being updated. |
newValue | The new value for the component. |
void ECSWorld::variableStep | ( | float | simulationProgress, |
uint32_t | variableStepMillis ) |
Runs callbacks associated with the variable step of the game loop.
The variable step is run once each frame. It may be run multiple times between simulation steps, or once every handful of simulation steps, according to the capabilities of its platform, and be affected by any other ongoing operations taking place on that platform.
simulationProgress | Progress, from 0.0 to 1.0, since the end of the last simulation step and the beginning of the next one. |
variableStepMillis | The time, in milliseconds, since the last frame. |
|
private |
A new EntityID that has never been created before in this world.