summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-19 22:23:25 +0200
committermadmaxoft <github@xoft.cz>2013-08-19 22:23:25 +0200
commitfdbe835131059579b429cbcc3cd4d06c3bed512e (patch)
tree011d6b186f73cdc3a24e02502041cce417502e5c /source
parentAdded a "Debug profiled" MSVC configuration. (diff)
downloadcuberite-fdbe835131059579b429cbcc3cd4d06c3bed512e.tar
cuberite-fdbe835131059579b429cbcc3cd4d06c3bed512e.tar.gz
cuberite-fdbe835131059579b429cbcc3cd4d06c3bed512e.tar.bz2
cuberite-fdbe835131059579b429cbcc3cd4d06c3bed512e.tar.lz
cuberite-fdbe835131059579b429cbcc3cd4d06c3bed512e.tar.xz
cuberite-fdbe835131059579b429cbcc3cd4d06c3bed512e.tar.zst
cuberite-fdbe835131059579b429cbcc3cd4d06c3bed512e.zip
Diffstat (limited to '')
-rw-r--r--source/Server.cpp2
-rw-r--r--source/World.cpp24
2 files changed, 17 insertions, 9 deletions
diff --git a/source/Server.cpp b/source/Server.cpp
index 9c1e06c81..dd18f8d3d 100644
--- a/source/Server.cpp
+++ b/source/Server.cpp
@@ -75,7 +75,7 @@ void cServer::cTickThread::Execute(void)
{
cTimer Timer;
- long long msPerTick = 50; // TODO - Put this in server config file
+ long long msPerTick = 50;
long long LastTime = Timer.GetNowTime();
while (!m_ShouldTerminate)
diff --git a/source/World.cpp b/source/World.cpp
index 8f9b3924f..053eaedc7 100644
--- a/source/World.cpp
+++ b/source/World.cpp
@@ -12,6 +12,7 @@
#include "Root.h"
#include "../iniFile/iniFile.h"
#include "ChunkMap.h"
+#include "OSSupport/Timer.h"
// Simulators:
#include "Simulator/SimulatorManager.h"
@@ -206,18 +207,25 @@ cWorld::cTickThread::cTickThread(cWorld & a_World) :
void cWorld::cTickThread::Execute(void)
{
- const int ClocksPerTick = CLOCKS_PER_SEC / 20;
- clock_t LastTime = clock();
+ cTimer Timer;
+
+ long long msPerTick = 50;
+ long long LastTime = Timer.GetNowTime();
+
while (!m_ShouldTerminate)
{
- clock_t Start = clock();
- m_World.Tick((float)(1000 * (Start - LastTime)) / CLOCKS_PER_SEC);
- clock_t Now = clock();
- if (Now - Start < ClocksPerTick)
+ long long NowTime = Timer.GetNowTime();
+ float DeltaTime = (float)(NowTime - LastTime);
+ m_World.Tick(DeltaTime);
+ 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;
}
}