aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxinef1 <w.szyszko2@gmail.com>2016-12-31 20:50:39 +0100
committerDoctorKraft <DoctorKraft@users.noreply.github.com>2018-03-18 00:19:48 +0100
commit608260b853167849626004a10fd9c49714824813 (patch)
treec82c844f5d5f09d5f290a2464a0b9267561dabb6
parentbec131eac3af0efb83c8140730ad97890d68033a (diff)
Core/World: Simplified sleep calculation routine for world update thread (#18634)
(cherry picked from commit 48f30911b9e09e45ed4426d41c4284141037bcc6)
-rw-r--r--src/server/worldserver/Main.cpp17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp
index 46e06109b09..508049a425b 100644
--- a/src/server/worldserver/Main.cpp
+++ b/src/server/worldserver/Main.cpp
@@ -431,8 +431,6 @@ void WorldUpdateLoop()
uint32 realCurrTime = 0;
uint32 realPrevTime = getMSTime();
- uint32 prevSleepTime = 0; // used for balanced full tick time length near WORLD_SLEEP_CONST
-
///- While we have not World::m_stopEvent, update the world
while (!World::IsStopped())
{
@@ -444,18 +442,11 @@ void WorldUpdateLoop()
sWorld->Update(diff);
realPrevTime = realCurrTime;
- // diff (D0) include time of previous sleep (d0) + tick time (t0)
- // we want that next d1 + t1 == WORLD_SLEEP_CONST
- // we can't know next t1 and then can use (t0 + d1) == WORLD_SLEEP_CONST requirement
- // d1 = WORLD_SLEEP_CONST - t0 = WORLD_SLEEP_CONST - (D0 - d0) = WORLD_SLEEP_CONST + d0 - D0
- if (diff <= WORLD_SLEEP_CONST + prevSleepTime)
- {
- prevSleepTime = WORLD_SLEEP_CONST + prevSleepTime - diff;
+ uint32 executionTimeDiff = getMSTimeDiff(realCurrTime, getMSTime());
- std::this_thread::sleep_for(std::chrono::milliseconds(prevSleepTime));
- }
- else
- prevSleepTime = 0;
+ // 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)