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

System to handle network-related operations on the client side. More...

#include <NetworkSyncSystem.hpp>

Inheritance diagram for rtp::client::NetworkSyncSystem:
Collaboration diagram for rtp::client::NetworkSyncSystem:

Classes

struct  GameOverSummary
 

Public Types

enum class  State {
  NotLogged , InLobby , JoiningRoom , CreatingRoom ,
  LeavingRoom , InRoom , InGame
}
 

Public Member Functions

 NetworkSyncSystem (ClientNetwork &network, ecs::Registry &registry, EntityBuilder builder)
 Constructor for NetworkSyncSystem.
 
void update (float dt) override
 Update system logic for one frame.
 
void tryLogin (const std::string &username, const std::string &password, uint8_t weaponKind) const
 Send a request to server attempting to log in with provided credentials.
 
void tryRegister (const std::string &username, const std::string &password) const
 Send a request to server attempting to register with provided credentials.
 
void requestListRooms (void)
 Send a request to have the list of available rooms from the server.
 
void tryCreateRoom (const std::string &roomName, uint32_t maxPlayers, float difficulty, float speed, uint32_t duration, uint32_t seed, uint32_t levelId, uint8_t roomType)
 Send a request to create a new room on the server.
 
void tryJoinRoom (uint32_t roomId, bool asSpectator=false)
 Send a request to join an existing room on the server.
 
void tryLeaveRoom (void)
 Send a request to leave the current room on the server.
 
void trySetReady (bool isReady)
 Send a request to set the client's ready status in the current room.
 
void tryStartSolo (void)
 Start a solo game by creating a private room and auto-joining/readying.
 
void trySendMessage (const std::string &message) const
 Send a chat message to the server.
 
void sendSelectedWeapon (uint8_t weaponKind) const
 Send currently selected weapon to server to apply immediately.
 
bool isInRoom (void) const
 Check if the client is in a room.
 
bool isReady (void) const
 Check if the client is ready.
 
bool isUdpReady (void) const
 Check if UDP is ready.
 
bool isLoggedIn (void) const
 Check if the client is logged in.
 
std::string getUsername (void) const
 Get the username of the client.
 
void setGameOverSummary (const GameOverSummary &summary)
 
GameOverSummary getGameOverSummary (void) const
 
bool consumeGameOver (void)
 
int getScore (void) const
 
int getHealthCurrent (void) const
 
int getHealthMax (void) const
 
std::list< net::RoomInfogetAvailableRooms (void) const
 Get a list of available rooms from the server.
 
bool isInGame (void) const
 Check if the client is in game.
 
State getState (void) const
 Get the current state of the client.
 
uint32_t getCurrentLevelId (void) const
 Get the current level ID for client-side visuals (parallax)
 
std::string getLastChatMessage (void) const
 Get the last received room chat message.
 
const std::deque< std::string > & getChatHistory (void) const
 Get chat history buffer (most recent last)
 
uint16_t getAmmoCurrent (void) const
 
uint16_t getAmmoMax (void) const
 
bool isReloading (void) const
 
float getReloadCooldownRemaining (void) const
 
uint32_t getPingMs (void) const
 
bool consumeKicked (void)
 
- Public Member Functions inherited from rtp::ecs::ISystem
virtual ~ISystem () noexcept=default
 

Public Attributes

bool _isStartingSolo = false
 Check if the client is starting a solo game.
 

Private Member Functions

void handleEvent (net::NetworkEvent &event)
 Handle a network event.
 
void onLoginResponse (net::Packet &packet)
 
void onRegisterResponse (net::Packet &packet)
 
void onRoomResponse (net::Packet &packet)
 
void onJoinRoomResponse (net::Packet &packet)
 
void onCreateRoomResponse (net::Packet &packet)
 
void onLeaveRoomResponse (net::Packet &packet)
 
void onSpawnEntityFromServer (net::Packet &packet)
 
void onEntityDeath (net::Packet &packet)
 
void onRoomUpdate (net::Packet &packet)
 
void onRoomChatReceived (net::Packet &packet)
 
void pushChatMessage (const std::string &message)
 
void onAmmoUpdate (net::Packet &packet)
 
void onBeamState (net::Packet &packet)
 
void onPong (net::Packet &packet)
 
