diff options
author | xinef1 <w.szyszko2@gmail.com> | 2016-12-31 20:50:39 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2016-12-31 20:50:39 +0100 |
commit | 48f30911b9e09e45ed4426d41c4284141037bcc6 (patch) | |
tree | 501da9106eb7ea49fca27a9cb64f5bb36c013bad /src/server/worldserver/Main.cpp | |
parent | bed369e7c8d0ef848f710bac9b8ceacc3cbe38a2 (diff) |
Core/World: Simplified sleep calculation routine for world update thread (#18634)
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) |