From 338a861cd9d25a1971610c1099f33657159a8c9c Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 22 Feb 2022 13:54:46 -0500 Subject: [PATCH] Core/Time: Remove artificially high minimal update intervals Port From (https://github.com/TrinityCore/TrinityCore/commit/3a67e376811743be208da4aab8a9e452e1ae637e) --- Source/Framework/Constants/MapConst.cs | 2 +- Source/Framework/Networking/NetworkThread.cs | 4 ++-- Source/Game/Server/WorldConfig.cs | 2 +- Source/WorldServer/Server.cs | 15 ++++++++------- Source/WorldServer/WorldServer.conf.dist | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Source/Framework/Constants/MapConst.cs b/Source/Framework/Constants/MapConst.cs index c78f5a6f7..73e8759c9 100644 --- a/Source/Framework/Constants/MapConst.cs +++ b/Source/Framework/Constants/MapConst.cs @@ -47,7 +47,7 @@ namespace Framework.Constants //Liquid public const float LiquidTileSize = (533.333f / 128.0f); - public const int MinMapUpdateDelay = 50; + public const int MinMapUpdateDelay = 1; public const int MinGridDelay = (Time.Minute * Time.InMilliseconds); public const int MapResolution = 128; diff --git a/Source/Framework/Networking/NetworkThread.cs b/Source/Framework/Networking/NetworkThread.cs index 29cf20b1d..ebc405ddf 100644 --- a/Source/Framework/Networking/NetworkThread.cs +++ b/Source/Framework/Networking/NetworkThread.cs @@ -91,7 +91,7 @@ namespace Framework.Networking { Log.outDebug(LogFilter.Network, "Network Thread Starting"); - int sleepTime = 10; + int sleepTime = 1; while (!_stopped) { Thread.Sleep(sleepTime); @@ -116,7 +116,7 @@ namespace Framework.Networking } uint diff = Time.GetMSTimeDiffToNow(tickStart); - sleepTime = (int)(diff > 10 ? 0 : 10 - diff); + sleepTime = (int)(diff > 1 ? 0 : 1 - diff); } Log.outDebug(LogFilter.Misc, "Network Thread exits"); diff --git a/Source/Game/Server/WorldConfig.cs b/Source/Game/Server/WorldConfig.cs index 259b76504..f6747c2b5 100644 --- a/Source/Game/Server/WorldConfig.cs +++ b/Source/Game/Server/WorldConfig.cs @@ -257,7 +257,7 @@ namespace Game Values[WorldCfg.IntervalGridclean] = MapConst.MinGridDelay; } - Values[WorldCfg.IntervalMapupdate] = GetDefaultValue("MapUpdateInterval", 100); + Values[WorldCfg.IntervalMapupdate] = GetDefaultValue("MapUpdateInterval", 10); if ((int)Values[WorldCfg.IntervalMapupdate] < MapConst.MinMapUpdateDelay) { Log.outError(LogFilter.ServerLoading, "MapUpdateInterval ({0}) must be greater {1}. Use this minimal value.", Values[WorldCfg.IntervalMapupdate], MapConst.MinMapUpdateDelay); diff --git a/Source/WorldServer/Server.cs b/Source/WorldServer/Server.cs index 1b4bbbbed..5f229730c 100644 --- a/Source/WorldServer/Server.cs +++ b/Source/WorldServer/Server.cs @@ -31,7 +31,7 @@ namespace WorldServer { public class Server { - const uint WorldSleep = 50; + const uint WorldSleep = 1; static void Main() { @@ -189,14 +189,15 @@ namespace WorldServer var realCurrTime = Time.GetMSTime(); uint diff = Time.GetMSTimeDiff(realPrevTime, realCurrTime); + if (diff == 0) + { + // sleep until enough time passes that we can update all timers + Thread.Sleep(1); + continue; + } + Global.WorldMgr.Update(diff); realPrevTime = realCurrTime; - - uint executionTimeDiff = Time.GetMSTimeDiffToNow(realCurrTime); - - // 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 < WorldSleep) - Thread.Sleep((int)(WorldSleep - executionTimeDiff)); } } diff --git a/Source/WorldServer/WorldServer.conf.dist b/Source/WorldServer/WorldServer.conf.dist index 10e5d1b1f..d2f0dfe88 100644 --- a/Source/WorldServer/WorldServer.conf.dist +++ b/Source/WorldServer/WorldServer.conf.dist @@ -334,9 +334,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