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

Author Topic: [Solved]Draw FPS each second  (Read 2931 times)

0 Members and 1 Guest are viewing this topic.

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
[Solved]Draw FPS each second
« on: October 31, 2010, 06:07:02 pm »
Hi,
I'm trying to make a function that would draw how many FPS were displayed each second.
The original function is:

Code: [Select]
double app_properties::draw_fps()
{
stringstream ss;
getfps=1/(App.GetFrameTime()); //getfps is a float declared in the app_properties class
ss << getfps;
dfps.SetText("FPS: " + (ss.str()).substr(0,2)); //dfps is a font string declared in the app_properties class
App.Draw(dfps);
return getfps;
}


How could I change this and make it draw the FPS only each second?
This is probably very easy to do, but I'm being dumb...

Thanks in advance!

Orwel

  • Full Member
  • ***
  • Posts: 208
    • View Profile
[Solved]Draw FPS each second
« Reply #1 on: October 31, 2010, 06:25:32 pm »
You have to add two parameters. A counter and clock.
When the clock equal 1s, else draw counter and reset clock and counter.

 :wink:

Canadadry

  • Hero Member
  • *****
  • Posts: 1081
    • View Profile
[Solved]Draw FPS each second
« Reply #2 on: October 31, 2010, 06:29:01 pm »
And you also could use static variable. like that

Code: [Select]
int app_properties::draw_fps()
{
static bool init = false;
static sf::Clock clock;

if(init == false)
{
init = true;
clock.reste();
}

getfps=1/(App.GetFrameTime()); //getfps is a float declared in the app_properties class

if(clock.GetEllapsedTime() >= 1.0)
{
clock.reste();
stringstream ss;
ss << getfps;
dfps.SetText("FPS: " + (ss.str()).substr(0,2)); //dfps is a font string declared in the app_properties class
App.Draw(dfps);
}

   return getfps;
}

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
[Solved]Draw FPS each second
« Reply #3 on: November 02, 2010, 10:59:44 am »
Aah, that was quite simple after all.
Thank you both   :wink: