• Advertisement

Archived

This topic is now archived and is closed to further replies.

Limiting the framerate....

This topic is 5951 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''ve managed to disable V-sync in my project, but on faster computers, my engine runs much too fast to be playable. Can anyone suggest a way to limit the framerate, so that the engine takes full advantage of fast computers without running too fast? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
To get a constant frame rate:
record the time at the top of your main-loop, t1. At the end of the loop you record the time again, t2. Then you calc the difference t2-t1=t3.
Suppose you want to try to achieve a rate equal to r=30 fps (frames per second).
Then calc wait=1/r [unit=second per frame]
Now you compare t3 and wait. If t3 >= wait, then ignore any delay and return to top of loop. If t3 < wait then wait an amount a=wait-t3 before you return to top of the loop.

Was this any help?

/Mankind gave birth to God.

Edited by - silvren on September 24, 2001 12:50:51 PM

Share this post


Link to post
Share on other sites
dont do that u want your engine to run as fast a possible on all machines, check out flipcode, one of the topics or code of the day. theres a big discussion about fixed time steps for physics and ai. graphics u handle differently though see what fraction of a second youre currently at and alter the drawing depending on that.
A<----------->B
say u have a vertice that moves from A to B and back. from A to B takes a second and back also takes a second.
check the games time 46453.5 seconds thus half a second remainder thus stick the vertice halfway between A + B.
this is how u calculate things linearly its not the smoothest but its the easiest later can u use more accurate methods if u wish. q3a use this btw

Share this post


Link to post
Share on other sites
Well, I think it''s even easier than ZedZeek explained it.
First, start thinking in a different mode. Don''t make objects move at a rate x ammount of pixels per frame, instead make them move y ammount of pixels per second. If you do things this way, you game will run at the same speed no matter how fast or slow it''s going. The only drawback, but is consistant with all games, is that on slower machines the display will be quite choppy... Anyway, here''s how I''d do it.

First, you need a framerate counter. I got mine from the OpenGL Game Programming book (CHiResTimer) but i''m sure you can find a way to make a good FPS calculator.

Now, when displaying your object, lets say you want this particular object to move at a rate of 20 PPS (pixels per second) and you''re getting some FPS like 630.

x = number of pixels to move
y = framerate
x / y = z, number of pixels to move in this frame.

You''d end up with roughly 0.031. Break out a calculator and look at it. If you traveled 0.031 pixels 630 times, you''d move 20 pixels. And since you''re framerate is 630 FPS, you moved 20 pixels in a second.

Well, hope this was helpful.

- Mike

Share this post


Link to post
Share on other sites
i would suggest the same method as zedzeek it is a great method
the animations will be smooth and always run at the correct speed
nehe.gamedev.net have a tutorial on morphing that might be useful


A new world, dark without the false light ....

Share this post


Link to post
Share on other sites

  • Advertisement