Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
rtp::server::LevelSystem Class Reference

#include <LevelSystem.hpp>

Collaboration diagram for rtp::server::LevelSystem:

Classes

struct  ActiveLevel
 Struct to hold active level data for a room. More...
 

Public Member Functions

 LevelSystem (ecs::Registry &registry, EntitySystem &entitySystem, RoomSystem &roomSystem, NetworkSyncSystem &networkSync)
 Constructor for LevelSystem.
 
void registerLevelPath (uint32_t levelId, const std::string &path)
 Register a level file path with a level ID.
 
void startLevelForRoom (uint32_t roomId, uint32_t levelId)
 Start a level for a specific room.
 
void stopLevelForRoom (uint32_t roomId)
 Stop the level for a specific room.
 
void update (float dt)
 Update system logic for one frame.
 
const LevelDatagetLevelData (uint32_t roomId) const
 Get the level data for a specific room.
 

Private Member Functions

void spawnEntityForRoom (uint32_t roomId, const ecs::Entity &entity)
 Spawn an entity for a specific room.
 
std::optional< LevelDataloadLevel (uint32_t levelId) const
 Load level data from a file.
 

Private Attributes

ecs::Registry_registry
 Reference to the entity registry.
 
EntitySystem_entitySystem
 Reference to the EntitySystem.
 
RoomSystem_roomSystem
 Reference to the RoomSystem.
 
NetworkSyncSystem_networkSync
 Reference to the NetworkSyncSystem.
 
std::unordered_map< uint32_t, ActiveLevel_activeLevels
 Active levels mapped by room ID.
 
std::unordered_map< uint32_t, std::string > _levelPaths
 Level file paths mapped by level ID.
 

Detailed Description

Definition at line 21 of file LevelSystem.hpp.

Constructor & Destructor Documentation

◆ LevelSystem()

rtp::server::LevelSystem::LevelSystem ( ecs::Registry registry,
EntitySystem entitySystem,
RoomSystem roomSystem,
NetworkSyncSystem networkSync 
)

Constructor for LevelSystem.

Parameters
registryReference to the ECS registry
entitySystemReference to the EntitySystem
roomSystemReference to the RoomSystem
networkSyncReference to the NetworkSyncSystem

Definition at line 23 of file LevelSystem.cpp.

Member Function Documentation

◆ getLevelData()

const LevelData * rtp::server::LevelSystem::getLevelData ( uint32_t  roomId) const

Get the level data for a specific room.

Parameters
roomIdID of the room
Returns
Pointer to the LevelData if the level is active, nullptr otherwise

Definition at line 238 of file LevelSystem.cpp.

References _activeLevels.

◆ loadLevel()

std::optional< LevelData > rtp::server::LevelSystem::loadLevel ( uint32_t  levelId) const
private

Load level data from a file.

Parameters
levelIdID of the level to load
Returns
Optional LevelData if loading was successful, std::nullopt otherwise

Definition at line 39 of file LevelSystem.cpp.

References _levelPaths, rtp::log::error(), rtp::server::loadLevelFromFile(), and rtp::log::warning().

Referenced by startLevelForRoom().

◆ registerLevelPath()

void rtp::server::LevelSystem::registerLevelPath ( uint32_t  levelId,
const std::string &  path 
)

Register a level file path with a level ID.

Parameters
levelIdID of the level
pathFile path to the level data

Definition at line 34 of file LevelSystem.cpp.

References _levelPaths.

◆ spawnEntityForRoom()

void rtp::server::LevelSystem::spawnEntityForRoom ( uint32_t  roomId,
const ecs::Entity entity 
)
private

Spawn an entity for a specific room.

Parameters
roomIdID of the room
entityEntity to spawn

Definition at line 178 of file LevelSystem.cpp.

References _networkSync, _registry, _roomSystem, rtp::net::EntitySpawn, rtp::log::error(), rtp::ecs::Registry::get(), rtp::server::RoomSystem::getRoom(), rtp::ecs::Entity::index(), rtp::server::NetworkSyncSystem::sendPacketToSessions(), and rtp::net::TCP.

Referenced by update().

◆ startLevelForRoom()

void rtp::server::LevelSystem::startLevelForRoom ( uint32_t  roomId,
uint32_t  levelId 
)

Start a level for a specific room.

Parameters
roomIdID of the room
levelIdID of the level to start

Definition at line 57 of file LevelSystem.cpp.

References _activeLevels, rtp::server::LevelSystem::ActiveLevel::data, rtp::log::info(), and loadLevel().

◆ stopLevelForRoom()

void rtp::server::LevelSystem::stopLevelForRoom ( uint32_t  roomId)

Stop the level for a specific room.

Parameters
roomIdID of the room

Definition at line 70 of file LevelSystem.cpp.

References _activeLevels.

◆ update()

Member Data Documentation

◆ _activeLevels

std::unordered_map<uint32_t, ActiveLevel> rtp::server::LevelSystem::_activeLevels
private

Active levels mapped by room ID.

Definition at line 100 of file LevelSystem.hpp.

Referenced by getLevelData(), startLevelForRoom(), stopLevelForRoom(), and update().

◆ _entitySystem

EntitySystem& rtp::server::LevelSystem::_entitySystem
private

Reference to the EntitySystem.

Definition at line 96 of file LevelSystem.hpp.

Referenced by update().

◆ _levelPaths

std::unordered_map<uint32_t, std::string> rtp::server::LevelSystem::_levelPaths
private

Level file paths mapped by level ID.

Definition at line 102 of file LevelSystem.hpp.

Referenced by loadLevel(), and registerLevelPath().

◆ _networkSync

NetworkSyncSystem& rtp::server::LevelSystem::_networkSync
private

Reference to the NetworkSyncSystem.

Definition at line 98 of file LevelSystem.hpp.

Referenced by spawnEntityForRoom().

◆ _registry

ecs::Registry& rtp::server::LevelSystem::_registry
private

Reference to the entity registry.

Definition at line 95 of file LevelSystem.hpp.

Referenced by spawnEntityForRoom(), and update().

◆ _roomSystem

RoomSystem& rtp::server::LevelSystem::_roomSystem
private

Reference to the RoomSystem.

Definition at line 97 of file LevelSystem.hpp.

Referenced by spawnEntityForRoom(), and update().


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