CONSTANT@FPS?

Started by
17 comments, last by tok_junior 19 years, 8 months ago
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?
Advertisement
Measure the time, roughly

(THIS_FRAME - LAST_FRAME) = DIFFERENCEIf ( DIFFERENCE < DESIRED_FRAME_RATE ) {    sleep( DESIRED_FRAME_RATE - DIFFERENCE ); // stop doing anything for a while   }
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.
______________________________"Man is born free, and everywhere he is in chains" - J.J. Rousseau
ThAnx for reply.but i think leiavoia
's method only viable if faster FPS@HAPPENS. wat if less?
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.
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.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
SORRY, i'm using OPENGL.KNOW nothiNG about D3D or DX.
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.
wglSwapIntervalEXT is extension? OPENGL 1.?.
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.

This topic is closed to new replies.

Advertisement