ECSTASY
All in the name
Loading...
Searching...
No Matches
Pipeline.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_SYSTEM_PIPELINE_HPP_
13#define ECSTASY_SYSTEM_PIPELINE_HPP_
14
15#include <map>
16#include <typeindex>
17#include <vector>
20
21namespace ecstasy
22{
24 class Registry;
25
32 class Pipeline {
33 public:
38
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 };
59
66 class Phase {
67 private:
76 Phase(Pipeline &pipeline, PhaseId id) : _pipeline(pipeline), _begin(), _size(0), _id(id)
77 {
78 }
79
80 public:
87 void run();
88
96 [[nodiscard]] constexpr std::size_t getSize() const noexcept
97 {
98 return _size;
99 }
100
109 [[nodiscard]] constexpr PhaseId getId() const noexcept
110 {
111 return _id;
112 }
113
122 [[nodiscard]] SystemIterator begin() const noexcept;
123
134 [[nodiscard]] SystemIterator end() const noexcept;
135
150 [[nodiscard]] constexpr Timer &getTimer() noexcept
151 {
152 return _timer;
153 }
154
169 [[nodiscard]] constexpr const Timer &getTimer() const noexcept
170 {
171 return _timer;
172 }
173
174 private:
185
194 [[nodiscard]] constexpr std::size_t begin_idx() const
195 {
196 return _begin;
197 }
198
209 [[nodiscard]] constexpr std::size_t end_idx() const
210 {
211 return _begin + _size;
212 }
213
215 friend Pipeline;
216 };
217
225 Pipeline(Registry &registry);
226
240 [[nodiscard]] Phase &getPhase(PhaseId id, bool autoRegister = true);
241
254 [[nodiscard]] const Phase &getSystemPhase(std::type_index system) const;
255
268 template <std::derived_from<ISystem> S>
269 [[nodiscard]] const Phase &getSystemPhase() const
270 {
271 return getSystemPhase(typeid(S));
272 }
273
286 Phase &registerPhase(PhaseId id);
287
300 void addSystem(std::type_index system, PhaseId phase = static_cast<std::size_t>(PredefinedPhases::OnUpdate));
301
310 void run();
311
320 void run(PhaseId phase);
321
322 private:
329 };
330} // namespace ecstasy
331
332#endif /* !ECSTASY_SYSTEM_PIPELINE_HPP_ */
System interface, base class of all systems.
A phase in the pipeline.
Definition Pipeline.hpp:66
SystemIterator begin() const noexcept
Get the iterator to the first system in this phase.
Definition Pipeline.cpp:18
Phase(Pipeline &pipeline, PhaseId id)
Construct a new empty Phase object.
Definition Pipeline.hpp:76
std::size_t _begin
Index of the first system in this phase.
Definition Pipeline.hpp:178
constexpr Timer & getTimer() noexcept
Get the phase timer.
Definition Pipeline.hpp:150
PhaseId _id
Identifier of the phase.
Definition Pipeline.hpp:182
Pipeline & _pipeline
Owning pipeline.
Definition Pipeline.hpp:176
constexpr std::size_t getSize() const noexcept
Get the number of systems in this phase.
Definition Pipeline.hpp:96
std::size_t _size
Number of systems in this phase.
Definition Pipeline.hpp:180
void run()
Run all systems in this phase.
Definition Pipeline.cpp:28
SystemIterator end() const noexcept
Get the iterator past the last system in this phase.
Definition Pipeline.cpp:23
constexpr const Timer & getTimer() const noexcept
Get the phase timer.
Definition Pipeline.hpp:169
Timer _timer
Timer to control the execution of the phase.
Definition Pipeline.hpp:184
friend Pipeline
Allow Pipeline to access the private members.
Definition Pipeline.hpp:215
constexpr std::size_t begin_idx() const
Get the index of the first system in this phase.
Definition Pipeline.hpp:194
constexpr PhaseId getId() const noexcept
Get the phase ID.
Definition Pipeline.hpp:109
constexpr std::size_t end_idx() const
Get the index past the last system in this phase.
Definition Pipeline.hpp:209
Pipeline of systems to orchestrate the execution of systems.
Definition Pipeline.hpp:32
std::size_t PhaseId
Type of phase identifiers.
Definition Pipeline.hpp:37
PredefinedPhases
Some predefined phases.
Definition Pipeline.hpp:49
@ 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)
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
Phase & registerPhase(PhaseId id)
Register a phase with the given identifier.
Definition Pipeline.cpp:100
const Phase & getSystemPhase() const
Get the phase containing the given system.
Definition Pipeline.hpp:269
void run()
Run a frame of the pipeline.
Definition Pipeline.cpp:59
void addSystem(std::type_index system, PhaseId phase=static_cast< std::size_t >(PredefinedPhases::OnUpdate))
Add a system to the pipeline.
Definition Pipeline.cpp:41
Registry & _registry
Owning registry.
Definition Pipeline.hpp:328
std::vector< std::type_index >::const_iterator SystemIterator
Type of system iterator.
Definition Pipeline.hpp:35
std::vector< std::type_index > _systemsIds
Ordered list of systems.
Definition Pipeline.hpp:324
Base of an ECS architecture.
Definition Registry.hpp:82
Timer class to control the execution of systems.
Definition Timer.hpp:32
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30