ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::Pipeline Class Reference

Pipeline of systems to orchestrate the execution of systems. More...

#include <Pipeline.hpp>

Collaboration diagram for ecstasy::Pipeline:

Classes

class  Phase
 A phase in the pipeline. More...
 

Public Types

enum class  PredefinedPhases : std::size_t {
  OnLoad = 100 , PostLoad = 200 , PreUpdate = 300 , OnUpdate = 400 ,
  OnValidate = 500 , PostUpdate = 600 , PreStore = 700 , OnStore = 800
}
 Some predefined phases. More...
 
using SystemIterator = std::vector< std::type_index >::const_iterator
 Type of system iterator.
 
using PhaseId = std::size_t
 Type of phase identifiers.
 

Public Member Functions

 Pipeline (Registry &registry)
 Construct a new Pipeline owned by the given registry.
 
PhasegetPhase (PhaseId id, bool autoRegister=true)
 Get a Phase instance from its identifier.
 
const PhasegetSystemPhase (std::type_index system) const
 Get the phase containing the given system.
 
template<std::derived_from< ISystem > S>
const PhasegetSystemPhase () const
 Get the phase containing the given system.
 
PhaseregisterPhase (PhaseId id)
 Register a phase with the given identifier.
 
void addSystem (std::type_index system, PhaseId phase=static_cast< std::size_t >(PredefinedPhases::OnUpdate))
 Add a system to the pipeline.
 
void run ()
 Run a frame of the pipeline.
 
void run (PhaseId phase)
 Run a specific phase of the pipeline.
 

Private Attributes

std::vector< std::type_index_systemsIds
 Ordered list of systems.
 
std::map< PhaseId, Phase_phases
 Ordered map of phases.
 
Registry_registry
 Owning registry.
 

Detailed Description

Pipeline of systems to orchestrate the execution of systems.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 32 of file Pipeline.hpp.

Member Typedef Documentation

◆ PhaseId

Type of phase identifiers.

Definition at line 37 of file Pipeline.hpp.

◆ SystemIterator

Type of system iterator.

Definition at line 35 of file Pipeline.hpp.

Member Enumeration Documentation

◆ PredefinedPhases

Some predefined phases.

Note
Theses phases are inspired from the default ones in flecs
The values are arbitrary and can be changed, they allow to insert custom phases between them.
Since
1.0.0 (2024-11-21)
Enumerator
OnLoad 

Load entities into the registry. (Ex: Keyboard inputs)

PostLoad 

After loading entities into the registry. (Ex: Convert inputs to game actions)

PreUpdate 

Before updating entities. (Ex: Initializing an empty frame/clearing the previous one)

OnUpdate 

Update entities, this is the default system. (Ex: Physics simulation)

OnValidate 

Validate entities state after the update. (Ex: Collision detection)

PostUpdate 

After updating entities. (Ex: Collision resolution)

PreStore 

Before storing entities. (Ex: Transform matrices computation)

OnStore 

Store entities. (Ex: Rendering)

Definition at line 49 of file Pipeline.hpp.

49 : std::size_t {
50 OnLoad = 100,
51 PostLoad = 200,
52 PreUpdate = 300,
53 OnUpdate = 400,
54 OnValidate = 500,
55 PostUpdate = 600,
56 PreStore = 700,
57 OnStore = 800,
58 };
@ OnValidate
Validate entities state after the update. (Ex: Collision detection)
@ OnStore
Store entities. (Ex: Rendering)
@ PostLoad
After loading entities into the registry. (Ex: Convert inputs to game actions)
@ PreUpdate
Before updating entities. (Ex: Initializing an empty frame/clearing the previous one)
@ PreStore
Before storing entities. (Ex: Transform matrices computation)
@ OnLoad
Load entities into the registry. (Ex: Keyboard inputs)
@ PostUpdate
After updating entities. (Ex: Collision resolution)
@ OnUpdate
Update entities, this is the default system. (Ex: Physics simulation)

Constructor & Destructor Documentation

◆ Pipeline()

ecstasy::Pipeline::Pipeline ( Registry registry)

Construct a new Pipeline owned by the given registry.

Parameters
[in]registryThe registry owning this pipeline.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 37 of file Pipeline.cpp.

37 : _registry(registry)
38 {
39 }
Registry & _registry
Owning registry.
Definition Pipeline.hpp:328

Member Function Documentation

◆ addSystem()

void ecstasy::Pipeline::addSystem ( std::type_index  system,
Pipeline::PhaseId  phaseId = static_cast<std::size_t>(PredefinedPhases::OnUpdate) 
)

Add a system to the pipeline.

Note
The systems are owned by the registry, not the pipeline.
Parameters
[in]systemType of the system to add.
[in]phasePhase in which the system should be. Default is OnUpdate.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Need to update all phases iterators

Definition at line 41 of file Pipeline.cpp.

