Fixed WorldTickThread reporting wrong time durations for each tick.
This had caused food eating to fail and players unable to collect pickups on Linux.
This commit is contained in:
parent
8289ac8ba7
commit
fdbe835131
@ -75,7 +75,7 @@ void cServer::cTickThread::Execute(void)
|
|||||||
{
|
{
|
||||||
cTimer Timer;
|
cTimer Timer;
|
||||||
|
|
||||||
long long msPerTick = 50; // TODO - Put this in server config file
|
long long msPerTick = 50;
|
||||||
long long LastTime = Timer.GetNowTime();
|
long long LastTime = Timer.GetNowTime();
|
||||||
|
|
||||||
while (!m_ShouldTerminate)
|
while (!m_ShouldTerminate)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "Root.h"
|
#include "Root.h"
|
||||||
#include "../iniFile/iniFile.h"
|
#include "../iniFile/iniFile.h"
|
||||||
#include "ChunkMap.h"
|
#include "ChunkMap.h"
|
||||||
|
#include "OSSupport/Timer.h"
|
||||||
|
|
||||||
// Simulators:
|
// Simulators:
|
||||||
#include "Simulator/SimulatorManager.h"
|
#include "Simulator/SimulatorManager.h"
|
||||||
@ -206,18 +207,25 @@ cWorld::cTickThread::cTickThread(cWorld & a_World) :
|
|||||||
|
|
||||||
void cWorld::cTickThread::Execute(void)
|
void cWorld::cTickThread::Execute(void)
|
||||||
{
|
{
|
||||||
const int ClocksPerTick = CLOCKS_PER_SEC / 20;
|
cTimer Timer;
|
||||||
clock_t LastTime = clock();
|
|
||||||
|
long long msPerTick = 50;
|
||||||
|
long long LastTime = Timer.GetNowTime();
|
||||||
|
|
||||||
while (!m_ShouldTerminate)
|
while (!m_ShouldTerminate)
|
||||||
{
|
{
|
||||||
clock_t Start = clock();
|
long long NowTime = Timer.GetNowTime();
|
||||||
m_World.Tick((float)(1000 * (Start - LastTime)) / CLOCKS_PER_SEC);
|
float DeltaTime = (float)(NowTime - LastTime);
|
||||||
clock_t Now = clock();
|
m_World.Tick(DeltaTime);
|
||||||
if (Now - Start < ClocksPerTick)
|
long long TickTime = Timer.GetNowTime() - NowTime;
|
||||||
|
|
||||||
|
if (TickTime < msPerTick)
|
||||||
{
|
{
|
||||||
cSleep::MilliSleep(1000 * (ClocksPerTick - (Now - Start)) / CLOCKS_PER_SEC);
|
// Stretch tick time until it's at least msPerTick
|
||||||
|
cSleep::MilliSleep((unsigned int)(msPerTick - TickTime));
|
||||||
}
|
}
|
||||||
LastTime = Start;
|
|
||||||
|
LastTime = NowTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user