]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
new toys, new toys! CSQC-based FPS counter with way too many (and long) cvars!
authorFruitieX <rasse@rasse-lappy.localdomain>
Mon, 14 Jun 2010 20:03:19 +0000 (23:03 +0300)
committerFruitieX <rasse@rasse-lappy.localdomain>
Mon, 14 Jun 2010 20:03:19 +0000 (23:03 +0300)
defaultXonotic.cfg
qcsrc/client/hud.qc
qcsrc/common/constants.qh
qcsrc/common/util.qc

index a0ad582aabd4c73e0a4e99ff4266ff29c7114b79..403cac685e31b6d339178e812b57e82ea5e7c512 100644 (file)
@@ -1499,6 +1499,20 @@ seta hud_chat_bg_alpha 0 "if set to something else than \"\" = override default
 seta hud_chat_bg_border "" "if set to something else than \"\" = override default size of border around the background"
 seta hud_chat_bg_padding "" "if set to something else than \"\" = override default padding of contents from border"
 
+seta hud_engineinfo 1 "enable/disable this panel, 1 = show only when spectating other players, 2 = show always"
+seta hud_engineinfo_pos "-0.131250 -0.050000"" "position of this base of the panel"
+seta hud_engineinfo_size "0.131250 0.041667" "size of this panel"
+seta hud_engineinfo_bg "" "if set to something else than \"\" = override default background"
+seta hud_engineinfo_bg_color "" "if set to something else than \"\" = override default panel background color"
+seta hud_engineinfo_bg_color_team "" "override panel color with team color in team based games"
+seta hud_engineinfo_bg_alpha 0 "if set to something else than \"\" = override default panel background alpha"
+seta hud_engineinfo_bg_border "" "if set to something else than \"\" = override default size of border around the background"
+seta hud_engineinfo_bg_padding "" "if set to something else than \"\" = override default padding of contents from border"
+seta hud_engineinfo_framecounter_time 1 "time between framerate display updates, smaller values yield less accuracy"
+seta hud_engineinfo_framecounter_exponentialmovingaverage 0 "use an averaging method for calculating fps instead of counting frametime like engine does"
+seta hud_engineinfo_framecounter_exponentialmovingaverage_new_weight 0.025 "weight of latest data point"
+seta hud_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold 0.5 "treshold for fps change when to update instantly, to make big fps changes update faster"
+
 // scoreboard
 seta scoreboard_columns default
 seta scoreboard_border_thickness 1 "scoreboard border thickness"
index 7df69e16e3b792f3e0bb394737a76047172c802b..45cc5150a5f5599254cbfe42d4a6b212379b7683 100644 (file)
@@ -217,31 +217,30 @@ void HUD_DrawXNum (vector pos, float num, float digits, float showsign, float le
        }
 }
 
