]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Bring some accuracy on the fps counter:
authorterencehill <piuntn@gmail.com>
Thu, 23 Sep 2010 22:38:04 +0000 (00:38 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 23 Sep 2010 22:38:04 +0000 (00:38 +0200)
- Get the time with gettime(GETTIME_REALTIME) because for some reason the vars time and frametime are not accurate (frametime and (time - time of previous frame) are always > 0.1) and because otherwise fps depend on slowmo value
- Fix inaccurate fps at low hud_panel_engineinfo_framecounter_time values and default this cvar to 0.1 instead of 1 for both fast update and good reading

defaultXonotic.cfg
qcsrc/client/csqc_builtins.qc
qcsrc/client/hud.qc

index 8e29eb492dc5c084425a503bc70a7d322dec56fa..6c1cf698e5fbb5f29fd40e3446b430c6dbdbae31 100644 (file)
@@ -1369,7 +1369,7 @@ seta hud_panel_radar_rotation 0   "rotation mode: you set what points up. 0 = play
 seta hud_panel_radar_zoommode 0        "zoom mode: 0 = zoomed by default, 1 = zoomed when +zoom, 2 = always zoomed, 3 = always zoomed out"
 alias hud_panel_radar_rotate "toggle hud_panel_radar_rotation 0 1 2 3 4"
 
-seta hud_panel_engineinfo_framecounter_time 1 "time between framerate display updates, smaller values yield less accuracy"
+seta hud_panel_engineinfo_framecounter_time 0.1 "time between framerate display updates"
 seta hud_panel_engineinfo_framecounter_decimals 0 "amount of decimals to show"
 seta hud_panel_engineinfo_framecounter_exponentialmovingaverage 1 "use an averaging method for calculating fps instead of counting frametime like engine does"
 seta hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight 0.1 "weight of latest data point"
index 0835c742db2499eeb51f3eddd0144fdce2c7f7a9..760197a2764a24419d42b69b5721cf9ce0d002b2 100644 (file)
@@ -293,6 +293,7 @@ entity(vector org, float rad) findradius = #22;
 
 string(float uselocaltime, string format, ...) strftime = #478;
 float(float timer) gettime = #519;
+#define GETTIME_REALTIME 1
 #define GETTIME_CDTRACK 4
 
 float(string s) tokenize_console = #514;
index c890866761b8d66c1809c44c9ab00e403383279c..c1dbede921a44231d5f157cf383d697b23dd248d 100644 (file)
@@ -4528,29 +4528,32 @@ void HUD_EngineInfo(void)
                mySize -= '2 2 0' * panel_bg_padding;
        }
 
+       float currentTime = gettime(GETTIME_REALTIME);
        if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
        {
-               frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + frametime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
+               float currentframetime = currentTime - prevfps_time;
+               frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
                frametimeavg2 = frametimeavg1;
                frametimeavg1 = frametimeavg;
                
                float weight;
                weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
-               if(frametime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter.
+               if(currentframetime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter.
                {
-                       if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/frametime) to make big updates instant
-                               prevfps = (1/frametime);
+                       if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/currentframetime) to make big updates instant
+                               prevfps = (1/currentframetime);
                        prevfps = (1 - weight) * prevfps + weight * (1/frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average"
                }
+               prevfps_time = currentTime;
        }
        else
        {
                framecounter += 1;
-               if(time - prevfps_time > cvar("hud_panel_engineinfo_framecounter_time"))
+               if(currentTime - prevfps_time > cvar("hud_panel_engineinfo_framecounter_time"))
                {
-                       prevfps = framecounter/cvar("hud_panel_engineinfo_framecounter_time");
+                       prevfps = framecounter/(currentTime - prevfps_time);
                        framecounter = 0;
-                       prevfps_time = time;
+                       prevfps_time = currentTime;
                }
        }