void onDebugModeUpdate (net::Packet &packet)
 

Private Attributes

ClientNetwork_network
 Reference to the client network manager.
 
ecs::Registry_registry
 Reference to the entity registry.
 
std::unordered_map< uint32_t, ecs::Entity_netIdToEntity
 Map of network IDs to entities.
 
EntityBuilder _builder
 Entity builder for spawning entities.
 
bool _isInRoom = false
 Flag indicating if the client is in a room.
 
bool _isReady = false
 Flag indicating if the client is ready.
 
bool _udpReady = false
 Flag indicating if UDP is ready.
 
bool _isLoggedIn = false
 Flag indicating if the client is logged in.
 
std::string _username
 The username of the client.
 
std::list< net::RoomInfo_availableRooms
 List of available rooms from the server.
 
State _currentState = State::NotLogged
 Current state of the client.
 
std::string _lastChatMessage
 Last received chat message.
 
std::deque< std::string > _chatHistory
 Recent chat messages.
 
std::size_t _chatHistoryLimit = 8
 Max chat messages to keep.
 
uint16_t _ammoCurrent = 0
 Current ammo.
 
uint16_t _ammoMax = 100
 Max ammo.
 
bool _ammoReloading = false
 Reload state.
 
float _ammoReloadRemaining = 0.0f
 Reload time remaining.
 
uint32_t _pingMs = 0
 Latest ping in ms.
 
float _pingTimer = 0.0f
 Ping timer accumulator.
 
float _pingInterval = 1.0f
 Ping interval in seconds.
 
bool _kicked = false
 Kicked flag.
 
uint32_t _currentLevelId = 1
 Current level id used by client visuals.
 
GameOverSummary _gameOverSummary {}
 Cached game over summary.
 
bool _gameOverPending {false}
 Game over pending flag.
 
int _score {0}
 Latest server score.
 
int _healthCurrent {0}
 Latest health.
 
int _healthMax {0}
 Latest max health.
 
std::unordered_map< uint32_t, std::vector< std::pair< ecs::Entity, float > > > _beamEntities
 
std::unordered_map< uint32_t, std::vector< float > > _beamLengths
 

Detailed Description

System to handle network-related operations on the client side.

Definition at line 39 of file NetworkSyncSystem.hpp.

Member Enumeration Documentation

◆ State

Enumerator
NotLogged 
InLobby 
JoiningRoom 
CreatingRoom 
LeavingRoom 
InRoom 
InGame 

Definition at line 42 of file NetworkSyncSystem.hpp.

Constructor & Destructor Documentation

◆ NetworkSyncSystem()

rtp::client::NetworkSyncSystem::NetworkSyncSystem ( ClientNetwork network,
ecs::Registry registry,
EntityBuilder  builder 
)

Constructor for NetworkSyncSystem.

Parameters
networkReference to the client network manager
registryReference to the entity registry

Definition at line 33 of file NetworkSyncSystem.cpp.

Member Function Documentation

◆ consumeGameOver()

bool rtp::client::NetworkSyncSystem::consumeGameOver ( void  )

Definition at line 271 of file NetworkSyncSystem.cpp.

References _gameOverPending.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ consumeKicked()

bool rtp::client::NetworkSyncSystem::consumeKicked ( void  )

◆ getAmmoCurrent()

uint16_t rtp::client::NetworkSyncSystem::getAmmoCurrent ( void  ) const

Definition at line 214 of file NetworkSyncSystem.cpp.

References _ammoCurrent.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ getAmmoMax()

uint16_t rtp::client::NetworkSyncSystem::getAmmoMax ( void  ) const

Definition at line 219 of file NetworkSyncSystem.cpp.

References _ammoMax.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ getAvailableRooms()

std::list< net::RoomInfo > rtp::client::NetworkSyncSystem::getAvailableRooms ( void  ) const

Get a list of available rooms from the server.

Returns
List of RoomInfo structures

Definition at line 199 of file NetworkSyncSystem.cpp.

References _availableRooms.

Referenced by rtp::client::scenes::LobbyScene::buildUi(), rtp::client::scenes::LobbyScene::onEnter(), and rtp::client::scenes::LobbyScene::update().

◆ getChatHistory()

