Ordered list of named systems, all updated once per tick.
More...
#include <aegis2d/ecs/system.hpp>
|
| | Scheduler ()=default |
| |
| | Scheduler (const Scheduler &)=delete |
| |
| Scheduler & | operator= (const Scheduler &)=delete |
| |
| | Scheduler (Scheduler &&) noexcept=default |
| |
| Scheduler & | operator= (Scheduler &&) noexcept=default |
| |
| | ~Scheduler ()=default |
| |
template<std::derived_from< ISystem > System, typename... Args>
requires std::constructible_from<System, Args...> |
| System & | add (std::string name, Args &&... args) |
| | Builds a system in place and adds it after the others.
|
| |
| ISystem & | add (std::string name, std::unique_ptr< ISystem > system) |
| | Adds a system after the others.
|
| |
| FunctionSystem & | add (std::string name, FunctionSystem::Function function) |
| | Adds a function as a system after the others.
|
| |
| bool | remove (std::string_view name) |
| | Removes a system; the others keep their order.
|
| |
| bool | contains (std::string_view name) const noexcept |
| | Tells whether a system has this name.
|
| |
| 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().
|
| |
| std::vector< std::string_view > | names () const |
| | Names of the systems, in update order.
|
| |
| std::size_t | size () const noexcept |
| | Number of systems, enabled or not.
|
| |
| bool | empty () const noexcept |
| | Tells whether no system was added.
|
| |
| void | update (Registry ®istry, core::Duration step) |
| | Runs one tick: every enabled system, in order.
|
| |
| void | set_profiler (core::Profiler *profiler) noexcept |
| | Times each system with a profiler, in a scope named after it.
|
| |
| std::uint64_t | ticks () const noexcept |
| | Number of completed updates.
|
| |
| bool | updating () const noexcept |
| | Tells whether update() is running the systems.
|
| |
Ordered list of named systems, all updated once per tick.
Systems run in the order they were added, so the order is written once, where the game registers them; e.g. on the server: inputs, movement, collisions, damage, cleanup. Each binary has its own scheduler and registers its own systems on the same engine types. update() is meant to be called by the fixed-step callback of core::MainLoop:
systems.
add<InputSystem>(
"input", inputs);
});
});
Entry point of the ECS: creates entities and stores their components.
Definition registry.hpp:34
View< Components... > view()
View on the entities that own all the listed components.
Definition registry.hpp:222
Ordered list of named systems, all updated once per tick.
Definition system.hpp:100
void update(Registry ®istry, core::Duration step)
Runs one tick: every enabled system, in order.
System & add(std::string name, Args &&... args)
Builds a system in place and adds it after the others.
Definition system.hpp:118
std::chrono::nanoseconds Duration
Duration type used for simulation time (nanoseconds).
Definition clock.hpp:14
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
How fast an entity moves.
Definition components.hpp:25
Vec2 value
Speed in logical pixels per second.
Definition components.hpp:27
A system can be disabled (a paused menu, a debug overlay) without losing its place. Systems cannot be added or removed while update() runs. Not thread-safe: use the scheduler from the game thread only.
◆ Scheduler() [1/3]
| aegis2d::ecs::Scheduler::Scheduler |
( |
| ) |
|
|
default |
◆ Scheduler() [2/3]
| aegis2d::ecs::Scheduler::Scheduler |
( |
const Scheduler & |
| ) |
|
|
delete |
◆ Scheduler() [3/3]
| aegis2d::ecs::Scheduler::Scheduler |
( |
Scheduler && |
| ) |
|
|
defaultnoexcept |
◆ ~Scheduler()
| aegis2d::ecs::Scheduler::~Scheduler |
( |
| ) |
|
|
default |
◆ add() [1/3]
template<std::derived_from<
ISystem > System, typename... Args>
requires std::constructible_from<System, Args...>
| System & aegis2d::ecs::Scheduler::add |
( |
std::string |
name, |
|
|
Args &&... |
args |
|
) |
| |
|
inline |
Builds a system in place and adds it after the others.
- Template Parameters
-
- Parameters
-
| name | Unique, non-empty name, used to remove or disable the system. |
| args | Arguments of the system's constructor. |
- Returns
- The new system, owned by the scheduler.
- Exceptions
-
| std::invalid_argument | If name is empty or already used. |
| std::logic_error | If called while update() runs. |
◆ add() [2/3]
Adds a function as a system after the others.
- Parameters
-
| name | Unique, non-empty name, used to remove or disable the system. |
| function | Called with the registry and the tick by every update(). |
- Returns
- The system wrapping the function.
- Exceptions
-
| std::invalid_argument | If name is empty or already used, or function is empty. |
| std::logic_error | If called while update() runs. |
◆ add() [3/3]
| ISystem & aegis2d::ecs::Scheduler::add |
( |
std::string |
name, |
|
|
std::unique_ptr< ISystem > |
system |
|
) |
| |
Adds a system after the others.
- Parameters
-
| name | Unique, non-empty name, used to remove or disable the system. |
| system | System to own. |
- Returns
- The system.
- Exceptions
-
| std::invalid_argument | If name is empty or already used, or system is null. |
| std::logic_error | If called while update() runs. |
◆ contains()
| bool aegis2d::ecs::Scheduler::contains |
( |
std::string_view |
name | ) |
const |
|
noexcept |
Tells whether a system has this name.
- Parameters
-
- Returns
true if a system was added with it and not removed.
◆ empty()
| bool aegis2d::ecs::Scheduler::empty |
( |
| ) |
const |
|
noexcept |
Tells whether no system was added.
- Returns
true when size() is 0.
◆ enabled()
| bool aegis2d::ecs::Scheduler::enabled |
( |
std::string_view |
name | ) |
const |
Tells whether a system runs on update().
- Parameters
-
- Returns
true unless it was disabled with set_enabled().
- Exceptions
-
| std::out_of_range | If no system has this name. |
◆ names()
| std::vector< std::string_view > aegis2d::ecs::Scheduler::names |
( |
| ) |
const |
Names of the systems, in update order.
- Returns
- Views of the names, valid until the system is removed.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ remove()
| bool aegis2d::ecs::Scheduler::remove |
( |
std::string_view |
name | ) |
|
Removes a system; the others keep their order.
- Parameters
-
- Returns
true if it was found; false (nothing changes) otherwise.
- Exceptions
-
| std::logic_error | If called while update() runs. |
◆ set_enabled()
| void aegis2d::ecs::Scheduler::set_enabled |
( |
std::string_view |
name, |
|
|
bool |
enabled |
|
) |
| |
Enables or disables a system; a disabled system keeps its place but is skipped by update().
Can be called by a system during update(): the change applies to the systems that have not run yet in this tick.
- Parameters
-
| name | Name of the system. |
| enabled | false to skip it, true to run it again. |
- Exceptions
-
| std::out_of_range | If no system has this name. |
◆ set_profiler()
| void aegis2d::ecs::Scheduler::set_profiler |
( |
core::Profiler * |
profiler | ) |
|
|
noexcept |
Times each system with a profiler, in a scope named after it.
- Parameters
-
| profiler | Profiler of the frame, kept by pointer; nullptr, the default, times nothing. |
◆ size()
| std::size_t aegis2d::ecs::Scheduler::size |
( |
| ) |
const |
|
noexcept |
Number of systems, enabled or not.
- Returns
- The count.
◆ ticks()
| std::uint64_t aegis2d::ecs::Scheduler::ticks |
( |
| ) |
const |
|
noexcept |
Number of completed updates.
- Returns
- The index the next tick will have.
◆ update()
Runs one tick: every enabled system, in order.
The systems get a Tick with step and the index ticks(). If a system throws, the exception propagates, the next systems do not run and the tick is not counted; the scheduler can be updated again.
- Parameters
-
| registry | World given to the systems. |
| step | Duration of the tick, usually the fixed step of core::MainLoop. |
- Exceptions
-
| std::logic_error | If called by a system, during update(). |
◆ updating()
| bool aegis2d::ecs::Scheduler::updating |
( |
| ) |
const |
|
noexcept |
Tells whether update() is running the systems.
- Returns
true from the first system of a tick to the end of the last one.
The documentation for this class was generated from the following file: