The following code is part of my game loop (Dewitters Game Loop).
// Calculate the elapsed time.
const double delta_time = m_timer->GetDeltaTime();
// Perform the fixed delta time updates of the current scene.
if (m_fixed_delta_time) {
fixed_time_budget += delta_time;
while (fixed_time_budget >= m_fixed_delta_time) {
FixedUpdate();
fixed_time_budget -= m_fixed_delta_time;
}
}
else {
FixedUpdate();
}
// Perform the non-fixed delta time updates of the current scene.
Update(delta_time);
// Render the current scene.
Render(); But I wonder how could this game loop ever work? It will enter the so-called Spiral-of-Death for sure. Lets say you use a fixed time step of 0.5ms and require 4ms for rendering. You will basically increase your time budget with the render time every frame, waste most of that budget on FixedUpdates after which your rendering has no time any more, resulting in the continuous increase of your elapsed frame time (and thus your time budget and the number of FixedUpdates per frame).
You could of course clamp your time budget, but then you obtain something like abs(sin(t)) = #FixedUpdates, which does not look very nice for a game loop IMHO.