const std::deque< std::string > & rtp::client::NetworkSyncSystem::getChatHistory ( void  ) const

Get chat history buffer (most recent last)

Returns
Chat message buffer

Definition at line 256 of file NetworkSyncSystem.cpp.

References _chatHistory.

Referenced by rtp::client::scenes::PlayingScene::updateChatHistoryText(), and rtp::client::scenes::RoomWaitingScene::updateChatHistoryText().

◆ getCurrentLevelId()

uint32_t rtp::client::NetworkSyncSystem::getCurrentLevelId ( void  ) const

Get the current level ID for client-side visuals (parallax)

Definition at line 246 of file NetworkSyncSystem.cpp.

References _currentLevelId.

Referenced by rtp::client::scenes::PlayingScene::spawnParallax().

◆ getGameOverSummary()

NetworkSyncSystem::GameOverSummary rtp::client::NetworkSyncSystem::getGameOverSummary ( void  ) const

Definition at line 266 of file NetworkSyncSystem.cpp.

References _gameOverSummary.

Referenced by rtp::client::scenes::GameOverScene::onEnter().

◆ getHealthCurrent()

int rtp::client::NetworkSyncSystem::getHealthCurrent ( void  ) const

Definition at line 285 of file NetworkSyncSystem.cpp.

References _healthCurrent.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ getHealthMax()

int rtp::client::NetworkSyncSystem::getHealthMax ( void  ) const

Definition at line 290 of file NetworkSyncSystem.cpp.

References _healthMax.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ getLastChatMessage()

std::string rtp::client::NetworkSyncSystem::getLastChatMessage ( void  ) const

Get the last received room chat message.

Returns
Last chat message string

Definition at line 251 of file NetworkSyncSystem.cpp.

References _lastChatMessage.

Referenced by rtp::client::scenes::PlayingScene::update(), and rtp::client::scenes::RoomWaitingScene::update().

◆ getPingMs()

uint32_t rtp::client::NetworkSyncSystem::getPingMs ( void  ) const

Definition at line 234 of file NetworkSyncSystem.cpp.

References _pingMs.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ getReloadCooldownRemaining()

float rtp::client::NetworkSyncSystem::getReloadCooldownRemaining ( void  ) const

Definition at line 229 of file NetworkSyncSystem.cpp.

References _ammoReloadRemaining.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ getScore()

int rtp::client::NetworkSyncSystem::getScore ( void  ) const

Definition at line 280 of file NetworkSyncSystem.cpp.

References _score.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ getState()

NetworkSyncSystem::State rtp::client::NetworkSyncSystem::getState ( void  ) const

Get the current state of the client.

Returns
Current State enum value

Definition at line 209 of file NetworkSyncSystem.cpp.

References _currentState.

Referenced by rtp::client::scenes::CreateRoomScene::update(), and rtp::client::scenes::LobbyScene::update().

◆ getUsername()

std::string rtp::client::NetworkSyncSystem::getUsername ( void  ) const

Get the username of the client.

Returns
The username string

Definition at line 194 of file NetworkSyncSystem.cpp.

References _username.

◆ handleEvent()

◆ isInGame()

bool rtp::client::NetworkSyncSystem::isInGame ( void  ) const

Check if the client is in game.

Returns
true if in game, false otherwise

Definition at line 204 of file NetworkSyncSystem.cpp.

References _currentState, and InGame.

Referenced by rtp::client::scenes::RoomWaitingScene::update().

◆ isInRoom()

bool rtp::client::NetworkSyncSystem::isInRoom ( void  ) const

Check if the client is in a room.

Returns
true if in a room, false otherwise

Definition at line 174 of file NetworkSyncSystem.cpp.

References _currentState, InGame, and InRoom.

◆ isLoggedIn()

bool rtp::client::NetworkSyncSystem::isLoggedIn ( void  ) const

Check if the client is logged in.

Returns
true if logged in, false otherwise

Definition at line 189 of file NetworkSyncSystem.cpp.

References _isLoggedIn.

Referenced by rtp::client::scenes::LoginScene::update().

◆ isReady()

bool rtp::client::NetworkSyncSystem::isReady ( void  ) const

Check if the client is ready.

Returns
true if ready, false otherwise

Definition at line 179 of file NetworkSyncSystem.cpp.

