Refactor engine loop to have better sync between game update, physics and drawing
This commit is contained in:
@@ -72,10 +72,9 @@ void Time::TickData::OnReset(float targetFps, double currentTime)
|
||||
LastEnd = currentTime;
|
||||
}
|
||||
|
||||
bool Time::TickData::OnTickBegin(float targetFps, float maxDeltaTime)
|
||||
bool Time::TickData::OnTickBegin(double time, float targetFps, float maxDeltaTime)
|
||||
{
|
||||
// Check if can perform a tick
|
||||
const double time = Platform::GetTimeSeconds();
|
||||
double deltaTime;
|
||||
if (FixedDeltaTimeEnable)
|
||||
{
|
||||
@@ -126,10 +125,9 @@ void Time::TickData::Advance(double time, double deltaTime)
|
||||
TicksCount++;
|
||||
}
|
||||
|
||||
bool Time::FixedStepTickData::OnTickBegin(float targetFps, float maxDeltaTime)
|
||||
bool Time::FixedStepTickData::OnTickBegin(double time, float targetFps, float maxDeltaTime)
|
||||
{
|
||||
// Check if can perform a tick
|
||||
double time = Platform::GetTimeSeconds();
|
||||
double deltaTime, minDeltaTime;
|
||||
if (FixedDeltaTimeEnable)
|
||||
{
|
||||
@@ -249,9 +247,9 @@ void Time::Synchronize()
|
||||
Draw.Synchronize(DrawFPS, time);
|
||||
}
|
||||
|
||||
bool Time::OnBeginUpdate()
|
||||
bool Time::OnBeginUpdate(double time)
|
||||
{
|
||||
if (Update.OnTickBegin(UpdateFPS, MaxUpdateDeltaTime))
|
||||
if (Update.OnTickBegin(time, UpdateFPS, MaxUpdateDeltaTime))
|
||||
{
|
||||
Current = &Update;
|
||||
return true;
|
||||
@@ -259,9 +257,9 @@ bool Time::OnBeginUpdate()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Time::OnBeginPhysics()
|
||||
bool Time::OnBeginPhysics(double time)
|
||||
{
|
||||
if (Physics.OnTickBegin(PhysicsFPS, _physicsMaxDeltaTime))
|
||||
if (Physics.OnTickBegin(time, PhysicsFPS, _physicsMaxDeltaTime))
|
||||
{
|
||||
Current = &Physics;
|
||||
return true;
|
||||
@@ -269,9 +267,9 @@ bool Time::OnBeginPhysics()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Time::OnBeginDraw()
|
||||
bool Time::OnBeginDraw(double time)
|
||||
{
|
||||
if (Draw.OnTickBegin(DrawFPS, 1.0f))
|
||||
if (Draw.OnTickBegin(time, DrawFPS, 1.0f))
|
||||
{
|
||||
Current = &Draw;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user