6#include <aegis2d/ecs/export.hpp>
32 [[nodiscard]]
constexpr float delta() const noexcept {
33 return std::chrono::duration<float>{
step}.count();
116 template <
std::derived_from<
ISystem> System, typename... Args>
117 requires
std::constructible_from<System, Args...>
118 System& add(
std::
string name, Args&&... args) {
119 auto system = std::make_unique<System>(std::forward<Args>(args)...);
120 System& added = *system;
121 add(std::move(name), std::move(system));
132 ISystem&
add(std::string name, std::unique_ptr<ISystem> system);
152 [[nodiscard]]
bool contains(std::string_view name)
const noexcept;
167 [[nodiscard]]
bool enabled(std::string_view name)
const;
171 [[nodiscard]] std::vector<std::string_view>
names()
const;
175 [[nodiscard]] std::size_t
size() const noexcept;
179 [[nodiscard]]
bool empty() const noexcept;
188 void update(
Registry& registry, core::Duration step);
193 void set_profiler(core::Profiler* profiler) noexcept;
197 [[nodiscard]]
std::uint64_t ticks() const noexcept;
201 [[nodiscard]]
bool updating() const noexcept;
206 std::unique_ptr<ISystem> system;
210 void check_not_updating(std::string_view action)
const;
211 [[nodiscard]] std::vector<Entry>::iterator find(std::string_view name)
noexcept;
212 [[nodiscard]] std::vector<Entry>::const_iterator find(std::string_view name)
const noexcept;
213 [[nodiscard]] Entry& entry(std::string_view name);
214 [[nodiscard]]
const Entry& entry(std::string_view name)
const;
216 std::vector<Entry> systems_;
217 std::uint64_t ticks_ = 0;
219 bool updating_ =
false;
Timers around the parts of a frame (its phases, each system of a ecs::Scheduler......
Definition profiler.hpp:92
System made of a function, for logic that keeps no state of its own.
Definition system.hpp:59
void update(Registry ®istry, const Tick &tick) override
Calls the function.
std::function< void(Registry ®istry, const Tick &tick)> Function
Signature of the function: the same as ISystem::update().
Definition system.hpp:62
FunctionSystem(Function function)
Wraps a function.
Game logic run on the registry once per tick (movement, collisions, spawns...).
Definition system.hpp:42
ISystem & operator=(const ISystem &)=delete
ISystem(ISystem &&)=delete
ISystem(const ISystem &)=delete
virtual ~ISystem()
Releases the system's own state.
virtual void update(Registry ®istry, const Tick &tick)=0
Runs the system for one tick.
ISystem & operator=(ISystem &&)=delete
Entry point of the ECS: creates entities and stores their components.
Definition registry.hpp:34
Ordered list of named systems, all updated once per tick.
Definition system.hpp:100
std::size_t size() const noexcept
Number of systems, enabled or not.
FunctionSystem & add(std::string name, FunctionSystem::Function function)
Adds a function as a system after the others.
void set_enabled(std::string_view name, bool enabled)
Enables or disables a system; a disabled system keeps its place but is skipped by update().
bool enabled(std::string_view name) const
Tells whether a system runs on update().
bool contains(std::string_view name) const noexcept
Tells whether a system has this name.
ISystem & add(std::string name, std::unique_ptr< ISystem > system)
Adds a system after the others.
bool remove(std::string_view name)
Removes a system; the others keep their order.
std::vector< std::string_view > names() const
Names of the systems, in update order.
Scheduler(Scheduler &&) noexcept=default
Scheduler & operator=(const Scheduler &)=delete
Scheduler(const Scheduler &)=delete
Fixed-timestep accumulator and monotonic stopwatch.
std::chrono::nanoseconds Duration
Duration type used for simulation time (nanoseconds).
Definition clock.hpp:14
Entity-Component-System used by client and server.
Definition animation.hpp:13
Definition endpoint.hpp:85
Timers around the parts of a frame, and the breakdown of the last frame.
Registry: owns the entities and one component pool per component type.
One simulation step, as the systems see it.
Definition system.hpp:23
constexpr float delta() const noexcept
Duration of the step in seconds, to scale values given per second.
Definition system.hpp:32
std::uint64_t index
Number of the tick: 0 for the first Scheduler::update(), then one more per completed update.
Definition system.hpp:28
core::Duration step
Duration of the step, the fixed step of core::MainLoop.
Definition system.hpp:25