Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Use of Clock Function for FrameRate Smoothing  (Read 11506 times)

0 Members and 1 Guest are viewing this topic.

sponsz

  • Newbie
  • *
  • Posts: 7
    • View Profile
Use of Clock Function for FrameRate Smoothing
« 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?

G.

  • Hero Member
  • *****
  • Posts: 1590
    • View Profile
Use of Clock Function for FrameRate Smoothing
« Reply #1 on: November 19, 2009, 06:47:28 pm »
What's wrong with SetFramerateLimit ? ;)

sponsz

  • Newbie
  • *
  • Posts: 7
    • View Profile
Use of Clock Function for FrameRate Smoothing
« Reply #2 on: November 19, 2009, 08:10:35 pm »
Why thank you, good sir.

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Use of Clock Function for FrameRate Smoothing
« Reply #3 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Use of Clock Function for FrameRate Smoothing
« Reply #4 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. :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Use of Clock Function for FrameRate Smoothing
« Reply #5 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)

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Use of Clock Function for FrameRate Smoothing
« Reply #6 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.

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Use of Clock Function for FrameRate Smoothing
« Reply #7 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)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Use of Clock Function for FrameRate Smoothing
« Reply #8 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?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Use of Clock Function for FrameRate Smoothing
« Reply #9 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).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Use of Clock Function for FrameRate Smoothing
« Reply #10 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 ;)
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Use of Clock Function for FrameRate Smoothing
« Reply #11 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

 

anything