SFML community forums

General => General discussions => Topic started by: keyforge on June 23, 2011, 03:07:54 am

Title: Only getting 16 FPS?
Post by: keyforge on June 23, 2011, 03:07:54 am
Hello, I'm only getting like 16 FPS with this game loop. When I move the render outside of the loop I'm getting like 800 FPS. Is this an issue with my code or SFML 2? I have SetFramerateLimit() at 60 and my computer is pretty new.

When I cout 1.f / myWindow.GetFrameTime() it says like 0.0######.
When I cout myWindow.GetFrameTime() it says 16 or 15.

Help please?

Code: [Select]
void Game::Tick() {
while(myWindow.IsOpened() && myRunning) {
sf::Uint32 elapsedTime = myLoopClock.GetElapsedTime();
myLoopClock.Reset();

       while(elapsedTime > myLoopClock.GetElapsedTime()) {
       sf::Event tmpEvent;
       while(myWindow.PollEvent(tmpEvent)) {
        HandleEvents(tmpEvent);
                        }
}

myStateManager.Update();

myStateManager.Render();
myWindow.Display();
myStateManager.Cleanup();

std::cout << 1.f / myWindow.GetFrameTime() << std::endl;
}
}
Title: Only getting 16 FPS?
Post by: keyforge on June 23, 2011, 05:32:55 am
I tried switching back to SFML-1.6 and the FPS was fine. Has their been an SFML2 update in the past month that broke it and / or fixed it?
Title: Only getting 16 FPS?
Post by: Laurent on June 23, 2011, 07:34:51 am
Quote
When I cout 1.f / myWindow.GetFrameTime() it says like 0.0######.
When I cout myWindow.GetFrameTime() it says 16 or 15.

Time is in milliseconds now.
Title: Only getting 16 FPS?
Post by: Cuban-Pete on June 23, 2011, 07:51:17 am
So it is now 15 frames per milisecond? That is way off the 60 FPS.... :roll:

15 FPmS -> 15000 FPS

60 FPS -> 0,06 FPmS

FPS -> divide by 1000 -> FPmS
Title: Only getting 16 FPS?
Post by: Laurent on June 23, 2011, 08:14:08 am
No, it's (1 / 16 ms) = (1 / 0.016 s) = 60 FPS.
Title: Only getting 16 FPS?
Post by: keyforge on June 23, 2011, 09:12:11 pm
Ok, I feel stupid now...

So how would I go about getting the true FPS? With Vertical Sync on I'm only getting 30 FPS with SFML 1.6, and that's pretty bad because I have a mobility radeon 4100 and it's pretty fast. Could my driver be out of date?

And is 1.f / (1.f / myWindow.GetFrameTime()) the true fps?
Title: Only getting 16 FPS?
Post by: Nexus on June 23, 2011, 09:26:21 pm
Quote from: "keyforge"
And is 1.f / (1.f / myWindow.GetFrameTime()) the true fps?
No, 1 / (1/x) is x itself. The frame time is not same as the number of frames per second.

FPS can be computed like this:
Code: [Select]
1.f / (frametime / 1000.f)
1000.f / frametime