1 #include "engineinfo.qh"
3 #include <client/autocvars.qh>
4 #include <client/miscfunctions.qh>
8 void HUD_EngineInfo_Export(int fh)
10 // allow saving cvars that aesthetically change the panel into hud skin files
18 float frametimeavg1; // 1 frame ago
19 float frametimeavg2; // 2 frames ago
20 float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage;
21 float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight;
22 float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold;
25 if(!autocvar__hud_configure)
27 if(!autocvar_hud_panel_engineinfo) return;
30 HUD_Panel_LoadCvars();
35 if (autocvar_hud_panel_engineinfo_dynamichud)
42 pos += '1 1 0' * panel_bg_padding;
43 mySize -= '2 2 0' * panel_bg_padding;
46 float currentTime = gettime(GETTIME_REALTIME);
47 if(autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage)
49 float currentframetime = currentTime - prevfps_time;
50 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
51 frametimeavg2 = frametimeavg1;
52 frametimeavg1 = frametimeavg;
55 weight = autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight;
56 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.
58 if(fabs(prevfps - (1/frametimeavg)) > prevfps * autocvar_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
59 prevfps = (1/currentframetime);
60 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"
62 prevfps_time = currentTime;
67 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
69 prevfps = framecounter/(currentTime - prevfps_time);
71 prevfps_time = currentTime;
75 vector color = HUD_Get_Num_Color(prevfps, 100, true);
76 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);