# Getting the FPS (Frames Per Second)

• 04-25-2002
Unregistered
Getting the FPS (Frames Per Second)
I'm curious as to how people get the frames per second the videocard on the computer is currently rendering at. I have an "Asteroids"- type clone, done in Direct3D, and I would like to be able to make it run at a specific speed for every computer, not super speedy on faster computers and like a turtle on slower ones. How do you guys do this?

What I've done thus far is made a global variable that all my movement on the screen is multiplied by. I don't want people to have to go into the code itself and lower the number for faster computers and raise it for slower ones in order for the game to operate at a decent speed. I'm thinking if I can get the F.P.S. the computer is currently running at I can use that as a factor for all my movement calculations.

How do I get the FPS? Or is there maybe another way to make my game run at a constant speed?

Frank
• 04-25-2002
Unregistered
I'm thinking it has to do with the system clock or something. Like taking the time while in one frame and comparing it with the time from the last frame.

Frank
• 04-26-2002
Magos
You need four variables:

Fps;
LastFps;
CurrentTime;
LastTime;

1) At the beginning, set Fps and LastFps to 0
2) At the beginning, set LastTime to CurrentTime
3) At each loop, incease Fps by 1.
4) When CurrentTime (which is updated at each loop) is greater than LastTime + 1 sec, set LastFps to Fps, Fps to 0 and LastTime to CurrentTime.
5) The variable LastFps now contains your Fps.
6) Repeat from 3)
• 04-26-2002
no-one
>
What I've done thus far is made a global variable that all my movement on the screen is multiplied by. I don't want people to have to go into the code itself and lower the number for faster computers and raise it for slower ones in order for the game to operate at a decent speed. I'm thinking if I can get the F.P.S. the computer is currently running at I can use that as a factor for all my movement calculations.
<

these methods are a little overcomplicated, what you need to due is us a timer so thing thing invariable happen only so fast on any computer, like how they control animation frame timing.

start timer;

for(;;)
{
if(check timer)
{
set timer; // set a new timer
do what ever;
}
}
• 04-26-2002
Unregistered
Thnx for the replies! I'm a newbie to these boards, as you can probably see, and am glad there are people around to help out.

How exactly do I get the computer's current time? BTW ... I'm using MS Visual C++ 6.0.

Frank
• 04-26-2002
Magos
GetTickCount() or timeGetTime()
• 04-29-2002
Tazar_Azar
I have a code to get it in OGL at home, i am at school right now. I'll post the function when i get home, if you want it in OGL.
• 04-29-2002
Unregistered
I figured how to get the current FPS once every second. Now I need to figure out what exac tly to do with it.

Is it a matter of using this number as a factor for my movement calculations, or is there an easier way to have the speed of my game run at approximately the same speed on most computers? Most other games(commercial-type anyway) don't do this by limiting the FPS in the game to a specific FPS for all graphics cards, since the actual FPS often varies between different graphics cards while the game appears to operate at the same speed. I assumed they do some sort of calculation using the FPS or something. Suggestions on getting my/our games to run at similar speeds with different graphics cards?????

BTW ... I'm using DirectX and Direct3D in MS Visual C++. However, OpenGL tricks are always welcome since that's where I'm probably headed next.

Frank
• 04-29-2002
no-one
FPS has nothing to do with it, its just used to measure performance, and to make people with hauss comps feel good.
in rare cases games use it for dynamic LOD.

heres a slightly different version of what i posted before!

start timer;

for(;;)
{

if(check timer)
{
set timer; // set a new timer
do what ever updating needs to be done;
}

drawframe();

}

don't limit the FPS just don't update whats in them! this concept can be fleshed out for many different uses.
such as animation!
• 05-01-2002
The best way to do this is to use high prescision timers. All recent computers have them, although pretty old computers won't. Those computers prob won't be running your directx game anyway though. You use these timers to make a class that gives you a mod number that you multiply all of your velocities by so as to make them the same depending on the framerate...pretty bad explanation huh? That's cause someone else already took the time to do it good:) and im sending you there...goto gamedev.net and look under tutorials...its under the section about just common game things, not the specific ones..with a little digging youll find it easy.
I think its called : framerate independent movement
• 05-01-2002
Unregistered
Cant you clamp the fps on high spec machines? If your machine is slow you'll do ok, but if its superfast then it will waste the extra cycles doing nothing - hence the fps is clamped to an upper limit. Just an idea I've seen used..
• 05-01-2002
no-one
>Cant you clamp the fps on high spec machines?
yes!

>
If your machine is slow you'll do ok, but if its superfast then it will waste the extra cycles doing nothing - hence the fps is clamped to an upper limit.
<

i depends really on what your doing wether you should or would need to do this, but yeah you could limit the fps...
• 05-05-2002
krappykoder
really e z solution
ive found hundereds of fps limiter patched u could include that in the install or bug them for the source adn edit 2 ure needs