Domanda

I'm programming a game in C++ and I'm having trouble creating a way so that the game only updates 60 times per second. The code I have written looks like it should work but the frame rate actually ends up as 44 frames per second instead of 60.

const int               FRAMES_PER_SECOND = 60;
const int               FRAME_CONTROL = (1000 / FRAMES_PER_SECOND);
double                  lastFrameTime;
double                  currentFrameTime;

void GameLoop()
{
    currentFrameTime = GetTickCount();

    if ((currentFrameTime - lastFrameTime) >= FRAME_CONTROL)
    {
        lastFrameTime = currentFrameTime;

        // Update Game.
    }
}

So yeah, it should be 60 frames but it actually runs at 44. And the class I'm using to count the frame rate works perfectly in other programs which already have a capped frame rate.

Any ideas what the problem is?

È stato utile?

Soluzione

Its due to the resolution of getTickCount. That function only gives 10-16 ms resolution Microsoft GetTickCount()

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top