R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ecs::wrapper::ECSWorld Class Reference

High-level ECS manager providing clean server-side API. More...

#include <ECSWorld.hpp>

Collaboration diagram for ecs::wrapper::ECSWorld:
Collaboration graph

Public Member Functions

 ECSWorld ()
 Construct a new ECSWorld.
 
 ~ECSWorld ()
 Destroy the ECSWorld and cleanup resources.
 
Entity createEntity ()
 Create a new entity.
 
std::vector< EntitycreateEntities (size_t count)
 Create multiple entities at once.
 
Entity getEntity (Address address)
 Get an entity wrapper from an address.
 
void destroyEntity (const Entity &entity)
 Destroy an entity and remove it from the world.
 
void destroyEntity (Address address)
 Destroy an entity by its address.
 
template<typename... Components>
std::vector< Entityquery ()
 Get all entities with specific components.
 
template<typename... Components>
void forEach (std::function< void(Entity, Components &...)> callback)
 Iterate over entities with specific components.
 
template<typename T >
void registerSystem (const std::string &name, std::unique_ptr< T > system)
 Register a system with the world.
 
template<typename T , typename... Args>
void createSystem (const std::string &name, Args &&...args)
 Create and register a system.
 
template<typename T , typename... Args>
void createSystem (SystemId id, Args &&...args)
 Create and register a system using an enum identifier.
 
template<typename T >
T * getSystem (const std::string &name)
 Get a registered system by name.
 
template<typename T >
T * getSystem (SystemId id)
 Get a registered system by enum identifier.
 
void removeSystem (const std::string &name)
 Remove a system from the world.
 
void removeSystem (SystemId id)
 Remove a system using its enum identifier.
 
void update (float deltaTime)
 Update all registered systems.
 
bool updateSystem (const std::string &name, float deltaTime)
 Update a specific system by name.
 
bool updateSystem (SystemId id, float deltaTime)
 Update a specific system by enum identifier.
 
RegistrygetRegistry ()
 Get direct access to the underlying registry.
 
const RegistrygetRegistry () const
 Get const access to the underlying registry.
 
void clear ()
 Clear all entities from the world.
 
size_t getSystemCount () const
 Get the number of systems registered.
 

Public Attributes

bool startingEvent = false
 World state (for accessing from Lua scripts)d 0 = not running, 1 = starting event, 2 = running.
 

Private Attributes

std::unique_ptr< Registry_registry
 
std::unordered_map< std::string, std::unique_ptr< ISystem > > _systems
 
std::vector< std::string > _systemsOrder
 

Detailed Description

High-level ECS manager providing clean server-side API.

Manages the ECS registry, entities, and systems with a clean interface. Designed for server-side game logic with emphasis on code clarity.

Examples
/home/ubuntu/actions-runner/_work/rtype/rtype/server/Scripting/LuaBindings/ComponentBindingHelper.hpp.

Definition at line 122 of file ECSWorld.hpp.

Constructor & Destructor Documentation

◆ ECSWorld()

ecs::wrapper::ECSWorld::ECSWorld ( )

Construct a new ECSWorld.

Definition at line 63 of file ECSWorld.cpp.

◆ ~ECSWorld()

ecs::wrapper::ECSWorld::~ECSWorld ( )
default

Destroy the ECSWorld and cleanup resources.

Member Function Documentation

◆ clear()

void ecs::wrapper::ECSWorld::clear ( )

Clear all entities from the world.

Systems are preserved.

Definition at line 154 of file ECSWorld.cpp.

References _registry, and ecs::Registry::view().

Here is the call graph for this function:

◆ createEntities()

std::vector< Entity > ecs::wrapper::ECSWorld::createEntities ( size_t  count)

Create multiple entities at once.

Parameters
countNumber of entities to create
Returns
std::vector<Entity> Vector of created entities

Definition at line 72 of file ECSWorld.cpp.

References createEntity().

