Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Fps Check every second  (Read 1313 times)

0 Members and 1 Guest are viewing this topic.

Teknol

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Fps Check every second
« on: September 16, 2017, 12:03:42 pm »
Now currently I have a system that calculates the fps (not 100% accurate but good enough) and out puts it into a txt file.

Now I'm trying to make it output only once a second and/or limit the output so there can only be 100 output inside the text file and deletes older outputs.

I tried many different way to slow down the output  but when I put it on a slower clock the fps becomes something like 0.9. (Which kind of makes sense because it's on a slower clock but)

Thank you for reading, anyways here is my code inside main(). I removed irrelevant code


std::ofstream fpsLog;
fpsLog.open("fps_log.txt");

sf::Clock fpsclock
sf::Time FPSTimer
while (window.isOpen())
{
FPSTimer = fpsclock.getElapsedTime();
fpsLog << 1.0f / FPSTimer.asSeconds();
fpsclock.restart().asSeconds();

}


Sent from my iPhone using Tapatalk

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Fps Check every second
« Reply #1 on: September 16, 2017, 12:44:54 pm »
This forum does support Code tags, please use them  ;)

You could do something simple like
sf::Time interval = sf::seconds(1);
float fpsCounter = 0;
while(window.isOpen)
{
  fpsCounter ++;
  if(fpsclock.getElaspedTime() >= interval)
  {
    fpsLog << fpsCounter / interval.asSeconds();
    fpsCounter = 0;
    fpsclock.restart();
  }
}
I just wrote it without testing, but it should be accurate enough (+- 1Frame) and very short to implement.

Also keep in mind that FPS is not linear and does not show peaks in frametime (if you measure a whole second into one value, as in the example). If your game does not feel smooth but still has >= 60FPS you should look at frametime variation.


P.S. fpsclock.restart() does return the elapsedTime before restarting, so your .asSeconds() does nothing ;). But you could write instead of
FPSTimer = fpsclock.getElapsedTime();
//...
fpsclock.restart().asSeconds();
simply write:
FPSTimer = fpsclock.restart()
Which does exactly the same :)


AlexAUT

Teknol

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Fps Check every second
« Reply #2 on: September 17, 2017, 02:06:21 am »
Thank you! Works very smoothely


Sent from my iPhone using Tapatalk