-// color the number differently based on how big it is (used in the health/armor panel)
-void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize, float alpha)
+vector HUD_Get_Num_Color (float x, float maxvalue)
 {
        vector color;
-       if(x > 200) {
+       if(x > maxvalue) {
                color_x = 0;
                color_y = 1;
                color_z = 0;
        }
-       else if(x > 150) {
+       else if(x > maxvalue * 0.75) {
                color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
                color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
                color_z = 0;
        }
-       else if(x > 100) {
+       else if(x > maxvalue * 0.5) {
                color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
                color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
                color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
        }
-       else if(x > 50) {
+       else if(x > maxvalue * 0.25) {
                color_x = 1;
                color_y = 1;
                color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
        }
-       else if(x > 20) {
+       else if(x > maxvalue * 0.1) {
                color_x = 1;
                color_y = (x-20)*90/27/100; // green value between 0 -> 1
                color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
@@ -251,6 +250,13 @@ void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize,
                color_y = 0;
                color_z = 0;
        }
+       return color;
+}
+// color the number differently based on how big it is (used in the health/armor panel)
+void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize, float alpha)
+{
+       vector color;
+       color = HUD_Get_Num_Color (x, 200);
        HUD_DrawXNum(pos, x, digits, 0, lettersize, color, 0, 0, alpha, DRAWFLAG_NORMAL);
 }
 
@@ -671,6 +677,9 @@ vector HUD_Panel_GetMinSize(float id)
                case 11: 
                        mySize_y = 0.5898; // 0.5898 * width, reason: bg has weird dimensions...
                        break;
+               case 13: 
+                       mySize_y = 0.25; // 0.25 * width, trial and error...
+                       break;
        }
        if(!mySize_x && mySize_y)
                mySize_x = 1/mySize_y;
@@ -3933,6 +3942,53 @@ void HUD_Chat(void)
        }
 }
 
+// Engine info panel (#13)
+//
+float prevfps;
+float prevfps_time;
+float framecounter;
+void HUD_EngineInfo(void)
+{
+       float id = HUD_PANEL_ENGINEINFO;
+       vector pos, mySize;
+       pos = HUD_Panel_GetPos(id);
+       mySize = HUD_Panel_GetSize(id);
+
+       HUD_Panel_DrawBg(id, pos, mySize, 0);
+       float padding;
+       padding = HUD_Panel_GetPadding(id);
+       if(padding)
+       {
+               pos += '1 1 0' * padding;
+               mySize -= '2 2 0' * padding;
+       }
+
+       if(cvar("hud_engineinfo_framecounter_exponentialmovingaverage"))
+       {
+               float weight;
+               weight = cvar("hud_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(fabs(prevfps - (1/frametime)) > prevfps * cvar("hud_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);
+                       prevfps = (1 - weight) * prevfps + weight * (1/frametime);
+               }
+       }
+       else
+       {
+               framecounter += 1;
+               if(time - prevfps_time > cvar("hud_engineinfo_framecounter_time"))
+               {
+                       prevfps = framecounter/cvar("hud_engineinfo_framecounter_time");
+                       framecounter = 0;
+                       prevfps_time = time;
+               }
+       }
+
+       vector color;
+       color = HUD_Get_Num_Color (prevfps, 100);
+       drawstring(pos, strcat("FPS: ", ftos_decimals(prevfps, 2)), '1 1 0' * 0.5 * mySize_y, color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
+}
 /*
 ==================
 Main HUD system
@@ -4115,6 +4171,8 @@ void HUD_Main (void)
                HUD_Chat();
        else
                cvar_set("con_csqcpositioning", "0");
+       if(HUD_Panel_CheckActive(HUD_PANEL_ENGINEINFO) || hud_configure)
+               HUD_EngineInfo();
 
        // TODO hud_'ify these
        if (cvar("cl_showspeed"))
index b52931e60ed876f27ca471a770db52a3369b7fb8..056e9a251f7851a4ca5db1724bad1026eb0486b9 100644 (file)
@@ -580,6 +580,7 @@ float HUD_PANEL_VOTE                = 9;
 float HUD_PANEL_MODICONS       = 10;
 float HUD_PANEL_PRESSEDKEYS    = 11;
 float HUD_PANEL_CHAT           = 12;
-float HUD_PANEL_NUM            = 13;
+float HUD_PANEL_ENGINEINFO     = 13;
+float HUD_PANEL_NUM            = 14; // always last panel id + 1, please increment when adding a new panel
 
 float HUD_MENU_ENABLE          = 0;
index b25302c703fc4dce5394039388e66615ad07ba10..08eaaeee74ab4dec57ccf070cba0d826fd900c1b 100644 (file)
@@ -1966,6 +1966,7 @@ string HUD_Panel_GetName(float id)
                case HUD_PANEL_MODICONS: return "modicons"; break;
                case HUD_PANEL_PRESSEDKEYS: return "pressedkeys"; break;
                case HUD_PANEL_CHAT: return "chat"; break;
+               case HUD_PANEL_ENGINEINFO: return "engineinfo"; break;
                default: return "";
        }
 }