Here is the call graph for this function:

◆ createEntity()

Entity ecs::wrapper::ECSWorld::createEntity ( )

Create a new entity.

Returns
Entity Wrapper around the new entity

Definition at line 67 of file ECSWorld.cpp.

References _registry.

Referenced by scripting::bindings::bindServerGame(), scripting::bindings::bindWorld(), and createEntities().

◆ createSystem() [1/2]

template<typename T , typename... Args>
void ecs::wrapper::ECSWorld::createSystem ( const std::string &  name,
Args &&...  args 
)

Create and register a system.

Template Parameters
TSystem type (must inherit from ISystem)
ArgsConstructor argument types
Parameters
nameUnique name for the system
argsConstructor arguments

◆ createSystem() [2/2]

template<typename T , typename... Args>
void ecs::wrapper::ECSWorld::createSystem ( SystemId  id,
Args &&...  args 
)

Create and register a system using an enum identifier.

Template Parameters
TSystem type (must inherit from ISystem)
ArgsConstructor argument types
Parameters
idEnum identifier for the system
argsConstructor arguments

◆ destroyEntity() [1/2]

void ecs::wrapper::ECSWorld::destroyEntity ( Address  address)

Destroy an entity by its address.

Parameters
addressThe entity's address

Definition at line 93 of file ECSWorld.cpp.

References _registry.

◆ destroyEntity() [2/2]

void ecs::wrapper::ECSWorld::destroyEntity ( const Entity entity)

Destroy an entity and remove it from the world.

Parameters
entityThe entity to destroy

Definition at line 87 of file ECSWorld.cpp.

References _registry, ecs::wrapper::Entity::getAddress(), and ecs::wrapper::Entity::isValid().

Referenced by scripting::bindings::bindEntity(), and scripting::bindings::bindWorld().

Here is the call graph for this function:

◆ forEach()

template<typename... Components>
void ecs::wrapper::ECSWorld::forEach ( std::function< void(Entity, Components &...)>  callback)

Iterate over entities with specific components.

Template Parameters
ComponentsComponent types required
Parameters
callbackFunction to call for each matching entity
world.forEach<Transform, Velocity>([](Entity entity, Transform& t, Velocity& v) {
t.position.x += v.x;
});
Component representing position, rotation and scale in 2D space.
Definition Transform.hpp:20
Component representing movement direction and speed.
Definition Velocity.hpp:20
High-level entity wrapper providing fluent interface.
Definition ECSWorld.hpp:33

◆ getEntity()

Entity ecs::wrapper::ECSWorld::getEntity ( Address  address)

Get an entity wrapper from an address.

Parameters
addressThe entity's address
Returns
Entity Wrapper around the entity

Definition at line 83 of file ECSWorld.cpp.

References _registry.

Referenced by scripting::bindings::bindWorld(), server::GameStateSerializer::serializeEntity(), and scripting::LuaSystemAdapter::update().

◆ getRegistry() [1/2]

Registry & ecs::wrapper::ECSWorld::getRegistry ( )

Get direct access to the underlying registry.

Warning
Use with caution. Prefer using the wrapper API.
Returns
Registry& Reference to the registry

Definition at line 146 of file ECSWorld.cpp.

References _registry.

◆ getRegistry() [2/2]

const Registry & ecs::wrapper::ECSWorld::getRegistry ( ) const

Get const access to the underlying registry.

Returns
const Registry& Const reference to the registry

Definition at line 150 of file ECSWorld.cpp.

References _registry.

◆ getSystem() [1/2]

template<typename T >
T * ecs::wrapper::ECSWorld::getSystem ( const std::string &  name)

Get a registered system by name.

Template Parameters
TSystem type
Parameters
nameThe system's name
Returns
T* Pointer to the system, or nullptr if not found

◆ getSystem() [2/2]

template<typename T >
T * ecs::wrapper::ECSWorld::getSystem ( SystemId  id)

