|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
System to handle network-related operations on the client side. More...
#include <NetworkSyncSystem.hpp>
Classes | |
| struct | GameOverSummary |
Public Types | |
| enum class | State { NotLogged , InLobby , JoiningRoom , CreatingRoom , LeavingRoom , InRoom , InGame } |
Public Member Functions | |
| NetworkSyncSystem (ClientNetwork &network, ecs::Registry ®istry, 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::RoomInfo > | getAvailableRooms (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 |
System to handle network-related operations on the client side.
Definition at line 39 of file NetworkSyncSystem.hpp.
|
strong |
| Enumerator | |
|---|---|
| NotLogged | |
| InLobby | |
| JoiningRoom | |
| CreatingRoom | |
| LeavingRoom | |
| InRoom | |
| InGame | |
Definition at line 42 of file NetworkSyncSystem.hpp.
| rtp::client::NetworkSyncSystem::NetworkSyncSystem | ( | ClientNetwork & | network, |
| ecs::Registry & | registry, | ||
| EntityBuilder | builder | ||
| ) |
Constructor for NetworkSyncSystem.
| network | Reference to the client network manager |
| registry | Reference to the entity registry |
Definition at line 33 of file NetworkSyncSystem.cpp.
| bool rtp::client::NetworkSyncSystem::consumeGameOver | ( | void | ) |
Definition at line 271 of file NetworkSyncSystem.cpp.
References _gameOverPending.
Referenced by rtp::client::scenes::PlayingScene::update().
| bool rtp::client::NetworkSyncSystem::consumeKicked | ( | void | ) |
Definition at line 239 of file NetworkSyncSystem.cpp.
References _kicked.
Referenced by rtp::client::scenes::PlayingScene::update(), and rtp::client::scenes::RoomWaitingScene::update().
| 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().
| 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().
| std::list< net::RoomInfo > rtp::client::NetworkSyncSystem::getAvailableRooms | ( | void | ) | const |
Get a list of available rooms from the server.
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().
| const std::deque< std::string > & rtp::client::NetworkSyncSystem::getChatHistory | ( | void | ) | const |
Get chat history buffer (most recent last)
Definition at line 256 of file NetworkSyncSystem.cpp.
References _chatHistory.
Referenced by rtp::client::scenes::PlayingScene::updateChatHistoryText(), and rtp::client::scenes::RoomWaitingScene::updateChatHistoryText().
| 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().
| 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().
| int rtp::client::NetworkSyncSystem::getHealthCurrent | ( | void | ) | const |
Definition at line 285 of file NetworkSyncSystem.cpp.
References _healthCurrent.
Referenced by rtp::client::scenes::PlayingScene::update().
| int rtp::client::NetworkSyncSystem::getHealthMax | ( | void | ) | const |
Definition at line 290 of file NetworkSyncSystem.cpp.
References _healthMax.
Referenced by rtp::client::scenes::PlayingScene::update().
| std::string rtp::client::NetworkSyncSystem::getLastChatMessage | ( | void | ) | const |
Get the last received room chat message.
Definition at line 251 of file NetworkSyncSystem.cpp.
References _lastChatMessage.
Referenced by rtp::client::scenes::PlayingScene::update(), and rtp::client::scenes::RoomWaitingScene::update().
| 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().
| float rtp::client::NetworkSyncSystem::getReloadCooldownRemaining | ( | void | ) | const |
Definition at line 229 of file NetworkSyncSystem.cpp.
References _ammoReloadRemaining.
Referenced by rtp::client::scenes::PlayingScene::update().
| int rtp::client::NetworkSyncSystem::getScore | ( | void | ) | const |
Definition at line 280 of file NetworkSyncSystem.cpp.
References _score.
Referenced by rtp::client::scenes::PlayingScene::update().
| NetworkSyncSystem::State rtp::client::NetworkSyncSystem::getState | ( | void | ) | const |
Get the current state of the client.
Definition at line 209 of file NetworkSyncSystem.cpp.
References _currentState.
Referenced by rtp::client::scenes::CreateRoomScene::update(), and rtp::client::scenes::LobbyScene::update().
| std::string rtp::client::NetworkSyncSystem::getUsername | ( | void | ) | const |
Get the username of the client.
Definition at line 194 of file NetworkSyncSystem.cpp.
References _username.
|
private |
Handle a network event.
| event | Reference to the network event to handle |
Definition at line 299 of file NetworkSyncSystem.cpp.
References _chatHistory, _currentState, _gameOverPending, _gameOverSummary, _healthCurrent, _healthMax, _kicked, _lastChatMessage, _score, rtp::net::AmmoUpdate, rtp::net::BeamState, rtp::client::NetworkSyncSystem::GameOverSummary::bestPlayer, rtp::client::NetworkSyncSystem::GameOverSummary::bestScore, rtp::net::CreateRoom, rtp::net::HealthUpdatePayload::current, rtp::net::DebugModeUpdate, rtp::net::EntityDeath, rtp::net::EntitySpawn, rtp::net::GameOver, rtp::net::Packet::header, rtp::net::HealthUpdate, rtp::log::info(), InGame, InLobby, rtp::net::JoinRoom, rtp::net::Kicked, rtp::net::LeaveRoom, rtp::net::LoginResponse, onAmmoUpdate(), onBeamState(), onCreateRoomResponse(), onDebugModeUpdate(), onEntityDeath(), onJoinRoomResponse(), onLeaveRoomResponse(), onLoginResponse(), onPong(), onRegisterResponse(), onRoomChatReceived(), onRoomResponse(), onRoomUpdate(), onSpawnEntityFromServer(), rtp::net::Header::opCode, rtp::net::NetworkEvent::packet, rtp::client::NetworkSyncSystem::GameOverSummary::playerScore, rtp::net::Pong, rtp::net::RegisterResponse, rtp::net::RoomChatReceived, rtp::net::RoomList, rtp::net::RoomUpdate, rtp::net::ScoreUpdatePayload::score, rtp::net::ScoreUpdate, rtp::net::StartGame, and rtp::log::warning().
Referenced by update().
| bool rtp::client::NetworkSyncSystem::isInGame | ( | void | ) | const |
Check if the client is in game.
Definition at line 204 of file NetworkSyncSystem.cpp.
References _currentState, and InGame.
Referenced by rtp::client::scenes::RoomWaitingScene::update().
| bool rtp::client::NetworkSyncSystem::isInRoom | ( | void | ) | const |
Check if the client is in a room.
Definition at line 174 of file NetworkSyncSystem.cpp.
References _currentState, InGame, and InRoom.
| bool rtp::client::NetworkSyncSystem::isLoggedIn | ( | void | ) | const |
Check if the client is logged in.
Definition at line 189 of file NetworkSyncSystem.cpp.
References _isLoggedIn.
Referenced by rtp::client::scenes::LoginScene::update().
| bool rtp::client::NetworkSyncSystem::isReady | ( | void | ) | const |
Check if the client is ready.
Definition at line 179 of file NetworkSyncSystem.cpp.
References _isReady.
Referenced by trySetReady().
| bool rtp::client::NetworkSyncSystem::isReloading | ( | void | ) | const |
Definition at line 224 of file NetworkSyncSystem.cpp.
References _ammoReloading.
Referenced by rtp::client::scenes::PlayingScene::update().
| bool rtp::client::NetworkSyncSystem::isUdpReady | ( | void | ) | const |
Check if UDP is ready.
Definition at line 184 of file NetworkSyncSystem.cpp.
References _network, and rtp::client::ClientNetwork::isUdpReady().
|
private |
Definition at line 908 of file NetworkSyncSystem.cpp.
References _ammoCurrent, _ammoMax, _ammoReloading, and _ammoReloadRemaining.
Referenced by handleEvent().
|
private |
Definition at line 919 of file NetworkSyncSystem.cpp.
References _beamEntities, _beamLengths, _builder, _netIdToEntity, _registry, rtp::log::error(), rtp::ecs::Registry::get(), rtp::client::EntityBuilder::kill(), rtp::client::EntityTemplate::position, rtp::client::EntityTemplate::rotation, rtp::client::EntityTemplate::scale, rtp::client::EntityTemplate::shot_5(), rtp::client::EntityBuilder::spawn(), rtp::client::EntityTemplate::tag, rtp::Vec2< T >::x, and rtp::Vec2< T >::y.
Referenced by handleEvent().
|
private |
Definition at line 491 of file NetworkSyncSystem.cpp.
References _currentState, _isStartingSolo, rtp::log::info(), InRoom, trySetReady(), and rtp::log::warning().
Referenced by handleEvent().
|
private |
Definition at line 1013 of file NetworkSyncSystem.cpp.
References rtp::client::g_drawDebugBounds.
Referenced by handleEvent().
|
private |
Definition at line 727 of file NetworkSyncSystem.cpp.
References _netIdToEntity, _registry, rtp::ecs::Registry::add(), rtp::ecs::components::ShieldVisual::animationTime, rtp::log::debug(), rtp::net::EnemyBullet, rtp::ecs::Registry::get(), rtp::log::info(), rtp::ecs::Registry::kill(), rtp::net::Player, rtp::net::PowerupShield, rtp::ecs::Registry::remove(), rtp::ecs::components::EntityType::type, and rtp::log::warning().
Referenced by handleEvent().
|
private |
Definition at line 478 of file NetworkSyncSystem.cpp.
References _currentState, rtp::log::info(), InRoom, and rtp::log::warning().
Referenced by handleEvent().
|
private |
Definition at line 508 of file NetworkSyncSystem.cpp.
References _chatHistory, _currentState, _lastChatMessage, rtp::log::info(), InLobby, and rtp::log::warning().
Referenced by handleEvent().
|
private |
Definition at line 406 of file NetworkSyncSystem.cpp.
References _currentState, _isLoggedIn, _username, rtp::log::info(), InLobby, NotLogged, rtp::net::LoginResponsePayload::success, rtp::net::LoginResponsePayload::username, and rtp::log::warning().
Referenced by handleEvent().
|
private |
Definition at line 1000 of file NetworkSyncSystem.cpp.
References _pingMs.
Referenced by handleEvent().
|
private |
Definition at line 424 of file NetworkSyncSystem.cpp.
References _currentState, _isLoggedIn, _username, rtp::log::info(), InLobby, NotLogged, rtp::net::RegisterResponsePayload::success, rtp::net::RegisterResponsePayload::username, and rtp::log::warning().
Referenced by handleEvent().
|
private |
Definition at line 883 of file NetworkSyncSystem.cpp.
References pushChatMessage().
Referenced by handleEvent().
|
private |
Definition at line 442 of file NetworkSyncSystem.cpp.
References _availableRooms, and rtp::log::info().
Referenced by handleEvent().
|
private |
Definition at line 813 of file NetworkSyncSystem.cpp.
References _beamEntities, _beamLengths, _netIdToEntity, _registry, rtp::ecs::Registry::get(), rtp::ecs::components::Transform::position, and rtp::Vec2< T >::x.
Referenced by handleEvent().
|
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().
|
private |
Definition at line 897 of file NetworkSyncSystem.cpp.
References _chatHistory, _chatHistoryLimit, and _lastChatMessage.
Referenced by onRoomChatReceived().
| void rtp::client::NetworkSyncSystem::requestListRooms | ( | void | ) |
Send a request to have the list of available rooms from the server.
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().
| void rtp::client::NetworkSyncSystem::sendSelectedWeapon | ( | uint8_t | weaponKind | ) | const |
Send currently selected weapon to server to apply immediately.
| weaponKind | weapon 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().
| void rtp::client::NetworkSyncSystem::setGameOverSummary | ( | const GameOverSummary & | summary | ) |
Definition at line 261 of file NetworkSyncSystem.cpp.
References _gameOverSummary.
| 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.
| roomName | Name of the room |
| maxPlayers | Maximum number of players allowed |
| difficulty | Difficulty level of the room |
| speed | Speed multiplier for the game |
| duration | Duration of the game session |
| seed | Seed for random generation |
| levelId | Level identifier |
| roomType | Type 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().
| void rtp::client::NetworkSyncSystem::tryJoinRoom | ( | uint32_t | roomId, |
| bool | asSpectator = false |
||
| ) |
Send a request to join an existing room on the server.
| roomId | Identifier 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().
| void rtp::client::NetworkSyncSystem::tryLeaveRoom | ( | void | ) |
Send a request to leave the current room on the server.
Definition at line 130 of file NetworkSyncSystem.cpp.
References _currentState, _network, rtp::net::LeaveRoom, LeavingRoom, rtp::client::ClientNetwork::sendPacket(), rtp::net::TCP, and trySetReady().
Referenced by rtp::client::scenes::GameOverScene::handleEvent(), rtp::client::scenes::GameOverScene::onEnter(), rtp::client::scenes::PauseScene::onEnter(), and rtp::client::scenes::RoomWaitingScene::onEnter().
| 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.
| sessionId | ID of the network session |
| username | Username string |
| password | Password string |
| weaponKind | Selected 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().
| 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.
| sessionId | ID of the network session |
| username | Username string |
| password | Password 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().
| void rtp::client::NetworkSyncSystem::trySendMessage | ( | const std::string & | message | ) | const |
Send a chat message to the server.
| message | The 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().
| void rtp::client::NetworkSyncSystem::trySetReady | ( | bool | isReady | ) |
Send a request to set the client's ready status in the current room.
| isReady | true 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().
| 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().
|
overridevirtual |
Update system logic for one frame.
| dt | Time 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.
|
private |
Current ammo.
Definition at line 244 of file NetworkSyncSystem.hpp.
Referenced by getAmmoCurrent(), and onAmmoUpdate().
|
private |
Max ammo.
Definition at line 245 of file NetworkSyncSystem.hpp.
Referenced by getAmmoMax(), and onAmmoUpdate().
|
private |
Reload state.
Definition at line 246 of file NetworkSyncSystem.hpp.
Referenced by isReloading(), onAmmoUpdate(), and update().
|
private |
Reload time remaining.
Definition at line 247 of file NetworkSyncSystem.hpp.
Referenced by getReloadCooldownRemaining(), onAmmoUpdate(), and update().
|
private |
List of available rooms from the server.
Definition at line 239 of file NetworkSyncSystem.hpp.
Referenced by getAvailableRooms(), onRoomResponse(), requestListRooms(), and tryJoinRoom().
|
private |
Definition at line 291 of file NetworkSyncSystem.hpp.
Referenced by onBeamState(), and onRoomUpdate().
|
private |
Definition at line 293 of file NetworkSyncSystem.hpp.
Referenced by onBeamState(), and onRoomUpdate().
|
private |
Entity builder for spawning entities.
Definition at line 231 of file NetworkSyncSystem.hpp.
Referenced by onBeamState(), and onSpawnEntityFromServer().
|
private |
Recent chat messages.
Definition at line 242 of file NetworkSyncSystem.hpp.
Referenced by getChatHistory(), handleEvent(), onLeaveRoomResponse(), and pushChatMessage().
|
private |
Max chat messages to keep.
Definition at line 243 of file NetworkSyncSystem.hpp.
Referenced by pushChatMessage().
|
private |
Current level id used by client visuals.
Definition at line 252 of file NetworkSyncSystem.hpp.
Referenced by getCurrentLevelId(), tryCreateRoom(), and tryJoinRoom().
|
private |
Current state of the client.
Definition at line 240 of file NetworkSyncSystem.hpp.
Referenced by getState(), handleEvent(), isInGame(), isInRoom(), onCreateRoomResponse(), onJoinRoomResponse(), onLeaveRoomResponse(), onLoginResponse(), onRegisterResponse(), tryCreateRoom(), tryJoinRoom(), and tryLeaveRoom().
|
private |
Game over pending flag.
Definition at line 254 of file NetworkSyncSystem.hpp.
Referenced by consumeGameOver(), and handleEvent().
|
private |
Cached game over summary.
Definition at line 253 of file NetworkSyncSystem.hpp.
Referenced by getGameOverSummary(), handleEvent(), and setGameOverSummary().
|
private |
Latest health.
Definition at line 256 of file NetworkSyncSystem.hpp.
Referenced by getHealthCurrent(), and handleEvent().
|
private |
Latest max health.
Definition at line 257 of file NetworkSyncSystem.hpp.
Referenced by getHealthMax(), and handleEvent().
|
private |
Flag indicating if the client is in a room.
Definition at line 234 of file NetworkSyncSystem.hpp.
|
private |
Flag indicating if the client is logged in.
Definition at line 237 of file NetworkSyncSystem.hpp.
Referenced by isLoggedIn(), onLoginResponse(), and onRegisterResponse().
|
private |
Flag indicating if the client is ready.
Definition at line 235 of file NetworkSyncSystem.hpp.
Referenced by isReady().
| bool rtp::client::NetworkSyncSystem::_isStartingSolo = false |
Check if the client is starting a solo game.
Definition at line 164 of file NetworkSyncSystem.hpp.
Referenced by onCreateRoomResponse(), and tryStartSolo().
|
private |
Kicked flag.
Definition at line 251 of file NetworkSyncSystem.hpp.
Referenced by consumeKicked(), and handleEvent().
|
private |
Last received chat message.
Definition at line 241 of file NetworkSyncSystem.hpp.
Referenced by getLastChatMessage(), handleEvent(), onLeaveRoomResponse(), and pushChatMessage().
|
private |
Map of network IDs to entities.
Definition at line 230 of file NetworkSyncSystem.hpp.
Referenced by onBeamState(), onEntityDeath(), onRoomUpdate(), and onSpawnEntityFromServer().
|
private |
Reference to the client network manager.
Definition at line 228 of file NetworkSyncSystem.hpp.
Referenced by isUdpReady(), requestListRooms(), sendSelectedWeapon(), tryCreateRoom(), tryJoinRoom(), tryLeaveRoom(), tryLogin(), tryRegister(), trySendMessage(), trySetReady(), and update().
|
private |
Ping interval in seconds.
Definition at line 250 of file NetworkSyncSystem.hpp.
Referenced by update().
|
private |
Latest ping in ms.
Definition at line 248 of file NetworkSyncSystem.hpp.
Referenced by getPingMs(), and onPong().
|
private |
Ping timer accumulator.
Definition at line 249 of file NetworkSyncSystem.hpp.
Referenced by update().
|
private |
Reference to the entity registry.
Definition at line 229 of file NetworkSyncSystem.hpp.
Referenced by onBeamState(), onEntityDeath(), onRoomUpdate(), and onSpawnEntityFromServer().
|
private |
Latest server score.
Definition at line 255 of file NetworkSyncSystem.hpp.
Referenced by getScore(), and handleEvent().
|
private |
Flag indicating if UDP is ready.
Definition at line 236 of file NetworkSyncSystem.hpp.
|
private |
The username of the client.
Definition at line 238 of file NetworkSyncSystem.hpp.
Referenced by getUsername(), onLoginResponse(), and onRegisterResponse().