]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/engineinfo.qc
Merge branch 'master' into Mario/speed_var
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / engineinfo.qc
1 #include "engineinfo.qh"
2
3 #include <client/autocvars.qh>
4 #include <client/miscfunctions.qh>
5
6 // Engine info (#13)
7
8 void HUD_EngineInfo_Export(int fh)
9 {
10         // allow saving cvars that aesthetically change the panel into hud skin files
11 }
12
13 float prevfps;
14 float prevfps_time;
15 int framecounter;
16
17 float frametimeavg;
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;
23 void HUD_EngineInfo()
24 {
25         if(!autocvar__hud_configure)
26         {
27                 if(!autocvar_hud_panel_engineinfo) return;
28         }
29
30         HUD_Panel_LoadCvars();
31         vector pos, mySize;
32         pos = panel_pos;
33         mySize = panel_size;
34
35         if (autocvar_hud_panel_engineinfo_dynamichud)
36                 HUD_Scale_Enable();
37         else
38                 HUD_Scale_Disable();
39         HUD_Panel_DrawBg();
40         if(panel_bg_padding)
41         {
42                 pos += '1 1 0' * panel_bg_padding;
43                 mySize -= '2 2 0' * panel_bg_padding;
44         }
45
46         float currentTime = gettime(GETTIME_REALTIME);
47         if(autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage)
48         {
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;
53
54                 float weight;
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.
57                 {
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"
61                 }
62                 prevfps_time = currentTime;
63         }
64         else
65         {
66                 framecounter += 1;
67                 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
68                 {
69                         prevfps = framecounter/(currentTime - prevfps_time);
70                         framecounter = 0;
71                         prevfps_time = currentTime;
72                 }
73         }
74
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);
77 }