]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
changed fps counter behavior to be more 'traditional' (count how many frames go by...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 14 Aug 2002 23:29:34 +0000 (23:29 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 14 Aug 2002 23:29:34 +0000 (23:29 +0000)
showfps 1 - count frames
showfps 2 - average of recent frame times
showfps 3 - most recent frame time only

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2242 d7cf8633-e32d-0410-b094-e92efae38249

sbar.c

diff --git a/sbar.c b/sbar.c
index f4d01ce9be2a6015f5f08932c261ff8dbcc28fd7..d91ff808b1292840e9a76549533bf7adb7b5638d 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -720,30 +720,51 @@ void Sbar_ShowFPS(void)
 {
        if (showfps.integer)
        {
-               static double currtime, frametimes[32];
-               double newtime, total;
+               int calc;
                char temp[32];
-               int calc, count, i;
-               static int framecycle = 0;
                float fps_x, fps_y, fps_scalex, fps_scaley;
-
-               newtime = Sys_DoubleTime();
-               frametimes[framecycle] = newtime - currtime;
-               total = 0;
-               count = 0;
-               while(total < 0.2 && count < 32 && frametimes[i = (framecycle - count) & 31])
+               if (showfps.integer > 1)
                {
-                       total += frametimes[i];
-                       count++;
+                       static double currtime, frametimes[32];
+                       double newtime, total;
+                       int count, i;
+                       static int framecycle = 0;
+
+                       newtime = Sys_DoubleTime();
+                       frametimes[framecycle] = newtime - currtime;
+                       total = 0;
+                       count = 0;
+                       while(total < 0.2 && count < 32 && frametimes[i = (framecycle - count) & 31])
+                       {
+                               total += frametimes[i];
+                               count++;
+                       }
+                       framecycle++;
+                       framecycle &= 31;
+                       if (showfps.integer == 2)
+                               calc = (int) (((double) count / total) + 0.5);
+                       else // showfps 3, rapid update
+                               calc = (int) ((1.0 / (newtime - currtime)) + 0.5);
+                       currtime = newtime;
+               }
+               else
+               {
+                       static double nexttime = 0, lasttime = 0;
+                       static int framerate = 0, framecount = 0;
+                       double newtime;
+                       newtime = Sys_DoubleTime();
+                       if (newtime < nexttime)
+                               framecount++;
+                       else
+                       {
+                               framerate = (int) (framecount / (newtime - lasttime) + 0.5);
+                               lasttime = newtime;
+                               nexttime = lasttime + 0.2;
+                               framecount = 1;
+                       }
+                       calc = framerate;
                }
-               framecycle++;
-               framecycle &= 31;
-               if (showfps.integer == 1)
-                       calc = (int) (((double) count / total) + 0.5);
-               else // showfps 2, rapid update
-                       calc = (int) ((1.0 / (newtime - currtime)) + 0.5);
                sprintf(temp, "%4i", calc);
-               currtime = newtime;
                fps_scalex = 12;
                fps_scaley = 12;
                fps_x = vid.conwidth - (fps_scalex * strlen(temp));