Archived

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

Sartak

Keeping track of FPS rate

Recommended Posts

I was just wondering if this is an ideal way to keep track of the FPS rate. Is it even accurate? This fps_count function is called every frame. I have it displayed on the screen right after it's called each time, so I can keep track of it...so yeah, here's the code.
      
int    fps;
int    old_fps;
time_t update_second;
int fps_count()
{
  fps++;
  if (time(NULL) >= update_second)
  {
    update_second = time(NULL) + 1;
    old_fps = fps;
    fps = 0;
  }
  return old_fps;
}
    
EDIT: I made the code a little more compact. -Sartak [edited by - Sartak on July 30, 2002 6:30:48 PM]

Share this post


Link to post
Share on other sites
that wouldn't be too accurate, and if you're on a high end machine, the fps counter would look like a mess. you won't be able to read it, because it will change so fast. instead, try waiting a period of time (0.25 - 1 sec), while counting how many frames were rendered (each time one is rendered, increase a counter). when that amount of time passed, you calculate the fps by dividing number of frames rendered by time passed (if it's in milliseconds, you'd have to multiply the result by 1000, or else you'd have frames per ms). set some var to the fps and use it for the next specific amount of time to show the fps. and don't forget to reset the frames rendered counter each fps rate update.

hope i helped.

edit: hmm... after looking at the code, i realized i misunderstood you. i though u said that fps rate is calculated each frame. what you have there is precicely what i described above. so i don't get it, why did u ask if it's accurate if you have that function? why not try it yourself. oh well...

---
shurcool
wwdev


[edited by - shurcool on July 30, 2002 6:13:00 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by shurcool
so i don''t get it, why did u ask if it''s accurate if you have that function? why not try it yourself. oh well...



I just want to be positive that I have an accurate FPS rate. I''m fairly sure that this is accurate, with perhaps a margin of error of +/- 1.

Is there an even better way to code it?

-Sartak

Share this post


Link to post
Share on other sites
Just an idea,

Why not set a timer.
If your using win32 you can set a timer for 1 second and do a callback.
{api call SetTimer I think}

It''s not threaded and is quiet reliable from the stuff that
I have done.

If your using Unix {or flavours there of} you could use a signal.
Note: not the best solution but does work well.




It is a good day to code.

Share this post


Link to post
Share on other sites