The code below worked correctly(and even with different framerates) - but I need to know - is everything ok ?(e.g - order of calling functions or delta time calculation). Is there is some room for improvements ?
Clock clock;
Time accumulator = Time::Zero;
Time updateRate = seconds(1.0f / 60.0f);
Time dt = Time::Zero;
Time fpsTime = Time::Zero;
while (m_pWindow->isOpen())
{
ProcessEvents();
accumulator += dt;
while (accumulator > updateRate)
{
update_state.DeltaTime = 1.0f / 60.0f;
accumulator -= updateRate;
Update(update_state);
}
Render(draw_state);
dt = clock.restart();
// calculating FPS
fpsTime += dt;
static unsigned frameCounter = 0;
if (fpsTime >= seconds(1.0f)) // calculate FPS only one time per second
{
m_FPS = frameCounter;
fpsTime = Time::Zero;
frameCounter = 0;
}
else
{
++frameCounter;
}
}