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

The base class that acts as the interface between the engine's ECS system and a particular built-in or user-defined System. More...

#include <ecs_world.hpp>

Inheritance diagram for ToyMaker::BaseSystem:
ToyMaker::System< TSystemDerived, std::tuple< TListenedForComponents... >, std::tuple< TRequiredComponents... > >

Public Member Functions

 BaseSystem (std::weak_ptr< ECSWorld > world)
 Construct a new Base System object.
 
virtual ~BaseSystem ()=default
 Destroy the Base System object.
 
virtual bool isSingleton () const
 A method to query whether a particular System is a singleton, or is instantiated for each world in the project.
 

Protected Member Functions

const std::set< EntityID > & getEnabledEntities ()
 Get a set of all entities that are influenced by this System.
 
template<typename TComponent, typename TSystem>
TComponent getComponent_ (EntityID entityID, float progress=1.f) const
 The actual implementation of getComponent for a system.
 
template<typename TComponent, typename TSystem>
void updateComponent_ (EntityID entityID, const TComponent &component)
 The actual implementation of updateComponent for a system.
 
bool isEnabled (EntityID entityID) const
 Tests whether a particular entity is active for this system.
 
bool isRegistered (EntityID entityID) const
 Tests whether a particular entity can be influenced by this system.
 
virtual std::shared_ptr< BaseSysteminstantiate (std::weak_ptr< ECSWorld > world)=0
 Creates a fresh copy of this system and associates it with a new ECS World, using this system as its template.
 

Protected Attributes

std::weak_ptr< ECSWorldmWorld
 A reference to the world this system belongs to.
 

Private Member Functions

void addEntity (EntityID entityID, bool enabled=true)
 Adds an entity to this system.
 
void removeEntity (EntityID entityID)
 Removes an entity from this system.
 
void enableEntity (EntityID entityID)
 Allows a registered entity to be influenced by this system.
 
void disableEntity (EntityID entityID)
 Prevents the influencing of an entity by this system.
 
virtual void onEntityEnabled (EntityID entityID)
 An overridable callback for when an entity has been enabled.
 
virtual void onEntityDisabled (EntityID entityID)
 An overridable callback for when an entity has been disabled.
 
virtual void onEntityUpdated (EntityID entityID)
 An overridable callback for when another system has updated a component shared by this system and an entity.
 
virtual void onInitialize ()
 An overridable callback for right after an ECS world has just been created.
 
virtual void onSimulationActivated ()
 An overridable callback for right after the ECS World has been activated.
 
virtual void onSimulationPreStep (uint32_t simStepMillis)
 An overridable callback called once at the beginning of every simulation step in the game loop.
 
virtual void onSimulationStep (uint32_t simStepMillis)
 An overridable callback called once in the middle of every simulation step.
 
virtual void onSimulationPostStep (uint32_t simStepMillis)
 An overridable callback called once at the end of this simulation step, and after related transform updates are applied.
 
virtual void onPostTransformUpdate (uint32_t timeStepMillis)
 An overridable callback called after all the transforms in the scene are updated by the scene system.
 
virtual void onVariableStep (float simulationProgress, uint32_t variableStepMillis)
 Overridable callback called after all simulation updates (if any) for the current frame have been completed.
 
virtual void onPreRenderStep (float simulationProgress)
 Overridable callback called just before the render step takes place.
 
virtual void onPostRenderStep (float simulationProgress)
 Overridable callback called just after the render step takes place.
 
virtual void onSimulationDeactivated ()
 Overridable callback called just after the ECS world owning this system has been deactivated.
 
virtual void onDestroyed ()
 Overridable callback called just before this system is destroyed.
 

Private Attributes

std::set< EntityIDmEnabledEntities {}
 A set of all entities that are actively influenced by this system, managed by this system's ECS world.
 
std::set< EntityIDmDisabledEntities {}
 A set of all entities that are compatible with this system, but have not been enabled for it.
 

Friends

class SystemManager
 
class ECSWorld
 

Detailed Description

