]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make scoreboard FPS counter much more reliable
authorMario <zacjardine@y7mail.com>
Sat, 25 Apr 2015 11:22:52 +0000 (21:22 +1000)
committerMario <zacjardine@y7mail.com>
Sat, 25 Apr 2015 11:22:52 +0000 (21:22 +1000)
qcsrc/client/main.qc
qcsrc/client/view.qc
qcsrc/common/physics.qc

index fd4427050722fc7e2da3174fda70606501acb153..3398066e82b6fcd79931ec56681976059b684c83 100644 (file)
@@ -413,22 +413,6 @@ void Playerchecker_Think()
        self.nextthink = time + 0.2;
 }
 
-void FPSReporter_Think()
-{
-       localcmd("\ncmd report fps ", ftos(floor(cl_fps)), "\n");
-       self.nextthink = time + sv_showfps;
-}
-
-void FPSReporter_Init()
-{
-       if(!sv_showfps)
-               return;
-
-       entity e = spawn();
-       e.think = FPSReporter_Think;
-       e.nextthink = time + 1;
-}
-
 void Porto_Init();
 void TrueAim_Init();
 void PostInit(void)
@@ -440,7 +424,6 @@ void PostInit(void)
 
        Porto_Init();
        TrueAim_Init();
-       FPSReporter_Init();
 
        fovlock = -1;
 
index 97829ceff12b70d1d80f03a7bf20be75c945bba6..c72a3dd14b5904f03b253fdce7c2130476218fe2 100644 (file)
 #elif defined(SVQC)
 #endif
 
+float showfps_prevfps;
+float showfps_prevfps_time;
+int showfps_framecounter;
+
+float showfps_delay;
+
+float showfps_frametimeavg;
+float showfps_frametimeavg1; // 1 frame ago
+float showfps_frametimeavg2; // 2 frames ago
+void FPSReporter_Think()
+{
+       if(!sv_showfps) { return; }
+
+       float currentTime = gettime(GETTIME_REALTIME);
+       if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
+       {
+               float currentframetime = currentTime - showfps_prevfps_time;
+               showfps_frametimeavg = (showfps_frametimeavg + showfps_frametimeavg1 + showfps_frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
+               showfps_frametimeavg2 = showfps_frametimeavg1;
+               showfps_frametimeavg1 = showfps_frametimeavg;
+
+               float weight;
+               weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
+               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(showfps_prevfps - (1/showfps_frametimeavg)) > showfps_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
+                               showfps_prevfps = (1/currentframetime);
+                       showfps_prevfps = (1 - weight) * showfps_prevfps + weight * (1/showfps_frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average"
+               }
+               showfps_prevfps_time = currentTime;
+       }
+       else
+       {
+               showfps_framecounter += 1;
+               if(currentTime - showfps_prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
+               {
+                       showfps_prevfps = showfps_framecounter/(currentTime - showfps_prevfps_time);
+                       showfps_framecounter = 0;
+                       showfps_prevfps_time = currentTime;
+               }
+       }
+
+       if(time >= showfps_delay)
+       {
+               showfps_delay = time + sv_showfps;
+               localcmd("\ncmd report fps ", sprintf("%.*f", autocvar_hud_panel_engineinfo_framecounter_decimals, showfps_prevfps), "\n");
+       }
+
+       //drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
+}
+
 entity porto;
 vector polyline[16];
 void Porto_Draw()
@@ -1471,6 +1522,8 @@ void CSQC_UpdateView(float w, float h)
        else if(fovlock > 0 && autocvar_cl_specfov) { setproperty(VF_FOV, GetCurrentFov(fovlock)); }
        else { setproperty(VF_FOV, GetCurrentFov(fov)); }
 
+       FPSReporter_Think();
+
        float tempcamera = false;
 
        if(gametype == MAPINFO_TYPE_JAILBREAK)
index 8740fc9c5c4d7dff372c43301d0212979bf163ec..83c0cf42bed6571ebd391c179208f6a909dc8bc4 100644 (file)
@@ -669,7 +669,11 @@ void CheckWaterJump()
                        self.velocity_z = 225;
                        self.flags |= FL_WATERJUMP;
                        SET_JUMP_HELD(self);
+#ifdef SVQC
                        self.teleport_time = time + 2;  // safety net
+#elif defined(CSQC)
+                       pmove_waterjumptime = time + 2;
+#endif
                }
        }
 }
@@ -1637,7 +1641,7 @@ bool IsFlying(entity a)
 
 void PM_Main()
 {
-       float buttons = PHYS_INPUT_BUTTON_MASK(self);
+       int buttons = PHYS_INPUT_BUTTON_MASK(self);
 #ifdef CSQC
        self.items = getstati(STAT_ITEMS, 0, 24);
 
@@ -1684,7 +1688,7 @@ void PM_Main()
                        self.parm_idlesince = time;
        }
 #endif
-       float buttons_prev = self.buttons_old;
+       int buttons_prev = self.buttons_old;
        self.buttons_old = buttons;
        self.movement_old = self.movement;
        self.v_angle_old = self.v_angle;
@@ -1709,14 +1713,14 @@ void PM_Main()
                                self.race_penalty = 0;
 #endif
 
-               float not_allowed_to_move = 0;
+               bool not_allowed_to_move = false;
 #ifdef SVQC
                if (self.race_penalty)
-                       not_allowed_to_move = 1;
+                       not_allowed_to_move = true;
 #endif
 #ifdef SVQC
                if (time < game_starttime)
-                       not_allowed_to_move = 1;
+                       not_allowed_to_move = true;
 #endif
 
                if (not_allowed_to_move)