Archived

This topic is now archived and is closed to further replies.

Slower update of FPS counter.

This topic is 5337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok. I''ve done a forum search, I''ve searched the articals on this site. So please keep the bashing to a minimum, ok? ...Please?... Ok, then. Anyhow, I''m having trouble with my FPS counter. You see, it updates every frame, based on how long the frame took. This leads to rapidly fluctuating readings and a loss of accuracy. What I want is for it to measure the framerate of each second, rather than each 10 or 15 milliseconds. This is the code I''m using right now: Start_Clock(); ... int looptime; int framerate; Wait_Clock(10); //make sure framerate does not go above 100 to avoid bugs. looptime = Get_Elapsed(); framerate = 1000 / looptime; sprintf(temptext, "FPS: %d", framerate); If you want the code for Start_Clock() and Get_Elapsed(), just ask. But they are really small functions: Start_Clock just sets a global variable to the current tick count, and Get_Elapsed gets the time elapsed since Start_Clock was called. I''m sure its something simple I''m just overlooking... maybe something like only computing framerate once a second. Could you enlighten me on how to do this properly?

Share this post


Link to post
Share on other sites
Ao.

Okay quick answer.
two ways.

1)
on is have a time count.
inc the time count by the time that has passed since last frame.
when the count is grator then a second.
do the fps math.
set the count to zero.

2}
Set a timer. {system clock event}
when the time event hits. do the fps math.

hope this helps.


Armand
-------------------------
It is a good day to code.

Share this post


Link to post
Share on other sites
Don''t. It''s easy to miss the simple things if you''ve been looking at the complex.

One of the hardest things is to take a step back and re-look.

glad I could help thought.

Armand
-------------------------
It is a good day to code.

Share this post


Link to post
Share on other sites
if it''s any help here is my code. You can guess at the definitions:

  
void CRenderer::CalculateFramesPerSecond(void)
{
++m_TotalFramesThisSecond;

if(m_FpsTimer.ElapsedSeconds() >= 1.0f)
{
m_FpsTimer.Reset();
m_FramesPerSecond = m_TotalFramesThisSecond;
m_TotalFramesThisSecond = 0;
}
}


Chris Brodie
http:\\fourth.flipcode.com

Share this post


Link to post
Share on other sites
quote:
Original post by Armand
Don''t. It''s easy to miss the simple things if you''ve been looking at the complex.

One of the hardest things is to take a step back and re-look.

glad I could help thought.

Armand
-------------------------
It is a good day to code.


Heh... I guess its because I was working on my AI for the last few weeks.


Share this post


Link to post
Share on other sites
Another way is to average the fps over the past 20 frames let''s say. It requires no more variables, just a bit of extra calculation.

ie every frame:
DTime = ((DTime * 19) + (TimeNow - TimeLastFrame))/20

I find fps counters that update every second annoying, I prefer a more dynamic reading. If I want to know if a single event is causing slowdown I set the average over 5 frames or something. It removes the erratic behaviour, while giving a better indication than one averaged over 1s.

But in my opinion they are just about the same.

Share this post


Link to post
Share on other sites
I have always used this bit of code... it works very well with high or low fps:


//========================================================
//
//
//
//========================================================
int GetFPS()
{
static float avgfps = 0.0;
static float loop;
static LARGE_INTEGER last_tick;
LARGE_INTEGER tick;
float dtick;
float fps;
float ticks_per_second;
LARGE_INTEGER freq;

QueryPerformanceFrequency(&freq);
ticks_per_second = float(freq.u.LowPart);

QueryPerformanceCounter(&tick);
dtick = float(tick.u.LowPart - last_tick.u.LowPart);

last_tick = tick;
fps = ticks_per_second / dtick;

return (int)fps;
}


http://www.dransik.com

Share this post


Link to post
Share on other sites