From 2383016b1d673fcf0ad69a08bba62d7ce36cdd76 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 30 Nov 2013 14:22:26 +0100 Subject: Added the real tick duration to the OnWorldTick hook. --- src/World.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 8ef4dc0f3..03efbdf32 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -197,20 +197,21 @@ void cWorld::cTickThread::Execute(void) { cTimer Timer; - long long msPerTick = 50; - long long LastTime = Timer.GetNowTime(); + const Int64 msPerTick = 50; + Int64 LastTime = Timer.GetNowTime(); + Int64 TickDuration = 50; while (!m_ShouldTerminate) { - long long NowTime = Timer.GetNowTime(); + Int64 NowTime = Timer.GetNowTime(); float DeltaTime = (float)(NowTime - LastTime); - m_World.Tick(DeltaTime); - long long TickTime = Timer.GetNowTime() - NowTime; + m_World.Tick(DeltaTime, (int)TickDuration); + TickDuration = Timer.GetNowTime() - NowTime; - if (TickTime < msPerTick) + if (TickDuration < msPerTick) { // Stretch tick time until it's at least msPerTick - cSleep::MilliSleep((unsigned int)(msPerTick - TickTime)); + cSleep::MilliSleep((unsigned int)(msPerTick - TickDuration)); } LastTime = NowTime; @@ -660,10 +661,10 @@ void cWorld::Stop(void) -void cWorld::Tick(float a_Dt) +void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec) { // Call the plugins - cPluginManager::Get()->CallHookWorldTick(*this, a_Dt); + cPluginManager::Get()->CallHookWorldTick(*this, a_Dt, a_LastTickDurationMSec); // We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it m_WorldAgeSecs += (double)a_Dt / 1000.0; -- cgit v1.2.3