diff --git a/include/game/client/ClientConnexion.h b/include/game/client/ClientConnexion.h index 8b3edbb..3a05365 100644 --- a/include/game/client/ClientConnexion.h +++ b/include/game/client/ClientConnexion.h @@ -12,6 +12,7 @@ private: std::uint8_t m_ConnectionID; std::string m_DisconnectReason; float m_ServerTPS; + float m_ServerMSPT; int m_Ping = 0; public: ClientConnexion(); @@ -25,6 +26,7 @@ public: const std::string& GetDisconnectReason() const { return m_DisconnectReason; } float GetServerTPS() const { return m_ServerTPS; } + float GetServerMSPT() const { return m_ServerMSPT; } int GetServerPing() const { return m_Ping; } REMOVE_COPY(ClientConnexion); diff --git a/include/game/server/Server.h b/include/game/server/Server.h index 12140be..406a97e 100644 --- a/include/game/server/Server.h +++ b/include/game/server/Server.h @@ -22,6 +22,7 @@ typedef std::map ConnexionMap; class TickCounter { private: float m_TPS; + float m_MSPT; std::uint64_t m_LastTPSTime; std::uint8_t m_TickCount; public: @@ -46,6 +47,9 @@ public: } float GetTPS() const { return m_TPS; } + float GetMSPT() const { return m_MSPT; } + + void SetMSPT(float mspt) { m_MSPT = mspt; } }; class Server { diff --git a/include/protocol/Protocol.h b/include/protocol/Protocol.h index 6d37c4d..fbddf47 100644 --- a/include/protocol/Protocol.h +++ b/include/protocol/Protocol.h @@ -373,10 +373,11 @@ public: class ServerTpsPacket : public Packet { private: float m_TPS; + float m_MSPT; std::uint64_t m_PacketSendTime; // used to calculate ping public: ServerTpsPacket() {} - ServerTpsPacket(float tps, std::uint64_t sendTime) : m_TPS(tps), m_PacketSendTime(sendTime) {} + ServerTpsPacket(float tps, float mspt, std::uint64_t sendTime) : m_TPS(tps), m_MSPT(mspt), m_PacketSendTime(sendTime) {} virtual ~ServerTpsPacket() {} virtual DataBuffer Serialize(bool packetID = true) const; @@ -384,6 +385,7 @@ public: virtual void Dispatch(PacketHandler* handler) const; float GetTPS() const { return m_TPS; } + float GetMSPT() const { return m_MSPT; } std::uint64_t GetPacketSendTime() const { return m_PacketSendTime; } virtual PacketType GetType() const { return PacketType::ServerTps; } diff --git a/src/game/client/ClientConnexion.cpp b/src/game/client/ClientConnexion.cpp index 225d780..7528f7a 100644 --- a/src/game/client/ClientConnexion.cpp +++ b/src/game/client/ClientConnexion.cpp @@ -27,6 +27,7 @@ void ClientConnexion::HandlePacket(const protocol::ConnexionInfoPacket* packet) void ClientConnexion::HandlePacket(const protocol::ServerTpsPacket* packet) { m_ServerTPS = packet->GetTPS(); + m_ServerMSPT = packet->GetMSPT(); m_Ping = utils::GetTime() - packet->GetPacketSendTime(); } diff --git a/src/game/server/Server.cpp b/src/game/server/Server.cpp index c729a45..fecadfd 100644 --- a/src/game/server/Server.cpp +++ b/src/game/server/Server.cpp @@ -26,13 +26,14 @@ void Server::StartThread() { if (delta >= SERVER_TICK) { Tick(delta); lastTime = td::utils::GetTime(); + m_TickCounter.SetMSPT(lastTime - time); std::uint64_t sleepTime = SERVER_TICK - (delta - SERVER_TICK); std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); } } Clean(); - }); + }); } void Server::Close() { @@ -85,7 +86,7 @@ void Server::Tick(std::uint64_t delta) { m_Lobby.Tick(); m_Game.Tick(delta); if (m_TickCounter.Update()) { - protocol::ServerTpsPacket packet(m_TickCounter.GetTPS(), utils::GetTime()); + protocol::ServerTpsPacket packet(m_TickCounter.GetTPS(), m_TickCounter.GetMSPT(), utils::GetTime()); BroadcastPacket(&packet); } } diff --git a/src/protocol/Protocol.cpp b/src/protocol/Protocol.cpp index 51b0562..25f2b01 100644 --- a/src/protocol/Protocol.cpp +++ b/src/protocol/Protocol.cpp @@ -29,22 +29,22 @@ static DataBuffer& operator<<(DataBuffer& buffer, game::TilePtr tile) { switch (tile->GetType()) { case game::TileType::Tower: { - const game::TowerTile* towerTile = dynamic_cast(tile.get()); - buffer << towerTile->color_palette_ref << towerTile->team_owner; - break; - } + const game::TowerTile* towerTile = dynamic_cast(tile.get()); + buffer << towerTile->color_palette_ref << towerTile->team_owner; + break; + } case game::TileType::Walk: { - const game::WalkableTile* walkTile = dynamic_cast(tile.get()); - buffer << walkTile->direction; - break; - } + const game::WalkableTile* walkTile = dynamic_cast(tile.get()); + buffer << walkTile->direction; + break; + } case game::TileType::Decoration: { - const game::DecorationTile* decoTile = dynamic_cast(tile.get()); - buffer << decoTile->color_palette_ref; - break; - } + const game::DecorationTile* decoTile = dynamic_cast(tile.get()); + buffer << decoTile->color_palette_ref; + break; + } default: break; @@ -58,23 +58,23 @@ static DataBuffer& operator>>(DataBuffer& buffer, game::TilePtr& tile) { buffer >> tileType; switch (tileType) { case game::TileType::Tower: { - auto tilePtr = std::make_shared(); - buffer >> tilePtr->color_palette_ref >> tilePtr->team_owner; - tile = tilePtr; - break; - } + auto tilePtr = std::make_shared(); + buffer >> tilePtr->color_palette_ref >> tilePtr->team_owner; + tile = tilePtr; + break; + } case game::TileType::Walk: { - auto tilePtr = std::make_shared(); - buffer >> tilePtr->direction; - tile = tilePtr; - break; - } + auto tilePtr = std::make_shared(); + buffer >> tilePtr->direction; + tile = tilePtr; + break; + } case game::TileType::Decoration: { - auto tilePtr = std::make_shared(); - buffer >> tilePtr->color_palette_ref; - tile = tilePtr; - break; - } + auto tilePtr = std::make_shared(); + buffer >> tilePtr->color_palette_ref; + tile = tilePtr; + break; + } default: break; } @@ -425,12 +425,12 @@ DataBuffer ServerTpsPacket::Serialize(bool packetID) const { DataBuffer data; WritePacketID(data, packetID); - data << m_TPS << m_PacketSendTime; + data << m_TPS << m_MSPT << m_PacketSendTime; return data; } void ServerTpsPacket::Deserialize(DataBuffer& data) { - data >> m_TPS >> m_PacketSendTime; + data >> m_TPS >> m_MSPT >> m_PacketSendTime; } DataBuffer SpawnMobPacket::Serialize(bool packetID) const { diff --git a/src/render/gui/GameMenu.cpp b/src/render/gui/GameMenu.cpp index 97e18ac..ba5943d 100644 --- a/src/render/gui/GameMenu.cpp +++ b/src/render/gui/GameMenu.cpp @@ -85,6 +85,7 @@ void GameMenu::ShowLobbyProgress() { void GameMenu::ShowTPS() { ImGui::Text("Server TPS : %.1f", GetClient()->GetConnexion().GetServerTPS()); + ImGui::Text("Server MSPT : %i", (int)GetClient()->GetConnexion().GetServerMSPT()); ImGui::Text("Server Ping : %i", GetClient()->GetConnexion().GetServerPing()); }