Jump to content
  • Advertisement
Sign in to follow this  
gan

CONSTANT@FPS?

This topic is 5051 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am doing some simple 3D stuff.But problem arise‚“: how do let the program has constant frame per second(FPS)? Sometimes, that program achieves >200 FPS on advanced computers until it's unplayable.Also, on the other hand, it achieves 2 FPSDIs that the so-called multithreading?

Share this post


Link to post
Share on other sites
Advertisement
Measure the time, roughly

(THIS_FRAME - LAST_FRAME) = DIFFERENCE

If ( DIFFERENCE < DESIRED_FRAME_RATE ) {
sleep( DESIRED_FRAME_RATE - DIFFERENCE ); // stop doing anything for a while
}

Share this post


Link to post
Share on other sites
There are a couple of options.
The easiest (but not most elegant) is to simply query a timer and locked the number of frame updates to a maximum number, say, 60FPS.
You'd have to do the same for movement. I'm not particularly fond of this solution for most apps, but for relatively simple apps, I use it.

Another option would be to implement time based animation and movement. I've implemented the time based animation, and it's not bad. You just need to make animations that have time information, such as what time the frame occurs, and simply interpolate in between frames. I'm not as familiar with time based motion, and I may actually be using the wrong term for what I'm trying to descibe. Basically, if you hold a direction for 1 second, you want the character to move the same distance in 1 second on every possible computer you run on.

Share this post


Link to post
Share on other sites
ThAnx for reply.but i think leiavoia
's method only viable if faster FPS@HAPPENS. wat if less?

Share this post


Link to post
Share on other sites
Then your game starts to run slower, which you can easily see in action on the older consoles like the SNES & MegaDrive when theres lots of sprites on screen. So make sure you provide some suitable options for everybody to get it to run at an acceptable speed for their particular machine.

Share this post


Link to post
Share on other sites
Assumming you are using DX (this is the DX forum [wink]), you can set the "presentation interval" in the presentation parameters structure when creating a device. You could set it to "PresentationInterval.One" (Managed DX, not sure what the constant is for unmanaged DX) and that will lock the frame rate to your monitors refresh rate. Most monitors refresh rates are either 60, 75, 85, 90 and 100 Hz, though there are probably others. That will make it so your game will never go above that rate.

Share this post


Link to post
Share on other sites
In OpenGL theres the wglSwapIntervalEXT which does the same thing, although I think its only avalible on windows. I assume if you're using something like SDL then they'll be a platform-independant method of setting the vSync.

Share this post


Link to post
Share on other sites
If your frame rate is too low, there are no tricks to getting it back to normal other than dumping as many of your special effects as possible to allow the app to run on lower hardware.

DOOM3 on a 486 will never run at 60fps no matter what you do to it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!