summaryrefslogtreecommitdiffstats
path: root/src/Server.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/Server.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 'src/Server.cpp')
-rw-r--r--src/Server.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/Server.cpp b/src/Server.cpp
index c5f4f9042..f29683b21 100644
--- a/src/Server.cpp
+++ b/src/Server.cpp
@@ -4,7 +4,6 @@
#include "Server.h"
#include "ClientHandle.h"
-#include "OSSupport/Timer.h"
#include "Mobs/Monster.h"
#include "OSSupport/Socket.h"
#include "Root.h"
@@ -73,22 +72,19 @@ cServer::cTickThread::cTickThread(cServer & a_Server) :
void cServer::cTickThread::Execute(void)
{
- cTimer Timer;
-
- long long msPerTick = 50;
- long long LastTime = Timer.GetNowTime();
+ auto LastTime = std::chrono::steady_clock::now();
+ static const auto msPerTick = std::chrono::milliseconds(50);
while (!m_ShouldTerminate)
{
- long long NowTime = Timer.GetNowTime();
- float DeltaTime = (float)(NowTime-LastTime);
- m_ShouldTerminate = !m_Server.Tick(DeltaTime);
- long long TickTime = Timer.GetNowTime() - NowTime;
+ auto NowTime = std::chrono::steady_clock::now();
+ m_ShouldTerminate = !m_Server.Tick(std::chrono::duration_cast<std::chrono::milliseconds>(NowTime - LastTime).count());
+ auto TickTime = std::chrono::steady_clock::now() - NowTime;
if (TickTime < msPerTick)
{
// Stretch tick time until it's at least msPerTick
- cSleep::MilliSleep((unsigned int)(msPerTick - TickTime));
+ std::this_thread::sleep_for(msPerTick -TickTime);
}
LastTime = NowTime;