summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-10-20 19:59:40 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-10-20 19:59:40 +0200
commitbde99d684e0bb51adaa053a240abe61cf4af07fb (patch)
treead1111d21ee606dd3cd60439189a92b1b51e2dea /src/World.cpp
parentMigrated random generators to std::random (diff)
downloadcuberite-bde99d684e0bb51adaa053a240abe61cf4af07fb.tar
cuberite-bde99d684e0bb51adaa053a240abe61cf4af07fb.tar.gz
cuberite-bde99d684e0bb51adaa053a240abe61cf4af07fb.tar.bz2
cuberite-bde99d684e0bb51adaa053a240abe61cf4af07fb.tar.lz
cuberite-bde99d684e0bb51adaa053a240abe61cf4af07fb.tar.xz
cuberite-bde99d684e0bb51adaa053a240abe61cf4af07fb.tar.zst
cuberite-bde99d684e0bb51adaa053a240abe61cf4af07fb.zip
Diffstat (limited to '')
-rw-r--r--src/World.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 56f0d6ce5..010fc0d87 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -11,7 +11,6 @@
#include "inifile/iniFile.h"
#include "ChunkMap.h"
#include "Generating/ChunkDesc.h"
-#include "OSSupport/Timer.h"
#include "SetChunkData.h"
// Serializers
@@ -109,7 +108,7 @@ protected:
// Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish
for (int i = 0; i < 20; i++)
{
- cSleep::MilliSleep(100);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (m_ShouldTerminate)
{
return;
@@ -159,7 +158,7 @@ protected:
// Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish
for (int i = 0; i < 20; i++)
{
- cSleep::MilliSleep(100);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (m_ShouldTerminate)
{
return;
@@ -167,8 +166,7 @@ protected:
}
} // for (-ever)
}
-
-} ;
+};
@@ -201,23 +199,20 @@ cWorld::cTickThread::cTickThread(cWorld & a_World) :
void cWorld::cTickThread::Execute(void)
{
- cTimer Timer;
-
- const Int64 msPerTick = 50;
- Int64 LastTime = Timer.GetNowTime();
+ auto LastTime = std::chrono::steady_clock::now();
+ static const auto msPerTick = std::chrono::milliseconds(50);
+ auto TickTime = std::chrono::steady_clock::duration(50);
- Int64 TickDuration = 50;
while (!m_ShouldTerminate)
{
- Int64 NowTime = Timer.GetNowTime();
- float DeltaTime = (float)(NowTime - LastTime);
- m_World.Tick(DeltaTime, (int)TickDuration);
- TickDuration = Timer.GetNowTime() - NowTime;
+ auto NowTime = std::chrono::steady_clock::now();
+ m_World.Tick(std::chrono::duration_cast<std::chrono::milliseconds>(NowTime - LastTime).count(), std::chrono::duration_cast<std::chrono::duration<int>>(TickTime).count());
+ TickTime = std::chrono::steady_clock::now() - NowTime;
- if (TickDuration < msPerTick)
+ if (TickTime < msPerTick)
{
// Stretch tick time until it's at least msPerTick
- cSleep::MilliSleep((unsigned int)(msPerTick - TickDuration));
+ std::this_thread::sleep_for(msPerTick -TickTime);
}
LastTime = NowTime;