Xonotic
physics.qc File Reference
#include "physics.qh"
#include <client/draw.qh>
#include <lib/csqcmodel/cl_player.qh>
+ Include dependency graph for physics.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void HUD_Physics ()
 
void HUD_Physics_Export (int fh)
 

Variables

float acc_avg
 
vector acc_prevspeed
 
float acc_prevtime
 
float discrete_acceleration
 
float discrete_speed
 
float physics_update_time
 
float top_speed
 
float top_speed_time
 

Function Documentation

◆ HUD_Physics()

void HUD_Physics ( )

Definition at line 31 of file physics.qc.

References acc_avg, acc_prevspeed, acc_prevtime, autocvar__hud_configure, autocvar_hud_panel_physics, autocvar_hud_panel_physics_acceleration_max, autocvar_hud_panel_physics_acceleration_movingaverage, autocvar_hud_panel_physics_acceleration_progressbar_mode, autocvar_hud_panel_physics_acceleration_progressbar_nonlinear, autocvar_hud_panel_physics_acceleration_progressbar_scale, autocvar_hud_panel_physics_acceleration_vertical, autocvar_hud_panel_physics_baralign, autocvar_hud_panel_physics_dynamichud, autocvar_hud_panel_physics_flip, autocvar_hud_panel_physics_progressbar, autocvar_hud_panel_physics_speed_max, autocvar_hud_panel_physics_speed_unit, autocvar_hud_panel_physics_speed_unit_show, autocvar_hud_panel_physics_speed_vertical, autocvar_hud_panel_physics_text, autocvar_hud_panel_physics_text_scale, autocvar_hud_panel_physics_topspeed, autocvar_hud_panel_physics_topspeed_time, autocvar_hud_panel_physics_update_interval, autocvar_hud_progressbar_acceleration_color, autocvar_hud_progressbar_acceleration_neg_color, autocvar_hud_progressbar_alpha, autocvar_hud_progressbar_speed_color, bound(), cos(), csqcplayer, discrete_acceleration, discrete_speed, draw_beginBoldFont, draw_endBoldFont, drawfill(), DRAWFLAG_NORMAL, drawstring_aspect(), eX, eY, floor(), ftos(), ftos_decimals(), GetSpeedUnit(), GetSpeedUnitFactor(), HUD_Panel_DrawBg, HUD_Panel_DrawProgressBar(), HUD_Panel_LoadCvars(), HUD_Scale_Disable(), HUD_Scale_Enable(), max(), min(), MUTATOR_CALLHOOK, panel_bg_padding, panel_fg_alpha, panel_pos, panel_size, physics_update_time, PI, pmove_vel, spectatee_status, speed, sqrt(), strcat(), time, top_speed, top_speed_time, vector(), and vlen().