References _isReady.

Referenced by trySetReady().

◆ isReloading()

bool rtp::client::NetworkSyncSystem::isReloading ( void  ) const

Definition at line 224 of file NetworkSyncSystem.cpp.

References _ammoReloading.

Referenced by rtp::client::scenes::PlayingScene::update().

◆ isUdpReady()

bool rtp::client::NetworkSyncSystem::isUdpReady ( void  ) const

Check if UDP is ready.

Returns
true if UDP is ready, false otherwise

Definition at line 184 of file NetworkSyncSystem.cpp.

References _network, and rtp::client::ClientNetwork::isUdpReady().

◆ onAmmoUpdate()

void rtp::client::NetworkSyncSystem::onAmmoUpdate ( net::Packet packet)
private

Definition at line 908 of file NetworkSyncSystem.cpp.

References _ammoCurrent, _ammoMax, _ammoReloading, and _ammoReloadRemaining.

Referenced by handleEvent().

◆ onBeamState()

◆ onCreateRoomResponse()

void rtp::client::NetworkSyncSystem::onCreateRoomResponse ( net::Packet packet)
private

◆ onDebugModeUpdate()

void rtp::client::NetworkSyncSystem::onDebugModeUpdate ( net::Packet packet)
private

Definition at line 1013 of file NetworkSyncSystem.cpp.

References rtp::client::g_drawDebugBounds.

Referenced by handleEvent().

◆ onEntityDeath()

◆ onJoinRoomResponse()

void rtp::client::NetworkSyncSystem::onJoinRoomResponse ( net::Packet packet)
private

Definition at line 478 of file NetworkSyncSystem.cpp.

References _currentState, rtp::log::info(), InRoom, and rtp::log::warning().

Referenced by handleEvent().

◆ onLeaveRoomResponse()

void rtp::client::NetworkSyncSystem::onLeaveRoomResponse ( net::Packet packet)
private

◆ onLoginResponse()

void rtp::client::NetworkSyncSystem::onLoginResponse ( net::Packet packet)
private

◆ onPong()

void rtp::client::NetworkSyncSystem::onPong ( net::Packet packet)
private

Definition at line 1000 of file NetworkSyncSystem.cpp.

References _pingMs.

Referenced by handleEvent().

◆ onRegisterResponse()

void rtp::client::NetworkSyncSystem::onRegisterResponse ( net::Packet packet)
private

◆ onRoomChatReceived()

void rtp::client::NetworkSyncSystem::onRoomChatReceived ( net::Packet packet)
private

Definition at line 883 of file NetworkSyncSystem.cpp.

References pushChatMessage().

Referenced by handleEvent().

◆ onRoomResponse()

void rtp::client::NetworkSyncSystem::onRoomResponse ( net::Packet packet)
private

Definition at line 442 of file NetworkSyncSystem.cpp.

References _availableRooms, and rtp::log::info().

Referenced by handleEvent().

◆ onRoomUpdate()

void rtp::client::NetworkSyncSystem::onRoomUpdate ( net::Packet packet)
private

◆ onSpawnEntityFromServer()

void rtp::client::NetworkSyncSystem::onSpawnEntityFromServer ( net::Packet packet)
private

Definition at line 523 of file NetworkSyncSystem.cpp.