The base class that acts as the interface between the engine's ECS system and a particular built-in or user-defined System.

Constructor & Destructor Documentation

◆ BaseSystem()

ToyMaker::BaseSystem::BaseSystem ( std::weak_ptr< ECSWorld > world)
inline

Construct a new Base System object.

Parameters
worldThe world the System belongs to

Member Function Documentation

◆ addEntity()

void BaseSystem::addEntity ( EntityID entityID,
bool enabled = true )
private

Adds an entity to this system.

Parameters
entityIDThe entity being added.
enabledWhether the entity should be influenced by this system after being added.

◆ disableEntity()

void BaseSystem::disableEntity ( EntityID entityID)
private

Prevents the influencing of an entity by this system.

Parameters
entityIDThe entity being disabled for this system.

◆ enableEntity()

void BaseSystem::enableEntity ( EntityID entityID)
private

Allows a registered entity to be influenced by this system.

Parameters
entityIDThe entity being enabled for this system.

◆ getComponent_()

template<typename TComponent, typename TSystem>
TComponent ToyMaker::BaseSystem::getComponent_ ( EntityID entityID,
float progress = 1.f ) const
protected

The actual implementation of getComponent for a system.

Template Parameters
TComponentThe type of component being retrieved.
TSystemThe system for which the component is retrieved.
Parameters
entityIDThe entity that owns the component.
progressThe progress (0-1) between the previous sim tick and the next sim tick.
Returns
TComponent The (interpolated) state of the component.

◆ getEnabledEntities()

const std::set< EntityID > & BaseSystem::getEnabledEntities ( )
protected

Get a set of all entities that are influenced by this System.

Returns
const std::set<EntityID>& The active set of entities.

◆ instantiate()

virtual std::shared_ptr< BaseSystem > ToyMaker::BaseSystem::instantiate ( std::weak_ptr< ECSWorld > world)
protectedpure virtual

Creates a fresh copy of this system and associates it with a new ECS World, using this system as its template.

Parameters
worldThe world the new system will be associated with.
Returns
std::shared_ptr<BaseSystem> The fresh copy of this system.

Implemented in ToyMaker::System< TSystemDerived, std::tuple< TListenedForComponents... >, std::tuple< TRequiredComponents... > >.

◆ isEnabled()

bool BaseSystem::isEnabled ( EntityID entityID) const
protected

Tests whether a particular entity is active for this system.

Parameters
entityIDThe entity being queried.
Return values
trueIndicates that the entity is influenced by this system;
falseIndicates that the entity is not influenced by this system;

◆ isRegistered()

bool BaseSystem::isRegistered ( EntityID entityID) const
protected

Tests whether a particular entity can be influenced by this system.

Parameters
entityIDThe entity being queried.
Return values
trueIndicates that the entity's component signature matches this system's component signature;
falseIndicates that the component signatures do not match;

◆ isSingleton()

virtual bool ToyMaker::BaseSystem::isSingleton ( ) const
inlinevirtual

A method to query whether a particular System is a singleton, or is instantiated for each world in the project.

Return values
trueThis system is a singleton, and manages entities across worlds;
falseThis system belongs to the world it is a part of, and is instantiated once for each world;

◆ onDestroyed()

virtual void ToyMaker::BaseSystem::onDestroyed ( )
inlineprivatevirtual

Overridable callback called just before this system is destroyed.

Useful if this system has some special bookkeeping it needs to perform before it is retired.

◆ onEntityDisabled()

virtual void ToyMaker::BaseSystem::onEntityDisabled ( EntityID entityID)
inlineprivatevirtual

An overridable callback for when an entity has been disabled.

Useful if the system has related bookkeeping of its own that it would need to update in such an event.

Parameters
entityIDThe disabled entity.

◆ onEntityEnabled()

virtual void ToyMaker::BaseSystem::onEntityEnabled ( EntityID entityID)
inlineprivatevirtual

An overridable callback for when an entity has been enabled.