32 {
34  {
35  if(!autocvar_hud_panel_physics) return;
37  if(autocvar_hud_panel_physics == 3 && !MUTATOR_CALLHOOK(HUD_Physics_showoptional)) return;
38  }
39 
41 
43 
46  else
50  {
51  panel_pos += '1 1 0' * panel_bg_padding;
52  panel_size -= '2 2 0' * panel_bg_padding;
53  }
54 
55  float acceleration_progressbar_scale = 0;
57  acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
58 
59  float text_scale;
61  text_scale = 1;
62  else
64 
65  //compute speed
67  vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
68 
69  float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
71  speed = floor( max_speed * 0.65 + 0.5 );
73  speed = floor( vlen(vel) * conversion_factor + 0.5 );
74  else
75  speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 );
76 
77  //compute acceleration
78  float acceleration, f;
81  else
82  {
83  // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
84  f = time - acc_prevtime;
86  acceleration = (vlen(vel) - vlen(acc_prevspeed));
87  else
88  acceleration = (vlen(vel - '0 0 1' * vel.z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed.z));
89 
90  acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
91 
92  acc_prevspeed = vel;
93  acc_prevtime = time;
94 
96  {
97  f = bound(0, f * 10, 1);
98  acc_avg = acc_avg * (1 - f) + acceleration * f;
99  acceleration = acc_avg;
100  }
101  }
102 
103  const int acc_decimals = 2;
105  {
106  discrete_acceleration = acceleration;
107  // workaround for ftos_decimals returning a negative 0
108  if(discrete_acceleration > -1 / (10 ** acc_decimals) && discrete_acceleration < 0)
114  }
115 
116  //compute layout
117  float panel_ar = panel_size.x/panel_size.y;
118  vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
119  if (panel_ar >= 5 && !acceleration_progressbar_scale)
120  {
121  panel_size.x *= 0.5;
123  speed_offset.x = panel_size.x;
124  else
125  acceleration_offset.x = panel_size.x;
126  }
127  else
128  {
129  panel_size.y *= 0.5;
131  speed_offset.y = panel_size.y;
132  else
133  acceleration_offset.y = panel_size.y;
134  }
135  int speed_baralign, acceleration_baralign;
137  acceleration_baralign = speed_baralign = 1;
139  acceleration_baralign = speed_baralign = 2;
141  {
142  acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
143  speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
144  }
145  else
146  {
147  speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
148  acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
149  }
151  acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
152 
153  //draw speed
154  if(speed)
157  vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
159  {
160  tmp_size.x = panel_size.x * 0.75;
161  tmp_size.y = panel_size.y * text_scale;
162  if (speed_baralign)
163  tmp_offset.x = panel_size.x - tmp_size.x;
164  //else
165  //tmp_offset_x = 0;
166  tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
167  drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(discrete_speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
168 
169  //draw speed unit
170  if (speed_baralign)
171  tmp_offset.x = 0;
172  else
173  tmp_offset.x = tmp_size.x;
175  {
176  //tmp_offset_y = 0;
177  tmp_size.x = panel_size.x * (1 - 0.75);
178  tmp_size.y = panel_size.y * 0.4 * text_scale;
179  tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2;
181  drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
182  }
183  }
184 
185  //compute and draw top speed
188  {
190  {
191  top_speed = floor( max_speed * 0.75 + 0.5 );
192  f = 1;
193  }
194  else
195  {
196  if (speed >= top_speed)
197  {
198  top_speed = speed;
200  }
201  if (top_speed != 0)
202  {
204  // divide by f to make it start from 1
205  f = cos( ((time - top_speed_time) / f) * PI/2 );
206  }
207  else // hide top speed 0
208  f = 0;
209  }
210  if (f > 0)
211  {
212  //top speed progressbar peak
213  if(speed < top_speed)
215  {
216  float peak_offsetX;
217  vector peak_size = '0 0 0';
218  if (speed_baralign == 0)
219  peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x;
220  else if (speed_baralign == 1)
221  peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x;
222  else // if (speed_baralign == 2)
223  peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5;
224  peak_size.x = floor(panel_size.x * 0.01 + 1.5);
225  peak_size.y = panel_size.y;
226  if (speed_baralign == 2) // draw two peaks, on both sides
227  {
228  drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x + peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
229  drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x - peak_offsetX + peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
230  }
231  else
232  drawfill(panel_pos + speed_offset + eX * (peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
233  }
234 
235  //top speed
236  tmp_offset.y = panel_size.y * 0.4;
237  tmp_size.x = panel_size.x * (1 - 0.75);
238  tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale;
239  tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2;
240  drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
241  }
242  else
243  top_speed = 0;
244  }
245 
246  //draw acceleration
247  if(acceleration)
249  {
250  vector progressbar_color;
251  if(acceleration < 0)
253  else
255 
258  f = (f >= 0 ? sqrt(f) : -sqrt(-f));
259 
260  if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
261  {
262  tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY;
263 
264  if (acceleration_baralign == 1)
265  tmp_offset.x = panel_size.x - tmp_size.x;
266  else if (acceleration_baralign == 2 || acceleration_baralign == 3)
267  tmp_offset.x = (panel_size.x - tmp_size.x) / 2;
268  else
269  tmp_offset.x = 0;
270  tmp_offset.y = 0;
271  }
272  else
273  {
274  tmp_size = panel_size;
275  tmp_offset = '0 0 0';
276  }
277 
278  HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset + tmp_offset, tmp_size, "accelbar", f, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
279  }
280 
282  {
283  tmp_size.x = panel_size.x;
284  tmp_size.y = panel_size.y * text_scale;
285  tmp_offset.x = 0;
286  tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
287 
288  drawstring_aspect(panel_pos + acceleration_offset + tmp_offset, strcat(ftos_decimals(discrete_acceleration, acc_decimals), "g"), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
289  }
290 
292 }
bool autocvar_hud_panel_physics_flip
Definition: physics.qh:14
#define draw_endBoldFont()
Definition: draw.qh:5
float panel_fg_alpha
Definition: hud.qh:166
ERASEABLE string ftos_decimals(float number, int decimals)
converts a number to a string with the indicated number of decimals
Definition: string.qh:450
vector autocvar_hud_progressbar_speed_color
Definition: physics.qh:27
bool autocvar_hud_panel_physics_acceleration_vertical
Definition: physics.qh:12
void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
Definition: hud.qc:270
float speed
Definition: subs.qh:41
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition: draw.qc:102
const vector eY
Definition: vector.qh:45
float PI
Definition: csprogsdefs.qc:963
float autocvar_hud_panel_physics_acceleration_max
Definition: physics.qh:9
float autocvar_hud_panel_physics_acceleration_progressbar_nonlinear
Definition: physics.qh:8
bool autocvar__hud_configure
Definition: hud_config.qh:3
#define draw_beginBoldFont()
Definition: draw.qh:4
float acc_avg
Definition: physics.qc:29
float discrete_speed
Definition: physics.qc:30
vector panel_size
Definition: hud.qh:160
vector autocvar_hud_progressbar_acceleration_color
Definition: physics.qh:25
vector pmove_vel
Definition: csprogsdefs.qc:55
void HUD_Scale_Disable()
Definition: hud.qc:83
int autocvar_hud_panel_physics_baralign
Definition: physics.qh:13
bool autocvar_hud_panel_physics_topspeed
Definition: physics.qh:22
float acc_prevtime
Definition: physics.qc:29
bool autocvar_hud_panel_physics_speed_vertical
Definition: physics.qh:19
float top_speed_time
Definition: physics.qc:29
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
vector acc_prevspeed
Definition: physics.qc:28
float physics_update_time
Definition: physics.qc:30
float GetSpeedUnitFactor(int speed_unit)
Definition: main.qc:1063
float autocvar_hud_panel_physics_topspeed_time
Definition: physics.qh:23
void HUD_Scale_Enable()
Definition: hud.qc:90
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
vector autocvar_hud_progressbar_acceleration_neg_color
Definition: physics.qh:26
bool autocvar_hud_panel_physics_dynamichud
Definition: physics.qh:15
float top_speed
Definition: physics.qc:29
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
float autocvar_hud_panel_physics_speed_max
Definition: physics.qh:16
vector panel_pos
Definition: hud.qh:159
int autocvar_hud_panel_physics_speed_unit
Definition: physics.qh:17
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float spectatee_status
Definition: main.qh:166
const vector eX
Definition: vector.qh:44
bool autocvar_hud_panel_physics_speed_unit_show
Definition: physics.qh:18
float discrete_acceleration
Definition: physics.qc:30
bool autocvar_hud_panel_physics
Definition: physics.qh:4
string GetSpeedUnit(int speed_unit)
Definition: main.qc:1076
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
float autocvar_hud_panel_physics_update_interval
Definition: physics.qh:10
float autocvar_hud_panel_physics_acceleration_movingaverage
Definition: physics.qh:5
int autocvar_hud_panel_physics_text
Definition: physics.qh:20
entity csqcplayer
Definition: cl_player.qh:26
float autocvar_hud_panel_physics_text_scale
Definition: physics.qh:21
float autocvar_hud_progressbar_alpha
Definition: hud.qh:201
float time
Definition: csprogsdefs.qc:16
float autocvar_hud_panel_physics_acceleration_progressbar_scale
Definition: physics.qh:7
float autocvar_hud_panel_physics_acceleration_progressbar_mode
Definition: physics.qh:6
int autocvar_hud_panel_physics_progressbar
Definition: physics.qh:11
void HUD_Panel_LoadCvars()
Definition: hud.qc:216
float panel_bg_padding
Definition: hud.qh:171
+ Here is the call graph for this function:

◆ HUD_Physics_Export()

void HUD_Physics_Export ( int  fh)

Definition at line 8 of file physics.qc.

References HUD_Write_Cvar.

9 {
10  // allow saving cvars that aesthetically change the panel into hud skin files
11  HUD_Write_Cvar("hud_panel_physics_speed_unit_show");
12  HUD_Write_Cvar("hud_panel_physics_speed_max");
13  HUD_Write_Cvar("hud_panel_physics_speed_vertical");
14  HUD_Write_Cvar("hud_panel_physics_topspeed");
15  HUD_Write_Cvar("hud_panel_physics_topspeed_time");
16  HUD_Write_Cvar("hud_panel_physics_acceleration_max");
17  HUD_Write_Cvar("hud_panel_physics_acceleration_vertical");
18  HUD_Write_Cvar("hud_panel_physics_flip");
19  HUD_Write_Cvar("hud_panel_physics_baralign");
20  HUD_Write_Cvar("hud_panel_physics_progressbar");
21  HUD_Write_Cvar("hud_panel_physics_acceleration_progressbar_mode");
22  HUD_Write_Cvar("hud_panel_physics_acceleration_progressbar_scale");
23  HUD_Write_Cvar("hud_panel_physics_acceleration_progressbar_nonlinear");
24  HUD_Write_Cvar("hud_panel_physics_text");
25  HUD_Write_Cvar("hud_panel_physics_text_scale");
26 }
#define HUD_Write_Cvar(cvar)
Definition: hud_config.qh:38

Variable Documentation

◆ acc_avg

float acc_avg

Definition at line 29 of file physics.qc.

Referenced by HUD_Physics().

◆ acc_prevspeed

vector acc_prevspeed

Definition at line 28 of file physics.qc.

Referenced by HUD_Physics().

◆ acc_prevtime

float acc_prevtime

Definition at line 29 of file physics.qc.

Referenced by HUD_Physics().

◆ discrete_acceleration

float discrete_acceleration

Definition at line 30 of file physics.qc.

Referenced by HUD_Physics().

◆ discrete_speed

float discrete_speed

Definition at line 30 of file physics.qc.

Referenced by HUD_Physics().

◆ physics_update_time

float physics_update_time

Definition at line 30 of file physics.qc.

Referenced by HUD_Physics().

◆ top_speed

float top_speed

Definition at line 29 of file physics.qc.

Referenced by HUD_Physics().

◆ top_speed_time

float top_speed_time

Definition at line 29 of file physics.qc.

Referenced by HUD_Physics().