Advertisement

FPS

Started by January 22, 2002 05:04 AM
3 comments, last by Tompie 23 years, 1 month ago
i''m creating a openGL game. But when a friend tries to do some testing, his (older) video card gives him about 10fps less than on my PC. Since i get about 13ms between each (draw)call, i added to every "calculation": * (average_milliseconds/13.0) it''s better now, but still not very good... Anybody has an idea how to fix this or knows some place where i can look for info?
What "calculation" ? FPS ?
I''m sorry but it seems that something is missing in your question.
I can''t see what is the problem : do you want to speed up the game on your friend''s machine ? do you want to compute a better framerate (FPS) ?
Advertisement
With fps i mean frames per second

my problem is that i have a loop where i update everything and draw it...
so on fast computers, the loop goes faster than on slow computers.
so where i used to calculate:
position += velocity;

i added:
position += velocity * millisconds_since_last_update / 0.013;

(where 0.013 is the millisconds_since_last_update on my computer)

now i did some more changes (better timer function and such), everything looks better now, but i still think there is a better solution for that problem somehow
congratulations
you did exactly what you had to do.

The thing is, when you develop on your machine, you can use the frame as reference for moving the scene, say "each frame my plane will be 1 meter further". But when you see the program running on another computer, or even on your computer (for instance if you computer slows down because other applications are running) you can experience time problems.

The ONLY solution is to base the movement on the time, not the frame. So, the below example becomes something like "every second my plane will be 75 meters further".

First of all, it's a solution for porting your program on other machines.
Secondly, it's also a better solution for realism. If you compute that an object falls with an acceleration of 9.81m/s², you gotta use the "second" as reference to compute exact distances in meters. You can not synchronize such things if you use the "frame" for reference.

Edited by - vincoof on January 22, 2002 9:57:14 AM
This is one of the most commonly asked questions in these forums ... I would get on my high horse and say use the search facility - but I know how often it doesn''t work, so I''ll give you the benefit of the doubt

So, to the solution ...

What you need to do is calculate the time ellapsed between each frame, and calculate how far the user (player?) would have travelled in that amount of time.

For example

If the user is walking at one meter per second, and the time between one frame is 10 milliseconds (1/100 of a second, or 100 FPS), then the user would move 1/100 of a meter for that frame. For a computer that rendered a frame in 4 milliseconds (or 250 FPS), then the distance travelled would be 4/1000 of a meter. Likewise, on a slower computer (say 27 milliseconds per frame, or 37 FPS) then the user would have to move 27/1000 of a meter for that frame.

Assuming you are using Windows, there are three functions normally used to calculate the time between each frame -

GetTickCount - less accurate, but fast to excute
timeGetTime - more accurate, but slower to excute
QueryPerformanceTimer - extremely accurate, but the slowest to excute.

If the above examples, the speed of execution is irrellevant if you only call the function once per frame. But, in the unlikely event you have to call them often each frame, QueryPerformanceTimer takes (on my machine) 55 times longer to query!

Hope that helps!

This topic is closed to new replies.

Advertisement