Xonotic
engineinfo.qc
Go to the documentation of this file.
1 #include "engineinfo.qh"
2 
3 #include <client/draw.qh>
4 
5 // Engine info (#13)
6 
8 {
9  // allow saving cvars that aesthetically change the panel into hud skin files
10 }
11 
12 float prevfps;
15 
17 float frametimeavg1; // 1 frame ago
18 float frametimeavg2; // 2 frames ago
23 {
25  {
27  }
28 
30  vector pos, mySize;
31  pos = panel_pos;
32  mySize = panel_size;
33 
36  else
40  {
41  pos += '1 1 0' * panel_bg_padding;
42  mySize -= '2 2 0' * panel_bg_padding;
43  }
44 
45  float currentTime = gettime(GETTIME_FRAMESTART);
47  {
48  float currentframetime = currentTime - prevfps_time;
49  frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
52 
53  float weight;
55  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.
56  {
57  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
58  prevfps = (1/currentframetime);
59  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"
60  }
61  prevfps_time = currentTime;
62  }
63  else
64  {
65  framecounter += 1;
67  {
68  prevfps = framecounter/(currentTime - prevfps_time);
69  framecounter = 0;
70  prevfps_time = currentTime;
71  }
72  }
73 
74  vector color = HUD_Get_Num_Color(prevfps, 100, true);
76 }
bool autocvar_hud_panel_engineinfo
Definition: engineinfo.qh:4
vector color
float panel_fg_alpha
Definition: hud.qh:166
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition: draw.qc:102
bool autocvar__hud_configure
Definition: hud_config.qh:3
float GETTIME_FRAMESTART
vector panel_size
Definition: hud.qh:160
void HUD_EngineInfo_Export(int fh)
Definition: engineinfo.qc:7
float autocvar_hud_panel_engineinfo_framecounter_time
Definition: engineinfo.qh:7
void HUD_Scale_Disable()
Definition: hud.qc:83
bool autocvar_hud_panel_engineinfo_dynamichud
Definition: engineinfo.qh:5
float prevfps
Definition: engineinfo.qc:12
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
float frametimeavg2
Definition: engineinfo.qc:18
void HUD_Scale_Enable()
Definition: hud.qc:90
float prevfps_time
Definition: engineinfo.qc:13
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
vector panel_pos
Definition: hud.qh:159
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage
Definition: engineinfo.qc:19
int framecounter
Definition: engineinfo.qc:14
vector HUD_Get_Num_Color(float hp, float maxvalue, bool blink)
Definition: hud.qc:123
float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight
Definition: engineinfo.qc:20
float autocvar_hud_panel_engineinfo_framecounter_decimals
Definition: engineinfo.qh:6
float frametimeavg1
Definition: engineinfo.qc:17
float frametimeavg
Definition: engineinfo.qc:16
void HUD_Panel_LoadCvars()
Definition: hud.qc:216
void HUD_EngineInfo()
Definition: engineinfo.qc:22
float panel_bg_padding
Definition: hud.qh:171
float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold
Definition: engineinfo.qc:21