Results 1 to 7 of 7
  1. #1
    VDV777's Avatar
    Join Date
    Mar 2013
    Gender
    male
    Posts
    11
    Reputation
    10
    Thanks
    1
    My Mood
    Amazed

    c++ VS 2012 calculate the FPS in the game

    I want to calculate the FPS in the game and put in my dirextX menu.

    How to do it? Interested in source code.
    Here's what I found on the Internet at:


    Code:
    DWORD FrameCnt;
    float TimeElapsed;
    float FPS;
    float oldTime;
    float newTime;
    float deltatime;
    
    FrameCnt++;
    newTime = GetTickCount();
    deltatime = newTime - oldTime;
    TimeElapsed += deltatime;
    
    if(TimeElapsed >= 500.0)
    {
    FPS = 1000*(float)FrameCnt / TimeElapsed;
    TimeElapsed = 0.0f;
    FrameCnt = 0;
    }
    But it does not work.

  2. #2
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    GetTickCount function (Windows)

    Syntax
    C++

    DWORD WINAPI GetTickCount(void); // Returns a DWORD, not float.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  3. The Following User Says Thank You to abuckau907 For This Useful Post:

    VDV777 (05-03-2013)

  4. #3
    AnVIRUS's Avatar
    Join Date
    May 2012
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    0
    char* GetFPS(void)
    {

    static int FPScounter = 0;
    static float FPSfLastTickCount = 0.0f;
    static float FPSfCurrentTickCount;
    static char cfps[6] = "";

    FPSfCurrentTickCount = clock() * 0.001f;
    FPScounter++;
    if((FPSfCurrentTickCount - FPSfLastTickCount) > 1.0f)
    {
    FPSfLastTickCount = FPSfCurrentTickCount;
    sprintf(cfps," %d",FPScounter);
    FPScounter = 0;
    }
    return cfps;
    }

    Using:
    DrawText(X,Y,color, GetFPS(), style);

  5. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Why measure once per second? Just take the time between two consecutive frames and calculate framerate from that.
    Ah we-a blaze the fyah, make it bun dem!

  6. The Following User Says Thank You to Hell_Demon For This Useful Post:

    ~Syphox (05-18-2013)

  7. #5
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    Where are you handling the calculations for the fps as well? If you aren't properly checking each frame you technically will never get valid results.

    The code you posted will also never work properly if you are just tossing all of it into a single function since all your variables will reset each call that is made to calculate the fps.

  8. #6
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by atom0s View Post
    Where are you handling the calculations for the fps as well? If you aren't properly checking each frame you technically will never get valid results.

    The code you posted will also never work properly if you are just tossing all of it into a single function since all your variables will reset each call that is made to calculate the fps.
    If you're refering to anvirus, he uses static which means they're not reset as they have a static address
    Ah we-a blaze the fyah, make it bun dem!

  9. #7
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    I was referring to the main post.

Similar Threads

  1. Evolution of the FPS - 100 FPS games
    By hussein5796 in forum General
    Replies: 20
    Last Post: 12-06-2011, 06:11 PM
  2. The Fps creator guy @fuko
    By Smurfyv in forum General
    Replies: 6
    Last Post: 07-07-2011, 06:06 PM
  3. 2012 The end of the world
    By CyberGenius in forum General
    Replies: 10
    Last Post: 08-02-2010, 08:12 AM
  4. Which FPS has the worst community?
    By Jabooty671 in forum General
    Replies: 60
    Last Post: 07-14-2010, 03:11 AM
  5. Replies: 10
    Last Post: 09-07-2009, 09:31 PM