add server mspt (+procotol format)

This commit is contained in:
2023-01-02 15:07:34 +01:00
parent 5a547b6514
commit 512fb23d0e
7 changed files with 43 additions and 32 deletions

View File

@@ -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();
}

View File

@@ -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);
}
}