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::SystemManager Class Reference

Holds references to all the systems belonging to this manager's ECSWorld. More...

#include <ecs_world.hpp>

Public Member Functions

 SystemManager (std::weak_ptr< ECSWorld > world)
 Construct a new System Manager object.
 

Private Member Functions

SystemManager instantiate (std::weak_ptr< ECSWorld > world) const
 Creates a new system manager containing fresh copies of the same systems this manager uses, and associates it with the new world.
 
template<typename TSystem>
void registerSystem (const Signature &signature, const Signature &listenedForComponents)
 During static initialization, adds the new System type and its component signatures to its tables.
 
void unregisterAll ()
 Removes all references to managed systems, in preparation for destruction.
 
template<typename TSystem>
std::shared_ptr< TSystem > getSystem ()
 Gets an instance of a system belonging to this ECS World.
 
template<typename TSystem>
void enableEntity (EntityID entityID)
 Enables the visibility of an entity to a particular system.
 
void enableEntity (EntityID entityID, Signature entitySignature, Signature systemMask=Signature{}.set())
 Enables an entity for all eligible systems, per its component signature and the system mask.
 
template<typename TSystem>
void disableEntity (EntityID entityID)
 Disables an entity for a particular system.
 
void disableEntity (EntityID entityID, Signature entitySignature)
 Disables all systems which match this entity's signature.
 
template<typename TSystem>
SystemType getSystemType () const
 Get the SystemType for a system.
 
template<typename TSystem>
bool isEnabled (EntityID entityID)
 Tests whether an entity is enabled for a particular system.
 
template<typename TSystem>
bool isRegistered (EntityID entityID)
 Tests whether an entity is eligible for participation in a particular system.
 
void handleEntitySignatureChanged (EntityID entityID, Signature signature)
 A callback for when components are added or removed from a particular entity, causing a corresponding change in its component signature, and addition or removal from various systems.
 
void handleEntityDestroyed (EntityID entityID)
 A callback for the destruction of an entity, passed on to systems interested in it.
 
void handleEntityUpdated (EntityID entityID, Signature signature, ComponentType updatedComponent)
 Handles an update to an entity by running a callback on all interested systems.
 
template<typename TSystem>
void handleEntityUpdatedBySystem (EntityID entityID, Signature signature, ComponentType updatedComponent)
 Handles an update to an entity by running a callback on all interested systems (except the one that triggered the update)
 
void handleInitialize ()
 Runs the initialization callback of all systems that implement it.
 
void handleSimulationActivated ()
 Runs the activation callback of all systems that implement it.
 
void handleSimulationPreStep (uint32_t simStepMillis)
 Runs the sim prestep callback of all systems that implement it.
 
void handleSimulationStep (uint32_t simStepMillis)
 Runs the sim step callback for all systems that implement it.
 
void handleSimulationPostStep (uint32_t simStepMillis)
 Runs the post simulation step callback for all systems that implement it.
 
void handlePostTransformUpdate (uint32_t timeStepMillis)
 Runs the update callback that occurs after new transforms have been computed.
 
void handleVariableStep (float simulationProgress, uint32_t variableStepMillis)
 Runs the System callback that occurs once every frame, after any simulation steps computed that frame.
 
void handlePreRenderStep (float simulationProgress)
 Runs the System callback that occurs once before the scene in this ECSWorld is rendered.
 
void handlePostRenderStep (float simulationProgress)
 Runs the System callback after the scene in this ECSWorld has been rendered.
 
void handleSimulationDeactivated ()
 Runs the System callback for deactivation, for any systems that have implemented it.
 

Private Attributes

std::unordered_map< std::string, SignaturemNameToSignature {}
 Mapping from the system type name for a system to its component signature.
 
std::unordered_map< std::string, SignaturemNameToListenedForComponents {}
 Mapping from the system type name for a system to its component listening signature.
 
std::unordered_map< std::string, SystemTypemNameToSystemType {}
 Maps system type names to their corresponding SystemType values.
 
std::unordered_map< std::string, std::shared_ptr< BaseSystem > > mNameToSystem {}
 Maps system type names to references to the actual in-memory Systems they represent.
 
std::weak_ptr< ECSWorldmWorld
 The world this System manager belongs to.
 

Friends

class ECSWorld
 
class BaseSystem
 

Detailed Description

Holds references to all the systems belonging to this manager's ECSWorld.

The system manager is responsible for keeping track of and passing messages to the various systems in this world. It also maintains tables to track entity membership and activation for all the systems it manages.

Constructor & Destructor Documentation

◆ SystemManager()

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

Construct a new System Manager object.

Parameters
worldThe world the system manager belongs to.

Member Function Documentation

◆ disableEntity() [1/2]

template<typename TSystem>
void ToyMaker::SystemManager::disableEntity ( EntityID entityID)
private

Disables an entity for a particular system.

Template Parameters
TSystemThe system for which this entity will be disabled.
Parameters
entityIDThe entity being disabled.

◆ disableEntity() [2/2]

void SystemManager::disableEntity ( EntityID entityID,
Signature entitySignature )
private

Disables all systems which match this entity's signature.

Parameters
entityIDThe entity being disabled.
entitySignatureThe component signature of this entity.

◆ enableEntity() [1/2]

template<typename TSystem>
void ToyMaker::SystemManager::enableEntity ( EntityID entityID)
private

Enables the visibility of an entity to a particular system.

Template Parameters
TSystemThe system for which the entity is being enabled.
Parameters
entityIDThe entity being enabled.

◆ enableEntity() [2/2]

void SystemManager::enableEntity ( EntityID entityID,
Signature entitySignature,
Signature systemMask = Signature{}.set() )
private

Enables an entity for all eligible systems, per its component signature and the system mask.

The position of each bit on the entitySignature corresponds to the type of a system. 1 indicates that this system ought to be enabled for this entity if possible, while 0 indicates no change.

Parameters
entityIDThe entity being enabled for multiple system.
entitySignatureThe component signature for this entity, which must match that of the system.
systemMaskThe systems for which this enabling should be performed.

◆ getSystem()

template<typename TSystem>
std::shared_ptr< TSystem > ToyMaker::SystemManager::getSystem ( )
private

Gets an instance of a system belonging to this ECS World.

Template Parameters
TSystemThe type of system whose instance is being retrieved.
Returns
std::shared_ptr<TSystem> The retrieved System reference.

◆ getSystemType()

template<typename TSystem>
SystemType ToyMaker::SystemManager::getSystemType ( ) const
private

Get the SystemType for a system.

The SystemType of a System corresponds to a position on the bitset of various System Masks, and its meaning varies according to context.

Template Parameters
TSystemThe System for which the SystemType id is being retrieved.
Returns
SystemType The SystemType id for a system.

◆ handleEntityDestroyed()

void SystemManager::handleEntityDestroyed ( EntityID entityID)
private

A callback for the destruction of an entity, passed on to systems interested in it.

Parameters
entityIDThe entity being destroyed.

◆ handleEntitySignatureChanged()

void SystemManager::handleEntitySignatureChanged ( EntityID entityID,
Signature signature )
private

A callback for when components are added or removed from a particular entity, causing a corresponding change in its component signature, and addition or removal from various systems.

Parameters
entityIDThe entity whose component signature has changed.
signatureThe entity's new component signature.

◆ handleEntityUpdated()

void SystemManager::handleEntityUpdated ( EntityID entityID,
Signature signature,
ComponentType updatedComponent )
private

Handles an update to an entity by running a callback on all interested systems.

Parameters
entityIDThe entity whose component was updated.
signatureThe component signature of the entity.
updatedComponentThe ComponentType of the updated component.

◆ handleEntityUpdatedBySystem()

template<typename TSystem>
void ToyMaker::SystemManager::handleEntityUpdatedBySystem ( EntityID entityID,
Signature signature,
ComponentType updatedComponent )
private

Handles an update to an entity by running a callback on all interested systems (except the one that triggered the update)

Template Parameters
TSystemThe system which caused the component update.
Parameters
entityIDThe entity whose component was updated.
signatureThe component signature of the entity.
updatedComponentThe ComponentType of the updated component.

◆ handleInitialize()

void SystemManager::handleInitialize ( )
private

Runs the initialization callback of all systems that implement it.

See also
BaseSystem::onInitialize()

◆ handlePostRenderStep()

void SystemManager::handlePostRenderStep ( float simulationProgress)
private

Runs the System callback after the scene in this ECSWorld has been rendered.

Parameters
simulationProgressProgress since the last simulation step, a number between 0.0 and 1.0.

◆ handlePostTransformUpdate()

void SystemManager::handlePostTransformUpdate ( uint32_t timeStepMillis)
private

Runs the update callback that occurs after new transforms have been computed.

Parameters
timeStepMillisSimulation time since the end of the last transform update.
See also
BaseSystem::onPostTransformUpdate()