References _builder, _netIdToEntity, _registry, rtp::ecs::Registry::add(), rtp::ecs::components::SimpleWeapon::ammo, rtp::ecs::components::Beam, rtp::ecs::components::SimpleWeapon::beamCooldown, rtp::ecs::components::SimpleWeapon::beamDuration, rtp::ecs::components::Boomerang, rtp::net::Boss, rtp::net::Boss2, rtp::net::Boss2Bullet, rtp::net::BossShield, rtp::net::Bullet, rtp::net::ChargedBullet, rtp::ecs::components::Classic, rtp::client::EntityTemplate::createBoss2Bullet(), rtp::client::EntityTemplate::createBoss2Kraken(), rtp::client::EntityTemplate::createBossShield(), rtp::client::EntityTemplate::createBossShip(), rtp::client::EntityTemplate::createBulletEnemy(), rtp::client::EntityTemplate::createBulletPlayer(), rtp::client::EntityTemplate::createPowerUpDoubleFire(), rtp::client::EntityTemplate::createPowerUpHeal(), rtp::client::EntityTemplate::createPowerUpShield(), rtp::ecs::components::SimpleWeapon::damage, rtp::log::debug(), rtp::client::EntityTemplate::effect_1(), rtp::client::EntityTemplate::effect_4(), rtp::client::EntityTemplate::enemy_1(), rtp::client::EntityTemplate::enemy_2(), rtp::net::EnemyBullet, rtp::log::error(), rtp::ecs::components::SimpleWeapon::fireRate, rtp::ecs::Registry::get(), rtp::config::getWeaponDef(), rtp::config::hasWeaponConfigs(), rtp::ecs::components::SimpleWeapon::homing, rtp::log::info(), rtp::ecs::components::SimpleWeapon::isBoomerang, rtp::ecs::components::SimpleWeapon::kind, rtp::ecs::components::SimpleWeapon::maxAmmo, rtp::net::EntitySpawnPayload::netId, rtp::net::Obstacle, rtp::net::ObstacleSolid, rtp::net::Player, rtp::client::EntityTemplate::player_ship(), rtp::net::EntitySpawnPayload::posX, rtp::net::EntitySpawnPayload::posY, rtp::net::PowerupDoubleFire, rtp::net::PowerupHeal, rtp::net::PowerupShield, rtp::net::PowerupSpeed, rtp::client::EntityTemplate::scale, rtp::net::Scout, rtp::client::EntityTemplate::shot_1(), rtp::net::EntitySpawnPayload::sizeX, rtp::net::EntitySpawnPayload::sizeY, rtp::client::EntityBuilder::spawn(), rtp::client::EntityTemplate::tag, rtp::net::Tank, rtp::ecs::components::Tracker, rtp::net::EntitySpawnPayload::type, rtp::log::warning(), and rtp::net::EntitySpawnPayload::weaponKind.

Referenced by handleEvent().

◆ pushChatMessage()

void rtp::client::NetworkSyncSystem::pushChatMessage ( const std::string &  message)
private

Definition at line 897 of file NetworkSyncSystem.cpp.

References _chatHistory, _chatHistoryLimit, and _lastChatMessage.

Referenced by onRoomChatReceived().

◆ requestListRooms()

void rtp::client::NetworkSyncSystem::requestListRooms ( void  )

Send a request to have the list of available rooms from the server.

Note
It updates the internal _availableRooms list

Definition at line 83 of file NetworkSyncSystem.cpp.

References _availableRooms, _network, rtp::log::info(), rtp::net::ListRooms, rtp::client::ClientNetwork::sendPacket(), and rtp::net::TCP.

Referenced by rtp::client::scenes::LobbyScene::buildUi(), rtp::client::scenes::LobbyScene::onEnter(), and rtp::client::scenes::MenuScene::onEnter().

◆ sendSelectedWeapon()

void rtp::client::NetworkSyncSystem::sendSelectedWeapon ( uint8_t  weaponKind) const

Send currently selected weapon to server to apply immediately.

Parameters
weaponKindweapon id (ecs::components::WeaponKind as uint8_t)

Definition at line 162 of file NetworkSyncSystem.cpp.

References _network, rtp::log::info(), rtp::client::ClientNetwork::sendPacket(), rtp::net::TCP, and rtp::net::UpdateSelectedWeapon.

Referenced by rtp::client::scenes::MenuScene::onEnter().

◆ setGameOverSummary()

void rtp::client::NetworkSyncSystem::setGameOverSummary ( const GameOverSummary summary)

Definition at line 261 of file NetworkSyncSystem.cpp.

References _gameOverSummary.

◆ tryCreateRoom()

void rtp::client::NetworkSyncSystem::tryCreateRoom ( const std::string &  roomName,
uint32_t  maxPlayers,
float  difficulty,
float  speed,
uint32_t  duration,
uint32_t  seed,
uint32_t  levelId,
uint8_t  roomType 
)

Send a request to create a new room on the server.

Parameters
roomNameName of the room
maxPlayersMaximum number of players allowed
difficultyDifficulty level of the room
speedSpeed multiplier for the game
durationDuration of the game session
seedSeed for random generation
levelIdLevel identifier
roomTypeType of the room (Public/Private)

