Thread: Getting the FPS (Frames Per Second)

  1. #1
    Unregistered
    Guest

    Question 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

  2. #2
    Unregistered
    Guest
    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

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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)
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    >
    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;
    }
    }
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Unregistered
    Guest

    Thumbs up

    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

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    GetTickCount() or timeGetTime()
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    57
    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.
    Language: C++
    Compiler: Visual C++ 6.0
    Currently Working On: Simple OpenGL aspects

  8. #8
    Unregistered
    Guest
    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

  9. #9
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    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!
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  10. #10
    Registered User DeadArchDown's Avatar
    Join Date
    Apr 2002
    Posts
    28
    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
    -------------------
    "Exception"

  11. #11
    Unregistered
    Guest
    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..

  12. #12
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    >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...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  13. #13
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SwapBuffers & fps
    By hannibar in forum Windows Programming
    Replies: 0
    Last Post: 03-13-2006, 05:19 AM
  2. Game update...
    By jdinger in forum Game Programming
    Replies: 14
    Last Post: 11-08-2002, 07:10 AM
  3. FPS Counter Prob in OpenGL
    By brandonp in forum Game Programming
    Replies: 1
    Last Post: 07-16-2002, 02:49 PM
  4. SkyLock graphics demo (scrolling, etc.)
    By jdinger in forum Game Programming
    Replies: 9
    Last Post: 06-30-2002, 08:18 PM
  5. dramatic decrease in fps
    By DavidP in forum Game Programming
    Replies: 4
    Last Post: 06-27-2002, 09:05 AM