diff options
Diffstat (limited to 'src/server/worldserver/Main.cpp')
-rw-r--r-- | src/server/worldserver/Main.cpp | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 0241221a2ac..3ac0d88e3f9 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -396,8 +396,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()) { @@ -409,18 +407,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) |