Definition at line 92 of file NetworkSyncSystem.cpp.

References _currentLevelId, _currentState, _network, rtp::net::CreateRoom, CreatingRoom, rtp::net::CreateRoomPayload::difficulty, rtp::net::CreateRoomPayload::duration, rtp::log::info(), rtp::net::CreateRoomPayload::levelId, rtp::net::CreateRoomPayload::maxPlayers, rtp::net::CreateRoomPayload::roomName, rtp::net::CreateRoomPayload::roomType, rtp::net::CreateRoomPayload::seed, rtp::client::ClientNetwork::sendPacket(), rtp::net::CreateRoomPayload::speed, and rtp::net::TCP.

Referenced by rtp::client::scenes::CreateRoomScene::onEnter(), and tryStartSolo().

◆ tryJoinRoom()

void rtp::client::NetworkSyncSystem::tryJoinRoom ( uint32_t  roomId,
bool  asSpectator = false 
)

Send a request to join an existing room on the server.

Parameters
roomIdIdentifier of the room to join

Definition at line 111 of file NetworkSyncSystem.cpp.

References _availableRooms, _currentLevelId, _currentState, _network, JoiningRoom, rtp::net::JoinRoom, rtp::net::JoinRoomPayload::roomId, rtp::client::ClientNetwork::sendPacket(), and rtp::net::TCP.

Referenced by rtp::client::scenes::LobbyScene::buildUi().

◆ tryLeaveRoom()

◆ tryLogin()

void rtp::client::NetworkSyncSystem::tryLogin ( const std::string &  username,
const std::string &  password,
uint8_t  weaponKind 
) const

Send a request to server attempting to log in with provided credentials.

Parameters
sessionIdID of the network session
usernameUsername string
passwordPassword string
weaponKindSelected weapon kind

Definition at line 58 of file NetworkSyncSystem.cpp.

References _network, rtp::net::LoginRequest, rtp::net::LoginPayload::password, rtp::client::ClientNetwork::sendPacket(), rtp::net::TCP, rtp::net::LoginPayload::username, and rtp::net::LoginPayload::weaponKind.

Referenced by rtp::client::scenes::LoginScene::onEnter().

◆ tryRegister()

void rtp::client::NetworkSyncSystem::tryRegister ( const std::string &  username,
const std::string &  password 
) const

Send a request to server attempting to register with provided credentials.

Parameters
sessionIdID of the network session
usernameUsername string
passwordPassword string

Definition at line 71 of file NetworkSyncSystem.cpp.

References _network, rtp::net::RegisterPayload::password, rtp::net::RegisterRequest, rtp::client::ClientNetwork::sendPacket(), rtp::net::TCP, and rtp::net::RegisterPayload::username.

Referenced by rtp::client::scenes::LoginScene::onEnter().

◆ trySendMessage()

void rtp::client::NetworkSyncSystem::trySendMessage ( const std::string &  message) const

Send a chat message to the server.

Parameters
messageThe message string to send

Definition at line 151 of file NetworkSyncSystem.cpp.

References _network, rtp::net::RoomChatSended, rtp::client::ClientNetwork::sendPacket(), and rtp::net::TCP.

Referenced by rtp::client::scenes::PlayingScene::sendChatMessage(), and rtp::client::scenes::RoomWaitingScene::sendChatMessage().

◆ trySetReady()

void rtp::client::NetworkSyncSystem::trySetReady ( bool  isReady)

Send a request to set the client's ready status in the current room.

Parameters
isReadytrue to set as ready, false to set as not ready

Definition at line 138 of file NetworkSyncSystem.cpp.

References _network, isReady(), rtp::client::ClientNetwork::sendPacket(), rtp::net::SetReady, and rtp::net::TCP.

Referenced by onCreateRoomResponse(), rtp::client::scenes::RoomWaitingScene::onEnter(), and tryLeaveRoom().

◆ tryStartSolo()

void rtp::client::NetworkSyncSystem::tryStartSolo ( void  )

Start a solo game by creating a private room and auto-joining/readying.

Definition at line 146 of file NetworkSyncSystem.cpp.

References _isStartingSolo, rtp::net::Private, and tryCreateRoom().

Referenced by rtp::client::scenes::MenuScene::onEnter().

◆ update()

