From 4f7f3edfced7285be6d91734a1730b8e3cedb389 Mon Sep 17 00:00:00 2001 From: Mordred Date: Mon, 20 Feb 2023 11:15:01 +0100 Subject: [PATCH] Put world server mainloop on a 300 ms tick --- src/world/WorldServer.cpp | 10 ++++++++-- src/world/WorldServer.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/world/WorldServer.cpp b/src/world/WorldServer.cpp index c0db83b7..0017a2fc 100644 --- a/src/world/WorldServer.cpp +++ b/src/world/WorldServer.cpp @@ -349,10 +349,16 @@ void WorldServer::mainLoop() while( isRunning() ) { - std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) ); + auto tickCount = Common::Util::getTimeMs(); + + if( tickCount - m_lastServerTick < 300 ) + { + std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) ); + continue; + } + m_lastServerTick = tickCount; auto currTime = Common::Util::getTimeSeconds(); - auto tickCount = Common::Util::getTimeMs(); taskMgr.update( tickCount ); terriMgr.updateTerritoryInstances( tickCount ); diff --git a/src/world/WorldServer.h b/src/world/WorldServer.h index 57ac36b2..90a30c15 100644 --- a/src/world/WorldServer.h +++ b/src/world/WorldServer.h @@ -74,6 +74,7 @@ namespace Sapphire::World uint16_t m_port; std::string m_ip; int64_t m_lastDBPingTime; + uint64_t m_lastServerTick{ 0 }; bool m_bRunning; uint16_t m_worldId;