SFML community forums

Help => System => Topic started by: sponsz on November 19, 2009, 05:00:41 pm

Title: Use of Clock Function for FrameRate Smoothing
Post by: sponsz on November 19, 2009, 05:00:41 pm
How would one go about using the clock function to smooth the FPS?

I was thinking of having it increment or decrement a delay loop, per tick, so that if the framerate increased beyond 60 FPS it would increase the delay by some proportionate amount, and if it fell below 60 FPS it would decrease the delay.

Thoughts?  Is there a canonical way of doing this?
Title: Use of Clock Function for FrameRate Smoothing
Post by: G. on November 19, 2009, 06:47:28 pm
What's wrong with SetFramerateLimit ? ;)
Title: Use of Clock Function for FrameRate Smoothing
Post by: sponsz on November 19, 2009, 08:10:35 pm
Why thank you, good sir.
Title: Use of Clock Function for FrameRate Smoothing
Post by: l0calh05t on November 19, 2009, 08:18:20 pm
why do you want to limit your framerate? you should design your game to be framerate-independent. anyways, if your game uses almost no graphics resources (high framerate), I would recommend enabling VSync instead, as that also prevents tearing.

btw: great avatar
Title: Use of Clock Function for FrameRate Smoothing
Post by: Nexus on November 19, 2009, 08:35:12 pm
Quote from: "l0calh05t"
why do you want to limit your framerate? you should design your game to be framerate-independent. anyways, if your game uses almost no graphics resources (high framerate), I would recommend enabling VSync instead, as that also prevents tearing.
I think, in many situations both ways are equivalent. Since SFML provides a function to set the framerate, this is a very easy approach. Besides, a lot of things are easier to handle with a fixed framerate (for example object movement and collision)...

Quote from: "l0calh05t"
great avatar
Hey, I thought so, too. Reminds me of good old Tintin. :)
Title: Use of Clock Function for FrameRate Smoothing
Post by: l0calh05t on November 19, 2009, 08:44:04 pm
Quote from: "Nexus"
I think, in many situations both ways are equivalent. Since SFML provides a function to set the framerate, this is a very easy approach. Besides, a lot of things are easier to handle with a fixed framerate (for example object movement and collision)...


well, setting framerate via SetFramerateLimit is not particularly precise (so your game's speed will vary on different computers). the best solution is to use a fixed framerate internally, and interpolate for display (which is then framerate independent)
Title: Use of Clock Function for FrameRate Smoothing
Post by: panithadrum on November 19, 2009, 08:48:33 pm
What about VSync + FrameRate + Delta time?

Vsync and FrameRate to make your application not to run too fast, and Delta time to keep your game speed if FPS goes under FrameRate.
Title: Use of Clock Function for FrameRate Smoothing
Post by: l0calh05t on November 19, 2009, 09:38:22 pm
Quote from: "panithadrum"
What about VSync + FrameRate + Delta time?

Vsync and FrameRate to make your application not to run too fast, and Delta time to keep your game speed if FPS goes under FrameRate.


No need for framerate limiting with vsync, the framerate will automatically be limited to the monitor's refresh rate (usually 60 or 75 Hz)
Title: Use of Clock Function for FrameRate Smoothing
Post by: Nexus on November 19, 2009, 10:25:19 pm
Quote from: "l0calh05t"
well, setting framerate via SetFramerateLimit is not particularly precise (so your game's speed will vary on different computers).
Really? I thought SFML would calculate the frame duration and wait every frame until its time is up (by sf::Sleep()). Am I wrong? Or do you mean that the resolution of sf::Sleep() might be not too precise?
Title: Use of Clock Function for FrameRate Smoothing
Post by: panithadrum on November 19, 2009, 11:44:06 pm
Quote from: "Nexus"
Quote from: "l0calh05t"
well, setting framerate via SetFramerateLimit is not particularly precise (so your game's speed will vary on different computers).
Really? I thought SFML would calculate the frame duration and wait every frame until its time is up (by sf::Sleep()). Am I wrong? Or do you mean that the resolution of sf::Sleep() might be not too precise?

I don't know why, but it's Windows related. I checked it.
Laurent will change the Windows timer function in SFML2 (he will implement the Ogre's one).
Title: Use of Clock Function for FrameRate Smoothing
Post by: Laurent on November 20, 2009, 12:23:17 am
Quote
I don't know why, but it's Windows related. I checked it.
Laurent will change the Windows timer function in SFML2 (he will implement the Ogre's one).

By the way, I added 3 links to the corresponding task that provide patches for this issue.
So maybe you can get rid of it before I fix it in SFML ;)
Title: Use of Clock Function for FrameRate Smoothing
Post by: l0calh05t on November 20, 2009, 09:13:47 am
Quote from: "Nexus"
Really? I thought SFML would calculate the frame duration and wait every frame until its time is up (by sf::Sleep()). Am I wrong? Or do you mean that the resolution of sf::Sleep() might be not too precise?


It's the resolution of Sleep which is usually around 10ms (but might be anywhere between 1 and 30ms depending on your windows version)

Btw this can be changed by calling timeBeginPeriod/timeEndPeriod