Add Time.Synchronize to stabilize engine loop
This commit is contained in:
@@ -163,6 +163,8 @@ namespace FlaxEditor.States
|
||||
Editor.OnPlayBegin();
|
||||
IsPlayModeStarting = false;
|
||||
Profiler.EndEvent();
|
||||
|
||||
Time.Synchronize();
|
||||
}
|
||||
|
||||
private void SetupEditorEnvOptions()
|
||||
@@ -209,6 +211,8 @@ namespace FlaxEditor.States
|
||||
Editor.OnPlayEnd();
|
||||
IsPlayModeEnding = false;
|
||||
Profiler.EndEvent();
|
||||
|
||||
Time.Synchronize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ int32 Engine::Main(const Char* cmdLine)
|
||||
#endif
|
||||
Log::Logger::WriteFloor();
|
||||
LOG_FLUSH();
|
||||
Time::OnBeforeRun();
|
||||
Time::Synchronize();
|
||||
EngineImpl::IsReady = true;
|
||||
|
||||
// Main engine loop
|
||||
@@ -465,7 +465,7 @@ void Engine::OnUnpause()
|
||||
LOG(Info, "App unpaused");
|
||||
Unpause();
|
||||
|
||||
Time::OnBeforeRun();
|
||||
Time::Synchronize();
|
||||
}
|
||||
|
||||
void Engine::OnExit()
|
||||
|
||||
@@ -54,7 +54,7 @@ void TimeSettings::Apply()
|
||||
::MaxUpdateDeltaTime = MaxUpdateDeltaTime;
|
||||
}
|
||||
|
||||
void Time::TickData::OnBeforeRun(float targetFps, double currentTime)
|
||||
void Time::TickData::Synchronize(float targetFps, double currentTime)
|
||||
{
|
||||
Time = UnscaledTime = TimeSpan::Zero();
|
||||
DeltaTime = UnscaledDeltaTime = targetFps > ZeroTolerance ? TimeSpan::FromSeconds(1.0f / targetFps) : TimeSpan::Zero();
|
||||
@@ -240,13 +240,13 @@ void Time::SetFixedDeltaTime(bool enable, float value)
|
||||
FixedDeltaTimeValue = value;
|
||||
}
|
||||
|
||||
void Time::OnBeforeRun()
|
||||
void Time::Synchronize()
|
||||
{
|
||||
// Initialize tick data (based on a time settings)
|
||||
const double time = Platform::GetTimeSeconds();
|
||||
Update.OnBeforeRun(UpdateFPS, time);
|
||||
Physics.OnBeforeRun(PhysicsFPS, time);
|
||||
Draw.OnBeforeRun(DrawFPS, time);
|
||||
Update.Synchronize(UpdateFPS, time);
|
||||
Physics.Synchronize(PhysicsFPS, time);
|
||||
Draw.Synchronize(DrawFPS, time);
|
||||
}
|
||||
|
||||
bool Time::OnBeginUpdate()
|
||||
|
||||
@@ -225,12 +225,14 @@ public:
|
||||
/// <param name="value">The fixed draw/update rate for the time.</param>
|
||||
API_FUNCTION() static void SetFixedDeltaTime(bool enable, float value);
|
||||
|
||||
/// <summary>
|
||||
/// Synchronizes update, fixed update and draw. Resets any pending deltas for fresh ticking in sync.
|
||||
/// </summary>
|
||||
API_FUNCTION() static void Synchronize();
|
||||
|
||||
private:
|
||||
|
||||
// Methods used by the Engine class
|
||||
|
||||
static void OnBeforeRun();
|
||||
|
||||
static bool OnBeginUpdate();
|
||||
static bool OnBeginPhysics();
|
||||
static bool OnBeginDraw();
|
||||
|
||||
Reference in New Issue
Block a user