Core/World: Simplified sleep calculation routine for world update thread (#18634)

This commit is contained in:
xinef1
2016-12-31 20:50:39 +01:00
committed by Aokromes
parent eed28a5be9
commit ae56332789

View File

@@ -394,8 +394,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())
{
@@ -407,18 +405,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)