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
11 HUD_Write_Cvar("hud_panel_engineinfo_framecounter_time");
12 HUD_Write_Cvar("hud_panel_engineinfo_framecounter_decimals");
20 float frametimeavg1; // 1 frame ago
21 float frametimeavg2; // 2 frames ago
22 float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage;
23 float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight;
24 float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold;
27 if(!autocvar__hud_configure)
29 if(!autocvar_hud_panel_engineinfo) return;
32 HUD_Panel_LoadCvars();
37 if (autocvar_hud_panel_engineinfo_dynamichud)
44 pos += '1 1 0' * panel_bg_padding;
45 mySize -= '2 2 0' * panel_bg_padding;
48 float currentTime = gettime(GETTIME_REALTIME);
49 if(autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage)
51 float currentframetime = currentTime - prevfps_time;
52 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
53 frametimeavg2 = frametimeavg1;
54 frametimeavg1 = frametimeavg;
57 weight = autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight;
58 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.
60 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
61 prevfps = (1/currentframetime);
62 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"
64 prevfps_time = currentTime;
69 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
71 prevfps = framecounter/(currentTime - prevfps_time);
73 prevfps_time = currentTime;
78 color = HUD_Get_Num_Color (prevfps, 100);
79 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);