void rtp::client::NetworkSyncSystem::update ( float  dt)
overridevirtual

Update system logic for one frame.

Parameters
dtTime elapsed since last update in seconds

Implements rtp::ecs::ISystem.

Definition at line 36 of file NetworkSyncSystem.cpp.

References _ammoReloading, _ammoReloadRemaining, _network, _pingInterval, _pingTimer, handleEvent(), rtp::net::Ping, rtp::client::ClientNetwork::pollEvent(), rtp::client::ClientNetwork::sendPacket(), and rtp::net::UDP.

Member Data Documentation

◆ _ammoCurrent

uint16_t rtp::client::NetworkSyncSystem::_ammoCurrent = 0
private

Current ammo.

Definition at line 244 of file NetworkSyncSystem.hpp.

Referenced by getAmmoCurrent(), and onAmmoUpdate().

◆ _ammoMax

uint16_t rtp::client::NetworkSyncSystem::_ammoMax = 100
private

Max ammo.

Definition at line 245 of file NetworkSyncSystem.hpp.

Referenced by getAmmoMax(), and onAmmoUpdate().

◆ _ammoReloading

bool rtp::client::NetworkSyncSystem::_ammoReloading = false
private

Reload state.

Definition at line 246 of file NetworkSyncSystem.hpp.

Referenced by isReloading(), onAmmoUpdate(), and update().

◆ _ammoReloadRemaining

float rtp::client::NetworkSyncSystem::_ammoReloadRemaining = 0.0f
private

Reload time remaining.

Definition at line 247 of file NetworkSyncSystem.hpp.

Referenced by getReloadCooldownRemaining(), onAmmoUpdate(), and update().

◆ _availableRooms

std::list<net::RoomInfo> rtp::client::NetworkSyncSystem::_availableRooms
private

List of available rooms from the server.

Definition at line 239 of file NetworkSyncSystem.hpp.

Referenced by getAvailableRooms(), onRoomResponse(), requestListRooms(), and tryJoinRoom().

◆ _beamEntities

std::unordered_map<uint32_t, std::vector<std::pair<ecs::Entity, float> > > rtp::client::NetworkSyncSystem::_beamEntities
private

Definition at line 291 of file NetworkSyncSystem.hpp.

Referenced by onBeamState(), and onRoomUpdate().

◆ _beamLengths

std::unordered_map<uint32_t, std::vector<float> > rtp::client::NetworkSyncSystem::_beamLengths
private

Definition at line 293 of file NetworkSyncSystem.hpp.

Referenced by onBeamState(), and onRoomUpdate().

◆ _builder

EntityBuilder rtp::client::NetworkSyncSystem::_builder
private

Entity builder for spawning entities.

Definition at line 231 of file NetworkSyncSystem.hpp.

Referenced by onBeamState(), and onSpawnEntityFromServer().

◆ _chatHistory

std::deque<std::string> rtp::client::NetworkSyncSystem::_chatHistory
private

Recent chat messages.

Definition at line 242 of file NetworkSyncSystem.hpp.

Referenced by getChatHistory(), handleEvent(), onLeaveRoomResponse(), and pushChatMessage().

◆ _chatHistoryLimit

std::size_t rtp::client::NetworkSyncSystem::_chatHistoryLimit = 8
private

Max chat messages to keep.

Definition at line 243 of file NetworkSyncSystem.hpp.

Referenced by pushChatMessage().

◆ _currentLevelId

uint32_t rtp::client::NetworkSyncSystem::_currentLevelId = 1
private

Current level id used by client visuals.

Definition at line 252 of file NetworkSyncSystem.hpp.

Referenced by getCurrentLevelId(), tryCreateRoom(), and tryJoinRoom().

◆ _currentState

State rtp::client::NetworkSyncSystem::_currentState = State::NotLogged
private

◆ _gameOverPending

bool rtp::client::NetworkSyncSystem::_gameOverPending {false}
private

Game over pending flag.

Definition at line 254 of file NetworkSyncSystem.hpp.

Referenced by consumeGameOver(), and handleEvent().

◆ _gameOverSummary

GameOverSummary rtp::client::NetworkSyncSystem::_gameOverSummary {}
private

Cached game over summary.

Definition at line 253 of file NetworkSyncSystem.hpp.

