mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-05-22 18:54:33 +00:00
73 lines
1.6 KiB
C++
73 lines
1.6 KiB
C++
#include "stdafx.h"
|
|
#include "Timer.h"
|
|
#include "..\Minecraft.World\System.h"
|
|
|
|
Timer::Timer(float ticksPerSecond)
|
|
{
|
|
// 4J - added initialisers
|
|
lastTime = 0;
|
|
ticks = 0;
|
|
a = 0;
|
|
timeScale = 1;
|
|
passedTime = 0;
|
|
accumMs = 0;
|
|
adjustTime = 1.0;
|
|
|
|
this->ticksPerSecond = ticksPerSecond;
|
|
lastMs = System::currentTimeMillis();
|
|
lastMsSysTime = System::nanoTime() / 1000000;
|
|
}
|
|
|
|
void Timer::advanceTime()
|
|
{
|
|
int64_t nowNano = System::nanoTime();
|
|
double nowSeconds = nowNano / 1000000000.0;
|
|
|
|
static double lastFrameTime = nowSeconds;
|
|
double elapsedSeconds = nowSeconds - lastFrameTime;
|
|
lastFrameTime = nowSeconds;
|
|
|
|
if (elapsedSeconds < 0) elapsedSeconds = 0;
|
|
if (elapsedSeconds > 1.0) elapsedSeconds = 1.0;
|
|
|
|
double frameDelta = elapsedSeconds * timeScale * ticksPerSecond;
|
|
|
|
passedTime += static_cast<float>(frameDelta);
|
|
|
|
ticks = static_cast<int>(passedTime);
|
|
passedTime -= ticks;
|
|
|
|
if (ticks > MAX_TICKS_PER_UPDATE)
|
|
ticks = MAX_TICKS_PER_UPDATE;
|
|
|
|
a = passedTime;
|
|
}
|
|
|
|
void Timer::advanceTimeQuickly()
|
|
{
|
|
passedTime += static_cast<float>(MAX_TICKS_PER_UPDATE) * timeScale;
|
|
|
|
ticks = static_cast<int>(passedTime);
|
|
passedTime -= ticks;
|
|
|
|
a = 0.0f;
|
|
|
|
lastMs = System::currentTimeMillis();
|
|
|
|
lastMsSysTime = System::nanoTime() / 1000000;
|
|
}
|
|
|
|
void Timer::skipTime()
|
|
{
|
|
int64_t nowNano = System::nanoTime();
|
|
double nowSeconds = nowNano / 1000000000.0;
|
|
|
|
lastMs = System::currentTimeMillis();
|
|
lastMsSysTime = nowNano / 1000000;
|
|
lastTime = nowSeconds;
|
|
|
|
ticks = 0;
|
|
passedTime = 0.0f;
|
|
|
|
a = 0.0f;
|
|
} |