1
0

Added the real tick duration to the OnWorldTick hook.

This commit is contained in:
madmaxoft
2013-11-30 14:22:26 +01:00
parent 463de118a0
commit 2383016b1d
8 changed files with 34 additions and 17 deletions

View File

@@ -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;