summaryrefslogtreecommitdiffstats
path: root/source/cServer.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-22 21:15:11 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-22 21:15:11 +0100
commit738b1b3467e5556667464bc33294a7485d37097b (patch)
tree0f42294589a7574e391644609e315694b194639f /source/cServer.cpp
parentBug FS#131 http://www.mc-server.org/support/index.php?do=details&task_id=131 should be fixed (diff)
downloadcuberite-738b1b3467e5556667464bc33294a7485d37097b.tar
cuberite-738b1b3467e5556667464bc33294a7485d37097b.tar.gz
cuberite-738b1b3467e5556667464bc33294a7485d37097b.tar.bz2
cuberite-738b1b3467e5556667464bc33294a7485d37097b.tar.lz
cuberite-738b1b3467e5556667464bc33294a7485d37097b.tar.xz
cuberite-738b1b3467e5556667464bc33294a7485d37097b.tar.zst
cuberite-738b1b3467e5556667464bc33294a7485d37097b.zip
Diffstat (limited to 'source/cServer.cpp')
-rw-r--r--source/cServer.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/source/cServer.cpp b/source/cServer.cpp
index 8d4f9ea16..326bbf9ce 100644
--- a/source/cServer.cpp
+++ b/source/cServer.cpp
@@ -278,11 +278,9 @@ void cServer::StartListenClient()
bool cServer::Tick(float a_Dt)
{
- //LOG("1. Tick");
+ //LOG("1. Tick %0.2f", a_Dt);
if( a_Dt > 100.f ) a_Dt = 100.f; // Don't go over 1/10 second
- cSleep::MilliSleep( 50 ); // Don't tick too much
-
m_Millisecondsf += a_Dt;
if( m_Millisecondsf > 1.f )
{
@@ -331,6 +329,7 @@ void ServerTickThread( void * a_Param )
cTimer Timer;
+ long long msPerTick = 50; // TODO - Put this in server config file
long long LastTime = Timer.GetNowTime();
bool bKeepGoing = true;
@@ -339,6 +338,13 @@ void ServerTickThread( void * a_Param )
long long NowTime = Timer.GetNowTime();
float DeltaTime = (float)(NowTime-LastTime);
bKeepGoing = CServerObj->Tick( DeltaTime );
+ long long TickTime = Timer.GetNowTime() - NowTime;
+
+ if( TickTime < msPerTick ) // Stretch tick time until it's at least msPerTick
+ {
+ cSleep::MilliSleep( (unsigned int)( msPerTick - TickTime ) );
+ }
+
LastTime = NowTime;
}