Skip to main content

SystemRegistry Class

Container for System instances within a game loop pass. More...

Declaration

class helios::engine::runtime::world::SystemRegistry { ... }

Public Member Functions Index

std::vector< std::unique_ptr< helios::engine::ecs::System > > &systems () noexcept

Returns a reference to the system collection. More...

template <typename T, typename... Args>
T &add (Args &&... args)

Adds a new System of type T to the registry. More...

template <typename T>
boolhasSystem () const

Checks if a System of type T is registered. More...

template <typename T>
T *getSystem () const

Retrieves a System by type. More...

Private Member Attributes Index

std::vector< std::unique_ptr< helios::engine::ecs::System > >systems_

Collection of owned System instances. More...

Description

Container for System instances within a game loop pass.

SystemRegistry manages a collection of Systems that execute together within a single pass of the game loop. It provides type-safe registration, lookup, and iteration over Systems.

## Ownership

The registry owns all registered Systems via `std::unique_ptr`. Systems are destroyed when the registry is destroyed.

## Type-Safe Access

Systems can be retrieved by type using `getSystem<T>()`, enabling inter-system communication when necessary.

Example: ```cpp SystemRegistry registry;

// Add systems registry.add<Move2DSystem>(gameWorld); registry.add<CollisionSystem>(gameWorld);

// Check for system if (registry.hasSystem<CollisionSystem>()) { auto* collision = registry.getSystem<CollisionSystem>(); }

// Iterate all systems for (auto& system : registry.systems()) { system->update(ctx); } ```

See Also

System

See Also

GameLoop

See Also

GameLoopPhase

Definition at line 59 of file SystemRegistry.ixx.

Public Member Functions

add()

template <typename T, typename... Args>
T & helios::engine::runtime::world::SystemRegistry::add (Args &&... args)
inline

Adds a new System of type T to the registry.

Template Parameters
T

The System type to add. Must derive from System.

Args

Constructor argument types.

Parameters
args

Arguments forwarded to the System constructor.

Returns

Reference to the newly added System.

Precondition

No System of type T is already registered.

Definition at line 91 of file SystemRegistry.ixx.

91 T& add(Args&&... args) {
92 assert(!hasSystem<T>() && "System already registered with GameLoopPhase");
93 auto system_ptr = std::make_unique<T>(std::forward<Args>(args)...);
94 T* raw_ptr = system_ptr.get();
95 systems_.push_back(std::move(system_ptr));
96 return *raw_ptr;
97 }

Reference hasSystem.

getSystem()

template <typename T>
T * helios::engine::runtime::world::SystemRegistry::getSystem ()
inline nodiscard

Retrieves a System by type.

Template Parameters
T

The System type to retrieve.

Returns

Pointer to the System if found, nullptr otherwise.

info

Uses dynamic_cast for type checking. O(n) complexity.

Definition at line 123 of file SystemRegistry.ixx.

123 [[nodiscard]] T* getSystem() const {
124 for (const auto& system : systems_) {
125 if (auto* sys = dynamic_cast<T*>(system.get())) {
126 return sys;
127 }
128 }
129
130 return nullptr;
131 }

Referenced by hasSystem.

hasSystem()

template <typename T>
bool helios::engine::runtime::world::SystemRegistry::hasSystem ()
inline nodiscard

Checks if a System of type T is registered.

Template Parameters
T

The System type to check for.

Returns

True if the System exists, false otherwise.

Definition at line 108 of file SystemRegistry.ixx.

108 [[nodiscard]] bool hasSystem() const {
109 return getSystem<T>() != nullptr;
110 }

Reference getSystem.

Referenced by add.

systems()

std::vector< std::unique_ptr< helios::engine::ecs::System > > & helios::engine::runtime::world::SystemRegistry::systems ()
inline nodiscard noexcept

Returns a reference to the system collection.

Returns

Reference to the vector of System unique_ptrs.

Definition at line 73 of file SystemRegistry.ixx.

73 [[nodiscard]] std::vector<std::unique_ptr<helios::engine::ecs::System>>& systems() noexcept {
74 return systems_;
75 }

Private Member Attributes

systems_

std::vector<std::unique_ptr<helios::engine::ecs::System> > helios::engine::runtime::world::SystemRegistry::systems_

Collection of owned System instances.

Definition at line 64 of file SystemRegistry.ixx.

64 std::vector<std::unique_ptr<helios::engine::ecs::System>> systems_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.