Useful if the system has related bookkeeping of its own that it would need to update in such an event.

Parameters
entityIDThe enabled entity.

◆ onEntityUpdated()

virtual void ToyMaker::BaseSystem::onEntityUpdated ( EntityID entityID)
inlineprivatevirtual

An overridable callback for when another system has updated a component shared by this system and an entity.

Parameters
entityIDThe updated entity.

◆ onPostRenderStep()

virtual void ToyMaker::BaseSystem::onPostRenderStep ( float simulationProgress)
inlineprivatevirtual

Overridable callback called just after the render step takes place.

Parameters
simulationProgressThe progress towards the next simulation step as a value between 0.0 and 1.0, calculated using time since last simulation step / (time of next simulation step - time of last simulation step)

◆ onPostTransformUpdate()

virtual void ToyMaker::BaseSystem::onPostTransformUpdate ( uint32_t timeStepMillis)
inlineprivatevirtual

An overridable callback called after all the transforms in the scene are updated by the scene system.

Parameters
timeStepMillisThe time by which the simulation must be moved forward.

◆ onPreRenderStep()

virtual void ToyMaker::BaseSystem::onPreRenderStep ( float simulationProgress)
inlineprivatevirtual

Overridable callback called just before the render step takes place.

Parameters
simulationProgressThe progress towards the next simulation step as a value between 0.0 and 1.0, calculated using time since last simulation step / (time of next simulation step - time of last simulation step)

◆ onSimulationDeactivated()

virtual void ToyMaker::BaseSystem::onSimulationDeactivated ( )
inlineprivatevirtual

Overridable callback called just after the ECS world owning this system has been deactivated.

Required if this system has some special bookkeeping it needs to perform before it is suspended.

◆ onSimulationPostStep()

virtual void ToyMaker::BaseSystem::onSimulationPostStep ( uint32_t simStepMillis)
inlineprivatevirtual

An overridable callback called once at the end of this simulation step, and after related transform updates are applied.

Parameters
simStepMillisThe time by which the simulation must be moved forward.

◆ onSimulationPreStep()

virtual void ToyMaker::BaseSystem::onSimulationPreStep ( uint32_t simStepMillis)
inlineprivatevirtual

An overridable callback called once at the beginning of every simulation step in the game loop.

Parameters
simStepMillisThe time by which the simulation must be moved forward.

◆ onSimulationStep()

virtual void ToyMaker::BaseSystem::onSimulationStep ( uint32_t simStepMillis)
inlineprivatevirtual

An overridable callback called once in the middle of every simulation step.

The simulation step is the same regardless of time that has elapsed since the last frame. If a lot of time has passed, multiple simulation steps are computed in this frame, and conversely if very little time has passed, no simulation step is computed this frame.

Parameters
simStepMillisThe time by which the simulation must be moved forward.

◆ onVariableStep()

virtual void ToyMaker::BaseSystem::onVariableStep ( float simulationProgress,
uint32_t variableStepMillis )
inlineprivatevirtual

Overridable callback called after all simulation updates (if any) for the current frame have been completed.

May be called multiple times between two simulation frames, or once every couple of simulation frames, depending on the cability of the current computer and operations being performed on it simultaneously.

Parameters
simulationProgressThe progress towards the next simulation step as a value between 0.0 and 1.0, calculated using time since last simulation step / (time of next simulation step - time of last simulation step)
variableStepMillisThe real time that has passed since the computation of the last frame (NOT the last simulation step).

◆ removeEntity()

void BaseSystem::removeEntity ( EntityID entityID)
private

Removes an entity from this system.

Parameters
entityIDThe entity being removed.

◆ updateComponent_()

template<typename TComponent, typename TSystem>
void ToyMaker::BaseSystem::updateComponent_ ( EntityID entityID,
const TComponent & component )
protected

The actual implementation of updateComponent for a system.

Template Parameters
TComponentThe type of component being updated.
TSystemThe system triggering the update.
Parameters
entityIDThe entity that owns the component.
componentThe new value of the component after the update.

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