• Create Account

## Limiting the framerate....

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Terran Marine  Members

122
Like
Likes
Like

Posted 24 September 2001 - 03:40 AM

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.

### #2silvren  Members

122
Like
Likes
Like

Posted 24 September 2001 - 04:17 AM

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.

/Mankind gave birth to God.

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

### #3zedzeek  Members

528
Like
Likes
Like

Posted 24 September 2001 - 10:14 AM

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

### #4mkaltner  Members

122
Like
Likes
Like

Posted 25 September 2001 - 05:37 AM

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.

- Mike

### #5satjaur  Members

122
Like
Likes
Like

Posted 05 October 2001 - 09:37 AM

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.