42 {
43 Phase &phase = getPhase(phaseId);
44
45 // Phase end is always after the last valid system (like end() in std::vector)
46 _systemsIds.insert(_systemsIds.begin() + static_cast<long>(phase.end_idx()), system);
47 ++phase._size;
48
50 auto phaseIt = _phases.find(phaseId);
51 size_t nextPhaseBegin = phase.end_idx();
52
53 for (++phaseIt; phaseIt != _phases.end(); ++phaseIt) {
54 phaseIt->second._begin = nextPhaseBegin;
55 nextPhaseBegin = phaseIt->second.end_idx();
56 }
57 }
T begin(T... args)
Phase & getPhase(PhaseId id, bool autoRegister=true)
Get a Phase instance from its identifier.
Definition Pipeline.cpp:76
std::map< PhaseId, Phase > _phases
Ordered map of phases.
Definition Pipeline.hpp:326
std::vector< std::type_index > _systemsIds
Ordered list of systems.
Definition Pipeline.hpp:324
T insert(T... args)

◆ getPhase()

Pipeline::Phase & ecstasy::Pipeline::getPhase ( Pipeline::PhaseId  id,
bool  autoRegister = true 
)

Get a Phase instance from its identifier.

Create it if it does not exist.

Parameters
[in]idIdentifier of the phase.
[in]autoRegisterWhether to register the phase if it does not exist. Default is true.
Returns
Phase& Reference to the phase.
Exceptions
std::out_of_rangeIf the phase does not exist and autoRegister is false.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 76 of file Pipeline.cpp.

77 {
78 if (autoRegister)
79 return registerPhase(id);
80 auto it = _phases.find(id);
81
82 if (it != _phases.end())
83 return it->second;
84 throw std::out_of_range("Phase not found");
85 }
Phase & registerPhase(PhaseId id)
Register a phase with the given identifier.
Definition Pipeline.cpp:100

◆ getSystemPhase() [1/2]

template<std::derived_from< ISystem > S>
const Phase & ecstasy::Pipeline::getSystemPhase ( ) const
inline

Get the phase containing the given system.

Template Parameters
SType of the system to find.
Returns
const Phase& Reference to the phase containing the system.
Exceptions
std::out_of_rangeIf the system is not in any phase.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 269 of file Pipeline.hpp.

270 {
271 return getSystemPhase(typeid(S));
272 }
const Phase & getSystemPhase() const
Get the phase containing the given system.
Definition Pipeline.hpp:269

◆ getSystemPhase() [2/2]

const Pipeline::Phase & ecstasy::Pipeline::getSystemPhase ( std::type_index  system) const

Get the phase containing the given system.

Parameters
[in]systemType of the system to find.
Returns
Phase& Reference to the phase containing the system.
Exceptions
std::out_of_rangeIf the system is not in any phase.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 87 of file Pipeline.cpp.

88 {
89 auto it = std::find(_systemsIds.begin(), _systemsIds.end(), system);
90
91 if (it == _systemsIds.end())
92 throw std::out_of_range("System not found in any phase");
93 for (auto &phase : _phases) {
94 if (it >= phase.second.begin() && it < phase.second.end())
95 return phase.second;
96 }
97 throw std::out_of_range("System not found in any phase");
98 }
T end(T... args)
T find(T... args)

◆ registerPhase()

Pipeline::Phase & ecstasy::Pipeline::registerPhase ( Pipeline::PhaseId  id)

Register a phase with the given identifier.

Note
Does nothing if the phase already exists.
Parameters
[in]idIdentifier of the phase.
Returns
Phase& Reference to the newly created phase.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 100 of file Pipeline.cpp.

101 {
102 auto it = _phases.find(id);
103
104 if (it != _phases.end())
105 return it->second;
106
107 it = _phases.emplace(id, Phase(*this, id)).first;
108 Phase &phase = it->second;
109
110 // No phase preceeding this one, set begin to the start of the systems list
111 if (it == _phases.begin()) {
112 phase._begin = 0;
113 } else {
114 phase._begin = std::prev(it)->second.end_idx();
115 }
116 // No need to update following phases since our phase is empty
117 return phase;
118 }
T prev(T... args)

◆ run() [1/2]

void ecstasy::Pipeline::run ( )

Run a frame of the pipeline.

Note
This will run all phases by ascending order of their identifier.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 59 of file Pipeline.cpp.

60 {
61 for (auto &phase : _phases) {
62 phase.second.run();
63 }
64 }

◆ run() [2/2]

void ecstasy::Pipeline::run ( Pipeline::PhaseId  phase)

Run a specific phase of the pipeline.

Parameters
[in]phaseIdentifier of the phase to run.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 66 of file Pipeline.cpp.

67 {
68 auto phaseIt = _phases.find(phase);
69
70 if (phaseIt == _phases.end())
71 return;
72
73 phaseIt->second.run();
74 }

Member Data Documentation

◆ _phases

std::map<PhaseId, Phase> ecstasy::Pipeline::_phases
private

Ordered map of phases.

Definition at line 326 of file Pipeline.hpp.

◆ _registry

Registry& ecstasy::Pipeline::_registry
private

Owning registry.

Definition at line 328 of file Pipeline.hpp.

◆ _systemsIds

std::vector<std::type_index> ecstasy::Pipeline::_systemsIds
private

Ordered list of systems.

Definition at line 324 of file Pipeline.hpp.


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