# 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.

## 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 on other sites
Measure the time, roughly

(THIS_FRAME - LAST_FRAME) = DIFFERENCEIf ( DIFFERENCE < DESIRED_FRAME_RATE ) {    sleep( DESIRED_FRAME_RATE - DIFFERENCE ); // stop doing anything for a while   }

##### 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 on other sites
ThAnx for reply.but i think leiavoia
's method only viable if faster FPS@HAPPENS. wat if less?

##### 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 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 on other sites
SORRY, i'm using OPENGL.KNOW nothiNG about D3D or DX.

##### 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 on other sites
wglSwapIntervalEXT is extension? OPENGL 1.?.

##### 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.

• 37
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631360
• Total Posts
2999556
×