aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2022-01-03 11:26:23 +0100
committerShauren <shauren.trinity@gmail.com>2022-01-03 16:19:29 +0100
commit32cef906b02562ffb129b095386a9314abde82f1 (patch)
tree8202a2af277d34365d6980a058180075e4802a9f /src
parent27cb415c13aeda8c1aa16c207b414184ab2ad700 (diff)
Core/Time: Remove artificially high minimal update intervals
(cherry picked from commit 3a67e376811743be208da4aab8a9e452e1ae637e)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Grids/GridDefines.h2
-rw-r--r--src/server/game/World/World.cpp2
-rw-r--r--src/server/shared/Networking/NetworkThread.h8
-rw-r--r--src/server/worldserver/Main.cpp55
-rw-r--r--src/server/worldserver/worldserver.conf.dist4
5 files changed, 56 insertions, 15 deletions
diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h
index fe70ab47019..a709cc586e8 100644
--- a/src/server/game/Grids/GridDefines.h
+++ b/src/server/game/Grids/GridDefines.h
@@ -41,7 +41,7 @@ class Player;
#define CENTER_GRID_OFFSET (SIZE_OF_GRIDS/2)
#define MIN_GRID_DELAY (MINUTE*IN_MILLISECONDS)
-#define MIN_MAP_UPDATE_DELAY 50
+#define MIN_MAP_UPDATE_DELAY 1
#define SIZE_OF_GRID_CELL (SIZE_OF_GRIDS/MAX_NUMBER_OF_CELLS)
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index 0c6b5cff6d9..2d8882dcaec 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -717,7 +717,7 @@ void World::LoadConfigSettings(bool reload)
if (reload)
sMapMgr->SetGridCleanUpDelay(m_int_configs[CONFIG_INTERVAL_GRIDCLEAN]);
- m_int_configs[CONFIG_INTERVAL_MAPUPDATE] = sConfigMgr->GetIntDefault("MapUpdateInterval", 100);
+ m_int_configs[CONFIG_INTERVAL_MAPUPDATE] = sConfigMgr->GetIntDefault("MapUpdateInterval", 10);
if (m_int_configs[CONFIG_INTERVAL_MAPUPDATE] < MIN_MAP_UPDATE_DELAY)
{
TC_LOG_ERROR("server.loading", "MapUpdateInterval (%i) must be greater %u. Use this minimal value.", m_int_configs[CONFIG_INTERVAL_MAPUPDATE], MIN_MAP_UPDATE_DELAY);
diff --git a/src/server/shared/Networking/NetworkThread.h b/src/server/shared/Networking/NetworkThread.h
index 7e0703ecb19..5f9071af656 100644
--- a/src/server/shared/Networking/NetworkThread.h
+++ b/src/server/shared/Networking/NetworkThread.h
@@ -122,8 +122,8 @@ protected:
{
TC_LOG_DEBUG("misc", "Network Thread Starting");
- _updateTimer.expires_from_now(boost::posix_time::milliseconds(10));
- _updateTimer.async_wait(std::bind(&NetworkThread<SocketType>::Update, this));
+ _updateTimer.expires_from_now(boost::posix_time::milliseconds(1));
+ _updateTimer.async_wait([this](boost::system::error_code const&) { Update(); });
_ioContext.run();
TC_LOG_DEBUG("misc", "Network Thread exits");
@@ -136,8 +136,8 @@ protected:
if (_stopped)
return;
- _updateTimer.expires_from_now(boost::posix_time::milliseconds(10));
- _updateTimer.async_wait(std::bind(&NetworkThread<SocketType>::Update, this));
+ _updateTimer.expires_from_now(boost::posix_time::milliseconds(1));
+ _updateTimer.async_wait([this](boost::system::error_code const&) { Update(); });
AddNewSockets();
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp
index 418b5de5eb1..888b0ad65d4 100644
--- a/src/server/worldserver/Main.cpp
+++ b/src/server/worldserver/Main.cpp
@@ -67,7 +67,7 @@ namespace fs = boost::filesystem;
#define _TRINITY_CORE_CONFIG "worldserver.conf"
#endif
-#define WORLD_SLEEP_CONST 50
+#define WORLD_SLEEP_CONST 1
#ifdef _WIN32
#include "ServiceWin32.h"
@@ -81,6 +81,9 @@ char serviceDescription[] = "TrinityCore World of Warcraft emulator world servic
* 2 - paused
*/
int m_ServiceStatus = -1;
+
+#include <boost/dll/shared_library.hpp>
+#include <timeapi.h>
#endif
class FreezeDetector
@@ -135,6 +138,44 @@ extern int main(int argc, char** argv)
return WinServiceUninstall() == true ? 0 : 1;
else if (configService.compare("run") == 0)
WinServiceRun();
+
+ Optional<UINT> newTimerResolution;
+ boost::system::error_code dllError;
+ std::shared_ptr<boost::dll::shared_library> winmm(new boost::dll::shared_library("winmm.dll", dllError, boost::dll::load_mode::search_system_folders), [&](boost::dll::shared_library* lib)
+ {
+ try
+ {
+ if (newTimerResolution)
+ lib->get<decltype(timeEndPeriod)>("timeEndPeriod")(*newTimerResolution);
+ }
+ catch (std::exception const&)
+ {
+ // ignore
+ }
+
+ delete lib;
+ });
+
+ if (winmm->is_loaded())
+ {
+ try
+ {
+ auto timeGetDevCapsPtr = winmm->get<decltype(timeGetDevCaps)>("timeGetDevCaps");
+ // setup timer resolution
+ TIMECAPS timeResolutionLimits;
+ if (timeGetDevCapsPtr(&timeResolutionLimits, sizeof(TIMECAPS)) == TIMERR_NOERROR)
+ {
+ auto timeBeginPeriodPtr = winmm->get<decltype(timeBeginPeriod)>("timeBeginPeriod");
+ newTimerResolution = std::min(std::max(timeResolutionLimits.wPeriodMin, 1u), timeResolutionLimits.wPeriodMax);
+ timeBeginPeriodPtr(*newTimerResolution);
+ }
+ }
+ catch (std::exception const& e)
+ {
+ printf("Failed to initialize timer resolution: %s\n", e.what());
+ }
+ }
+
#endif
std::string configError;
@@ -445,16 +486,16 @@ void WorldUpdateLoop()
realCurrTime = getMSTime();
uint32 diff = getMSTimeDiff(realPrevTime, realCurrTime);
+ if (!diff)
+ {
+ // sleep until enough time passes that we can update all timers
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ continue;
+ }
sWorld->Update(diff);
realPrevTime = realCurrTime;
- uint32 executionTimeDiff = getMSTimeDiff(realCurrTime, getMSTime());
-
- // we know exactly how long it took to update the world, if the update took less than WORLD_SLEEP_CONST, sleep for WORLD_SLEEP_CONST - world update time
- if (executionTimeDiff < WORLD_SLEEP_CONST)
- std::this_thread::sleep_for(std::chrono::milliseconds(WORLD_SLEEP_CONST - executionTimeDiff));
-
#ifdef _WIN32
if (m_ServiceStatus == 0)
World::StopNow(SHUTDOWN_EXIT_CODE);
diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist
index 2f11d3e7c5d..f475d0248e8 100644
--- a/src/server/worldserver/worldserver.conf.dist
+++ b/src/server/worldserver/worldserver.conf.dist
@@ -337,9 +337,9 @@ GridCleanUpDelay = 300000
#
# MapUpdateInterval
# Description: Time (milliseconds) for map update interval.
-# Default: 100 - (0.1 second)
+# Default: 10 - (0.01 second)
-MapUpdateInterval = 100
+MapUpdateInterval = 10
#
# ChangeWeatherInterval