◆ handlePreRenderStep()

void SystemManager::handlePreRenderStep ( float simulationProgress)
private

Runs the System callback that occurs once before the scene in this ECSWorld is rendered.

Parameters
simulationProgressProgress since the last simulation step towards the next simulation step, a number between 0.0 and 1.0.
See also
BaseSystem::onPreRenderStep()

◆ handleSimulationActivated()

void SystemManager::handleSimulationActivated ( )
private

Runs the activation callback of all systems that implement it.

See also
BaseSystem::onSimulationActivated()

◆ handleSimulationPostStep()

void SystemManager::handleSimulationPostStep ( uint32_t simStepMillis)
private

Runs the post simulation step callback for all systems that implement it.

Parameters
simStepMillisTime by which the simulation will advance this frame, in milliseconds.
See also
BaseSystem::onSimulationPostStep()

◆ handleSimulationPreStep()

void SystemManager::handleSimulationPreStep ( uint32_t simStepMillis)
private

Runs the sim prestep callback of all systems that implement it.

Parameters
simStepMillisTime by which the simulation will advance this update, in milliseconds.
See also
BaseSystem::onSimulationPreStep()

◆ handleSimulationStep()

void SystemManager::handleSimulationStep ( uint32_t simStepMillis)
private

Runs the sim step callback for all systems that implement it.

Parameters
simStepMillisTime by which the simulation will advance this frame, in milliseconds.
See also
BaseSystem::onSimulationStep()

◆ handleVariableStep()

void SystemManager::handleVariableStep ( float simulationProgress,
uint32_t variableStepMillis )
private

Runs the System callback that occurs once every frame, after any simulation steps computed that frame.

Parameters
simulationProgressProgress since the last simulation step towards the next simulation step, a number between 0.0 and 1.0.
variableStepMillisTime (in milliseconds) since the last variable step
See also
BaseSystem::onVariableStep()

◆ instantiate()

SystemManager SystemManager::instantiate ( std::weak_ptr< ECSWorld > world) const
private

Creates a new system manager containing fresh copies of the same systems this manager uses, and associates it with the new world.

Parameters
worldThe world to which the instantiated manager will be related.
Returns
SystemManager The new manager templated off the current one.

◆ isEnabled()

template<typename TSystem>
bool ToyMaker::SystemManager::isEnabled ( EntityID entityID)
private

Tests whether an entity is enabled for a particular system.

Template Parameters
TSystemThe system being queried.
Parameters
entityIDThe entity whose activation is being tested.
Return values
trueIndicates the entity is active;
falseIndicates the entity is inactive;

◆ isRegistered()

template<typename TSystem>
bool ToyMaker::SystemManager::isRegistered ( EntityID entityID)
private

Tests whether an entity is eligible for participation in a particular system.

Template Parameters
TSystemThe system being queried.
Parameters
entityIDThe entity whose compatibility is being tested.
Return values
trueIndicates the entity is eligible;
falseIndicates the entity is ineligible;

◆ registerSystem()

template<typename TSystem>
void ToyMaker::SystemManager::registerSystem ( const Signature & signature,
const Signature & listenedForComponents )
private

During static initialization, adds the new System type and its component signatures to its tables.

This allows the System to receive callbacks from this manager. It also allows the manager to determine if and when a particular system should receive component-related updates.

Template Parameters
TSystemThe system being registered against the system manager.
Parameters
signatureThe component signature of the system, indicating which components an entity is required to have to be eligible for a particular system.
listenedForComponentsThe components this System would like to listen for updates for, when they occur on an entity enabled for it.

Member Data Documentation

◆ mNameToListenedForComponents

std::unordered_map<std::string, Signature> ToyMaker::SystemManager::mNameToListenedForComponents {}
private

Mapping from the system type name for a system to its component listening signature.

When an entity enabled for a system has one of its components updated, and that component is marked in the systems listening signature, the corresponding system will be notified.

◆ mNameToSignature

std::unordered_map<std::string, Signature> ToyMaker::SystemManager::mNameToSignature {}
private

Mapping from the system type name for a system to its component signature.

Only entities with Signatures that match a System's signature may be influenced by it.

◆ mNameToSystemType

std::unordered_map<std::string, SystemType> ToyMaker::SystemManager::mNameToSystemType {}
private

Maps system type names to their corresponding SystemType values.

Each position on an entity's SystemMask (as provided in enableEntity()) corresponds to a value of SystemType, and indicates whether the entity is to be enabled or left alone for that System.


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