Refactor engine loop to have better sync between game update, physics and drawing

This commit is contained in:
Wojtek Figat
2024-04-17 13:38:06 +02:00
parent e53ab10145
commit 9f983cff49
4 changed files with 28 additions and 37 deletions

View File

@@ -192,8 +192,11 @@ int32 Engine::Main(const Char* cmdLine)
OnUnpause();
}
// Use the same time for all ticks to improve synchronization
const double time = Platform::GetTimeSeconds();
// Update game logic
if (Time::OnBeginUpdate())
if (Time::OnBeginUpdate(time))
{
OnUpdate();
OnLateUpdate();
@@ -201,7 +204,7 @@ int32 Engine::Main(const Char* cmdLine)
}
// Start physics simulation
if (Time::OnBeginPhysics())
if (Time::OnBeginPhysics(time))
{
OnFixedUpdate();
OnLateFixedUpdate();
@@ -209,7 +212,7 @@ int32 Engine::Main(const Char* cmdLine)
}
// Draw frame
if (Time::OnBeginDraw())
if (Time::OnBeginDraw(time))
{
OnDraw();
Time::OnEndDraw();