Referenced by getGameOverSummary(), handleEvent(), and setGameOverSummary().

◆ _healthCurrent

int rtp::client::NetworkSyncSystem::_healthCurrent {0}
private

Latest health.

Definition at line 256 of file NetworkSyncSystem.hpp.

Referenced by getHealthCurrent(), and handleEvent().

◆ _healthMax

int rtp::client::NetworkSyncSystem::_healthMax {0}
private

Latest max health.

Definition at line 257 of file NetworkSyncSystem.hpp.

Referenced by getHealthMax(), and handleEvent().

◆ _isInRoom

bool rtp::client::NetworkSyncSystem::_isInRoom = false
private

Flag indicating if the client is in a room.

Definition at line 234 of file NetworkSyncSystem.hpp.

◆ _isLoggedIn

bool rtp::client::NetworkSyncSystem::_isLoggedIn = false
private

Flag indicating if the client is logged in.

Definition at line 237 of file NetworkSyncSystem.hpp.

Referenced by isLoggedIn(), onLoginResponse(), and onRegisterResponse().

◆ _isReady

bool rtp::client::NetworkSyncSystem::_isReady = false
private

Flag indicating if the client is ready.

Definition at line 235 of file NetworkSyncSystem.hpp.

Referenced by isReady().

◆ _isStartingSolo

bool rtp::client::NetworkSyncSystem::_isStartingSolo = false

Check if the client is starting a solo game.

Returns
true if starting solo, false otherwise

Definition at line 164 of file NetworkSyncSystem.hpp.

Referenced by onCreateRoomResponse(), and tryStartSolo().

◆ _kicked

bool rtp::client::NetworkSyncSystem::_kicked = false
private

Kicked flag.

Definition at line 251 of file NetworkSyncSystem.hpp.

Referenced by consumeKicked(), and handleEvent().

◆ _lastChatMessage

std::string rtp::client::NetworkSyncSystem::_lastChatMessage
private

Last received chat message.

Definition at line 241 of file NetworkSyncSystem.hpp.

Referenced by getLastChatMessage(), handleEvent(), onLeaveRoomResponse(), and pushChatMessage().

◆ _netIdToEntity

std::unordered_map<uint32_t, ecs::Entity> rtp::client::NetworkSyncSystem::_netIdToEntity
private

Map of network IDs to entities.

Definition at line 230 of file NetworkSyncSystem.hpp.

Referenced by onBeamState(), onEntityDeath(), onRoomUpdate(), and onSpawnEntityFromServer().

◆ _network

ClientNetwork& rtp::client::NetworkSyncSystem::_network
private

◆ _pingInterval

float rtp::client::NetworkSyncSystem::_pingInterval = 1.0f
private

Ping interval in seconds.

Definition at line 250 of file NetworkSyncSystem.hpp.

Referenced by update().

◆ _pingMs

uint32_t rtp::client::NetworkSyncSystem::_pingMs = 0
private

Latest ping in ms.

Definition at line 248 of file NetworkSyncSystem.hpp.

Referenced by getPingMs(), and onPong().

◆ _pingTimer

float rtp::client::NetworkSyncSystem::_pingTimer = 0.0f
private

Ping timer accumulator.

Definition at line 249 of file NetworkSyncSystem.hpp.

Referenced by update().

◆ _registry

ecs::Registry& rtp::client::NetworkSyncSystem::_registry
private

Reference to the entity registry.

Definition at line 229 of file NetworkSyncSystem.hpp.

Referenced by onBeamState(), onEntityDeath(), onRoomUpdate(), and onSpawnEntityFromServer().

◆ _score

int rtp::client::NetworkSyncSystem::_score {0}
private

Latest server score.

Definition at line 255 of file NetworkSyncSystem.hpp.

Referenced by getScore(), and handleEvent().

◆ _udpReady

bool rtp::client::NetworkSyncSystem::_udpReady = false
private

Flag indicating if UDP is ready.

Definition at line 236 of file NetworkSyncSystem.hpp.

◆ _username

std::string rtp::client::NetworkSyncSystem::_username
private

The username of the client.

Definition at line 238 of file NetworkSyncSystem.hpp.

Referenced by getUsername(), onLoginResponse(), and onRegisterResponse().


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