Frame Independent Problem

Started by
14 comments, last by Medo Mex 7 years, 12 months ago

I tried what Irlan Robson suggested, now the frame is independent but sometimes the game lag (when there is sudden frame rate drop) for example, from: 60 FPS to 49 FPS

I'm not sure why it's lagging occasionally, any suggestions?

Advertisement

According do computer science it can be many things you're doing incorrect. Disable anything but physics and graphics and check the results.

Since you've mentioned Bullet, check if it does substepping (steps > 1) internally already. If yes, disable it and use only the substepping scheme you have implemented.

Again, my suggestion is to isolate the problem and measure the elapsed time of code executions using a profiler. That's the best way of checking performance bootlenecks IMHO.

@Irlan Robson: Here is what I'm doing (correct me if I'm doing something wrong):

double timeElapsed = getElapsedTime();

const static double dt = 0.01;
static double accumulator = 0.0;
if (timeElapsed > 0.25)
    timeElapsed = 0.25;
accumulator += timeElapsed;
while (accumulator >= dt)
{
    Update((float)dt);
    accumulator -= dt;
}

And here is how I call bullet physics stepSimulation():


void Update(float dt)
{
    // ...
    // ...
    // ...
    dynamicsWorld->stepSimulation(dt, 0); // dt is always equal to 0.01, maxSubSteps is equal to 0
}

According to Bullet, when you pass maxSubSteps = 0, it will use only step the world once. Therefore, your code seems to be correct.

Try to isolate code sections and compare the elapsed time of their execution using a profiler (scope-based if you'd like convenience; otherwise just measure it manually and dump the elapsed time to the console) to check where is the source of these frame rate spikes. That will save us a couple of words here in trying to guess exactly what is the problem.

@Irlan Robson: I created a class to measure the time of execution for a block of code

It seems that the problem is not caused by the physics engine, because even when I use free camera to move in the scene I experience lag occasionally.

Although the lag occurs only when the frame rate drop few frames (for example: From 60 to 52), running at around 49-55 FPS for few seconds should not make any noticeable difference (should not cause lag) than running at 60 FPS, am I correct?

Btw, I have VSync enabled.

Any update?

This topic is closed to new replies.

Advertisement