stabilize showfps a bit
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 12 Jul 2009 22:25:26 +0000 (22:25 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 12 Jul 2009 22:25:26 +0000 (22:25 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9055 d7cf8633-e32d-0410-b094-e92efae38249

sbar.c

diff --git a/sbar.c b/sbar.c
index 5db9491..6dc02b9 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -1110,12 +1110,15 @@ void Sbar_ShowFPS(void)
                static double nexttime = 0, lasttime = 0;
                static double framerate = 0;
                static int framecount = 0;
-               double interval = 0.25;
+               double interval = 1;
                double newtime;
-               newtime = realtime;
+               newtime = Sys_DoubleTime();
                if (newtime >= nexttime)
                {
-                       framerate = framecount / (newtime - lasttime);
+                       if (framecount > 1) // frames per second
+                               framerate = framecount / interval;
+                       else // seconds per frame
+                               framerate = framecount / (newtime - lasttime);
                        if (nexttime < newtime - interval * 1.5)
                                nexttime = newtime;
                        lasttime = newtime;
@@ -1126,7 +1129,7 @@ void Sbar_ShowFPS(void)
                calc = framerate;
 
                if ((red = (calc < 1.0f)))
-                       dpsnprintf(fpsstring, sizeof(fpsstring), "%4i spf", (int)(1.0f / calc + 0.5));
+                       dpsnprintf(fpsstring, sizeof(fpsstring), "%4i spf", (int)(1.0 / calc + 0.5));
                else
                        dpsnprintf(fpsstring, sizeof(fpsstring), "%4i fps", (int)(calc + 0.5));
        }