Get a registered system by enum identifier.

Template Parameters
TSystem type
Parameters
idEnum identifier for the system
Returns
T* Pointer to the system, or nullptr if not found

◆ getSystemCount()

size_t ecs::wrapper::ECSWorld::getSystemCount ( ) const

Get the number of systems registered.

Returns
size_t Number of systems

Definition at line 162 of file ECSWorld.cpp.

References _systems.

◆ query()

template<typename... Components>
std::vector< Entity > ecs::wrapper::ECSWorld::query ( )

Get all entities with specific components.

Template Parameters
ComponentsComponent types to query
Returns
std::vector<Entity> Entities matching the query

Referenced by server::GameStateSerializer::createFullSnapshot().

◆ registerSystem()

template<typename T >
void ecs::wrapper::ECSWorld::registerSystem ( const std::string &  name,
std::unique_ptr< T >  system 
)

Register a system with the world.

Template Parameters
TSystem type (must inherit from ISystem)
Parameters
nameUnique name for the system
systemUnique pointer to the system

◆ removeSystem() [1/2]

void ecs::wrapper::ECSWorld::removeSystem ( const std::string &  name)

Remove a system from the world.

Parameters
nameThe system's name

Definition at line 97 of file ECSWorld.cpp.

References _systems, and _systemsOrder.

Referenced by removeSystem().

◆ removeSystem() [2/2]

void ecs::wrapper::ECSWorld::removeSystem ( SystemId  id)

Remove a system using its enum identifier.

Parameters
idEnum identifier for the system

Definition at line 110 of file ECSWorld.cpp.

References removeSystem(), and ecs::wrapper::systemIdToName().

Here is the call graph for this function:

◆ update()

void ecs::wrapper::ECSWorld::update ( float  deltaTime)

Update all registered systems.

Systems are updated in registration order.

Parameters
deltaTimeTime elapsed since last update (in seconds)

Definition at line 114 of file ECSWorld.cpp.

References _registry, _systems, _systemsOrder, and LOG_ERROR.

◆ updateSystem() [1/2]

bool ecs::wrapper::ECSWorld::updateSystem ( const std::string &  name,
float  deltaTime 
)

Update a specific system by name.

Parameters
nameThe system's name
deltaTimeTime elapsed since last update (in seconds)
Returns
bool true if system was found and updated, false otherwise

Definition at line 127 of file ECSWorld.cpp.

References _registry, _systems, and LOG_ERROR.

Referenced by ecs::wrapper::SystemScheduler::update(), and updateSystem().

◆ updateSystem() [2/2]

bool ecs::wrapper::ECSWorld::updateSystem ( SystemId  id,
float  deltaTime 
)

Update a specific system by enum identifier.

Parameters
idEnum identifier for the system
deltaTimeTime elapsed since last update (in seconds)
Returns
bool true if system was found and updated, false otherwise

Definition at line 142 of file ECSWorld.cpp.

References ecs::wrapper::systemIdToName(), and updateSystem().

Here is the call graph for this function:

Member Data Documentation

◆ _registry

std::unique_ptr<Registry> ecs::wrapper::ECSWorld::_registry
private

◆ _systems

std::unordered_map<std::string, std::unique_ptr<ISystem> > ecs::wrapper::ECSWorld::_systems
private

Definition at line 125 of file ECSWorld.hpp.

Referenced by getSystemCount(), removeSystem(), update(), and updateSystem().

◆ _systemsOrder

std::vector<std::string> ecs::wrapper::ECSWorld::_systemsOrder
private

Definition at line 126 of file ECSWorld.hpp.

Referenced by removeSystem(), and update().

◆ startingEvent

bool ecs::wrapper::ECSWorld::startingEvent = false

World state (for accessing from Lua scripts)d 0 = not running, 1 = starting event, 2 = running.

Definition at line 320 of file ECSWorld.hpp.


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