3 #include <client/main.qh>
4 #include <common/mapinfo.qh>
5 #include <lib/csqcmodel/cl_player.qh>
10 float acc_prevtime, acc_avg, top_speed, top_speed_time;
11 float physics_update_time, discrete_speed, discrete_acceleration;
14 if(!autocvar__hud_configure)
16 if(!autocvar_hud_panel_physics) return;
17 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
18 if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
21 HUD_Panel_LoadCvars();
25 if (autocvar_hud_panel_physics_dynamichud)
32 panel_pos += '1 1 0' * panel_bg_padding;
33 panel_size -= '2 2 0' * panel_bg_padding;
36 float acceleration_progressbar_scale = 0;
37 if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
38 acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
41 if (autocvar_hud_panel_physics_text_scale <= 0)
44 text_scale = min(autocvar_hud_panel_physics_text_scale, 1);
47 float speed, conversion_factor = GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit);
48 string unit = GetSpeedUnit(autocvar_hud_panel_physics_speed_unit);
49 vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
51 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
52 if (autocvar__hud_configure)
53 speed = floor( max_speed * 0.65 + 0.5 );
54 else if(autocvar_hud_panel_physics_speed_vertical)
55 speed = floor( vlen(vel) * conversion_factor + 0.5 );
57 speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 );
59 //compute acceleration
60 float acceleration, f;
61 if (autocvar__hud_configure)
62 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
65 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
66 f = time - acc_prevtime;
67 if(autocvar_hud_panel_physics_acceleration_vertical)
68 acceleration = (vlen(vel) - vlen(acc_prevspeed));
70 acceleration = (vlen(vel - '0 0 1' * vel.z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed.z));
72 acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
77 if(autocvar_hud_panel_physics_acceleration_movingaverage)
79 f = bound(0, f * 10, 1);
80 acc_avg = acc_avg * (1 - f) + acceleration * f;
81 acceleration = acc_avg;
86 if(time > physics_update_time)
88 // workaround for ftos_decimals returning a negative 0
89 if(discrete_acceleration > -1 / pow(10, acc_decimals) && discrete_acceleration < 0)
90 discrete_acceleration = 0;
91 discrete_acceleration = acceleration;
92 discrete_speed = speed;
93 physics_update_time += autocvar_hud_panel_physics_update_interval;
97 float panel_ar = panel_size.x/panel_size.y;
98 vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
99 if (panel_ar >= 5 && !acceleration_progressbar_scale)
102 if (autocvar_hud_panel_physics_flip)
103 speed_offset.x = panel_size.x;
105 acceleration_offset.x = panel_size.x;
110 if (autocvar_hud_panel_physics_flip)
111 speed_offset.y = panel_size.y;
113 acceleration_offset.y = panel_size.y;
115 int speed_baralign, acceleration_baralign;
116 if (autocvar_hud_panel_physics_baralign == 1)
117 acceleration_baralign = speed_baralign = 1;
118 else if(autocvar_hud_panel_physics_baralign == 4)
119 acceleration_baralign = speed_baralign = 2;
120 else if (autocvar_hud_panel_physics_flip)
122 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
123 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
127 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
128 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
130 if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
131 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
135 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
136 HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, autocvar_hud_progressbar_speed_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
137 vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
138 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
140 tmp_size.x = panel_size.x * 0.75;
141 tmp_size.y = panel_size.y * text_scale;
143 tmp_offset.x = panel_size.x - tmp_size.x;
146 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
147 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(discrete_speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
153 tmp_offset.x = tmp_size.x;
154 if (autocvar_hud_panel_physics_speed_unit_show)
157 tmp_size.x = panel_size.x * (1 - 0.75);
158 tmp_size.y = panel_size.y * 0.4 * text_scale;
159 tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2;
160 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
164 //compute and draw top speed
165 if (autocvar_hud_panel_physics_topspeed)
166 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
168 if (autocvar__hud_configure)
170 top_speed = floor( max_speed * 0.75 + 0.5 );
175 if (speed >= top_speed)
178 top_speed_time = time;
182 f = max(1, autocvar_hud_panel_physics_topspeed_time);
183 // divide by f to make it start from 1
184 f = cos( ((time - top_speed_time) / f) * PI/2 );
186 else //hide top speed 0, it would be stupid
191 //top speed progressbar peak
192 if(speed < top_speed)
193 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
196 vector peak_size = '0 0 0';
197 if (speed_baralign == 0)
198 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x;
199 else if (speed_baralign == 1)
200 peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x;
201 else // if (speed_baralign == 2)
202 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5;
203 peak_size.x = floor(panel_size.x * 0.01 + 1.5);
204 peak_size.y = panel_size.y;
205 if (speed_baralign == 2) // draw two peaks, on both sides
207 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);
208 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);
211 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);
215 tmp_offset.y = panel_size.y * 0.4;
216 tmp_size.x = panel_size.x * (1 - 0.75);
217 tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale;
218 tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2;
219 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
227 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
229 vector progressbar_color;
231 progressbar_color = autocvar_hud_progressbar_acceleration_neg_color;
233 progressbar_color = autocvar_hud_progressbar_acceleration_color;
235 f = acceleration/autocvar_hud_panel_physics_acceleration_max;
236 if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear)
237 f = (f >= 0 ? sqrt(f) : -sqrt(-f));
239 if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
241 tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY;
243 if (acceleration_baralign == 1)
244 tmp_offset.x = panel_size.x - tmp_size.x;
245 else if (acceleration_baralign == 2 || acceleration_baralign == 3)
246 tmp_offset.x = (panel_size.x - tmp_size.x) / 2;
253 tmp_size = panel_size;
254 tmp_offset = '0 0 0';
257 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);
260 if(autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
262 tmp_size.x = panel_size.x;
263 tmp_size.y = panel_size.y * text_scale;
265 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
267 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);