From: Mario Date: Sat, 25 Apr 2015 11:22:52 +0000 (+1000) Subject: Make scoreboard FPS counter much more reliable X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=521f01b793687e0e06f5e0d966c95099342df2e6;p=xonotic%2Fxonotic-data.pk3dir.git Make scoreboard FPS counter much more reliable --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index fd4427050..3398066e8 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -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; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 97829ceff..c72a3dd14 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -22,6 +22,57 @@ #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) diff --git a/qcsrc/common/physics.qc b/qcsrc/common/physics.qc index 8740fc9c5..83c0cf42b 100644 --- a/qcsrc/common/physics.qc +++ b/qcsrc/common/physics.qc @@ -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)