From b77c6baee52243d0f70d8d6f66697335ae7e1eaa Mon Sep 17 00:00:00 2001 From: terencehill Date: Wed, 1 Dec 2010 09:15:13 +0100 Subject: [PATCH] New Physics panel It shows: - speed progressbar - top speed (a slightly improved version of showtopspeed); it leaves a peek on the speed progressbar - acceleration progressbar --- _hud_descriptions.cfg | 16 +++ defaultXonotic.cfg | 9 ++ hud_luminos.cfg | 18 +++- hud_nexuiz.cfg | 18 +++- qcsrc/client/autocvars.qh | 2 + qcsrc/client/hud.qc | 218 +++++++++++++++++++++++++++++++++++++- qcsrc/client/hud.qh | 22 +++- qcsrc/common/constants.qh | 4 +- qcsrc/common/util.qh | 1 + 9 files changed, 297 insertions(+), 11 deletions(-) diff --git a/_hud_descriptions.cfg b/_hud_descriptions.cfg index 33d85443e..9ad7ce37a 100644 --- a/_hud_descriptions.cfg +++ b/_hud_descriptions.cfg @@ -21,6 +21,9 @@ seta hud_progressbar_health_color "" "R G B vector of the progress bar backgroun seta hud_progressbar_armor_color "" "R G B vector of the progress bar background color" seta hud_progressbar_fuel_color "" "R G B vector of the progress bar background color" seta hud_progressbar_nexball_color "" "R G B vector of the progress bar background color" +seta hud_progressbar_speed_color "" "R G B vector of the progress bar background color" +seta hud_progressbar_acceleration_color "" "R G B vector of the progress bar background color" +seta hud_progressbar_acceleration_neg_color "" "R G B vector of the progress bar background color" seta _hud_panelorder "" "contains order in which panels are to be drawn" @@ -203,3 +206,16 @@ seta hud_panel_infomessages_bg_alpha "" "if set to something else than \"\" = ov seta hud_panel_infomessages_bg_border "" "if set to something else than \"\" = override default size of border around the background" seta hud_panel_infomessages_bg_padding "" "if set to something else than \"\" = override default padding of contents from border" seta hud_panel_infomessages_flip "" "1 = align the items to the right" + +seta hud_panel_physics "" "enable/disable this panel +seta hud_panel_physics_pos "" "position of this base of the panel" +seta hud_panel_physics_size "" "size of this panel" +seta hud_panel_physics_bg "" "if set to something else than \"\" = override default background" +seta hud_panel_physics_bg_color "" "if set to something else than \"\" = override default panel background color" +seta hud_panel_physics_bg_color_team "" "override panel color with team color in team based games" +seta hud_panel_physics_bg_alpha "" "if set to something else than \"\" = override default panel background alpha" +seta hud_panel_physics_bg_border "" "if set to something else than \"\" = override default size of border around the background" +seta hud_panel_physics_bg_padding "" "if set to something else than \"\" = override default padding of contents from border" +seta hud_panel_physics_baralign "" "1 = align bars to the right" +seta hud_panel_physics_flip "" "flip speed/acceleration positions" +seta hud_panel_physics_progressbar "" "enable progressbar in panel" diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 37288a064..cbec66e3d 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1366,6 +1366,15 @@ seta hud_panel_engineinfo_framecounter_exponentialmovingaverage 1 "use an averag seta hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight 0.1 "weight of latest data point" seta hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold 0.5 "threshold for fps change when to update instantly, to make big fps changes update faster" +seta hud_panel_physics_speed_unit 3 "speed unit (1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots)" +seta hud_panel_physics_speed_unit_show 1 "also show speed unit" +seta hud_panel_physics_speed_max 1800 "speed progressbar gets filled up completely by this value (in qu/s)" +seta hud_panel_physics_speed_z 0 "include the speed on the Z-axis" +seta hud_panel_physics_topspeed 1 "also show top speed" +seta hud_panel_physics_topspeed_time 4 "how many seconds the top speed takes to fade out" +seta hud_panel_physics_acceleration_max 2 "acceleration progressbar gets filled up completely by this value" +seta hud_panel_physics_acceleration_z 0 "include the acceleration on the Z-axis" + seta hud_showbinds 1 "the way to show the keys to press in HUD messages: 0 displays commands, 1 bound keys, 2 both" seta hud_showbinds_limit 2 "maximum number of bound keys to show for a command. 0 for unlimited" diff --git a/hud_luminos.cfg b/hud_luminos.cfg index 45e723119..6f6879654 100644 --- a/hud_luminos.cfg +++ b/hud_luminos.cfg @@ -19,8 +19,11 @@ seta hud_progressbar_health_color "0.6 0 0" seta hud_progressbar_armor_color "0 0.6 0" seta hud_progressbar_fuel_color "0.6 0.6 0" seta hud_progressbar_nexball_color "0.7 0.1 0" +seta hud_progressbar_speed_color "1 0.75 0" +seta hud_progressbar_acceleration_color "0.5 0.75 1" +seta hud_progressbar_acceleration_neg_color "0.125 0.25 0.5" -seta _hud_panelorder "10 9 6 8 14 5 0 4 13 2 7 1 3 11 12 " +seta _hud_panelorder "10 9 6 8 14 5 0 4 13 2 7 1 3 11 12 15 " seta hud_configure_grid "1" seta hud_configure_grid_xsize "0.010000" @@ -202,4 +205,17 @@ seta hud_panel_infomessages_bg_border "" seta hud_panel_infomessages_bg_padding "0" seta hud_panel_infomessages_flip "1" +seta hud_panel_physics 0 +seta hud_panel_physics_pos "0.410000 0.590000" +seta hud_panel_physics_size "0.180000 0.100000" +seta hud_panel_physics_bg "" +seta hud_panel_physics_bg_color "" +seta hud_panel_physics_bg_color_team "" +seta hud_panel_physics_bg_alpha "" +seta hud_panel_physics_bg_border "" +seta hud_panel_physics_bg_padding "" +seta hud_panel_physics_flip "0" +seta hud_panel_physics_baralign "0" +seta hud_panel_physics_progressbar "1" + menu_sync diff --git a/hud_nexuiz.cfg b/hud_nexuiz.cfg index 8345b5b2d..ee076a0ad 100644 --- a/hud_nexuiz.cfg +++ b/hud_nexuiz.cfg @@ -19,8 +19,11 @@ seta hud_progressbar_health_color "0.6 0 0" seta hud_progressbar_armor_color "0 0.6 0" seta hud_progressbar_fuel_color "0.6 0.6 0" seta hud_progressbar_nexball_color "0.7 0.1 0" +seta hud_progressbar_speed_color "1 0.5 0.75" +seta hud_progressbar_acceleration_color "0.5 1 0.75" +seta hud_progressbar_acceleration_neg_color "0.5 0.75 1" -seta _hud_panelorder "0 11 8 5 6 14 9 13 7 2 3 1 10 12 4 " +seta _hud_panelorder "0 11 8 5 6 14 9 13 7 2 3 1 10 12 4 15 " seta hud_configure_grid "1" seta hud_configure_grid_xsize "0.01" @@ -202,4 +205,17 @@ seta hud_panel_infomessages_bg_border "" seta hud_panel_infomessages_bg_padding "" seta hud_panel_infomessages_flip "1" +seta hud_panel_physics 0 +seta hud_panel_physics_pos "0.430000 0.640000" +seta hud_panel_physics_size "0.140000 0.100000" +seta hud_panel_physics_bg "0" +seta hud_panel_physics_bg_color "" +seta hud_panel_physics_bg_color_team "" +seta hud_panel_physics_bg_alpha "" +seta hud_panel_physics_bg_border "" +seta hud_panel_physics_bg_padding "" +seta hud_panel_physics_flip "0" +seta hud_panel_physics_baralign "0" +seta hud_panel_physics_progressbar "1" + menu_sync diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index c7ca054b6..b15644de0 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -64,6 +64,8 @@ var float autocvar_hud_panel_engineinfo; var float autocvar_hud_panel_infomessages; var float autocvar_hud_panel_infomessages_flip; +var float autocvar_hud_panel_physics; + var float autocvar_scoreboard_border_thickness; var float autocvar_cl_allow_uid2name; diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index f739a5108..bbe82993a 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -520,6 +520,11 @@ void HUD_Panel_ExportCfg(string cfgname) case HUD_PANEL_INFOMESSAGES: HUD_Write_PanelCvar_q("_flip"); break; + case HUD_PANEL_PHYSICS: + HUD_Write_PanelCvar_q("_flip"); + HUD_Write_PanelCvar_q("_baralign"); + HUD_Write_PanelCvar_q("_progressbar"); + break; } HUD_Write("\n"); } @@ -4852,6 +4857,213 @@ void HUD_InfoMessages(void) } } +// Physics panel (#15) +// +vector acc_prevspeed; +float acc_prevtime, acc_avg, top_speed, top_speed_time; + +void HUD_Physics(void) +{ + if(!autocvar_hud_panel_physics && !autocvar__hud_configure) + return; + + active_panel = HUD_PANEL_PHYSICS; + HUD_Panel_UpdateCvars(physics); + vector pos, mySize; + pos = panel_pos; + mySize = panel_size; + + HUD_Panel_DrawBg(1); + if(panel_bg_padding) + { + pos += '1 1 0' * panel_bg_padding; + mySize -= '2 2 0' * panel_bg_padding; + } + + //compute speed + float speed, conversion_factor; + string zspeed, unit; + + switch(cvar("hud_panel_physics_speed_unit")) + { + default: + case 1: + unit = "qu/s"; + conversion_factor = 1.0; + break; + case 2: + unit = "m/s"; + conversion_factor = 0.0254; + break; + case 3: + unit = "km/h"; + conversion_factor = 0.0254 * 3.6; + break; + case 4: + unit = "mph"; + conversion_factor = 0.0254 * 3.6 * 0.6213711922; + break; + case 5: + unit = "knots"; + conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h + break; + } + + float max_speed = floor( cvar("hud_panel_physics_speed_max") * conversion_factor + 0.5 ); + if (autocvar__hud_configure) + speed = floor( max_speed * 0.65 + 0.5 ); + else if(cvar("hud_panel_physics_speed_z")) + speed = floor( vlen(pmove_vel) * conversion_factor + 0.5 ); + else + speed = floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 ); + + //compute acceleration + float acceleration, f; + float max_acceleration = cvar("hud_panel_physics_acceleration_max"); + if (autocvar__hud_configure) + acceleration = max_acceleration * 0.3; + else + { + f = time - acc_prevtime; + if(cvar("hud_panel_physics_acceleration_z")) + acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f); + else + acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f); + acc_prevspeed = pmove_vel; + acc_prevtime = time; + + f = bound(0, f * 10, 1); + acc_avg = acc_avg * (1 - f) + acceleration * f; + acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED); + } + + //compute layout + drawfont = hud_bigfont; + float baralign = cvar("hud_panel_physics_baralign"); + float progressbar = cvar("hud_panel_physics_progressbar"); + float panel_ar = mySize_x/mySize_y; + vector speed_offset, acceleration_offset; + if (panel_ar >= 5) + { + mySize_x *= 0.5; + if (cvar("hud_panel_physics_flip")) + speed_offset_x = mySize_x; + else + acceleration_offset_x = mySize_x; + } + else + { + mySize_y *= 0.5; + if (cvar("hud_panel_physics_flip")) + speed_offset_y = mySize_y; + else + acceleration_offset_y = mySize_y; + } + float speed_baralign, acceleration_baralign; + if (cvar("hud_panel_physics_flip")) + { + acceleration_baralign = (baralign == 1 || baralign == 2); + speed_baralign = (baralign == 1 || baralign == 3); + } + else + { + speed_baralign = (baralign == 1 || baralign == 2); + acceleration_baralign = (baralign == 1 || baralign == 3); + } + + //draw speed + if(speed && progressbar) + { + HUD_Panel_GetProgressBarColor(speed); + HUD_Panel_DrawProgressBar(pos + speed_offset, mySize, speed/max_speed, 0, speed_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + + vector tmp_offset, tmp_size; + tmp_size_x = mySize_x * 0.75; + tmp_size_y = mySize_y; + if (speed_baralign) + tmp_offset_x = mySize_x - tmp_size_x; + //else + //tmp_offset_x = 0; + drawstring_aspect(pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); + + //draw speed unit + if (speed_baralign) + tmp_offset_x = 0; + else + tmp_offset_x = tmp_size_x; + if (cvar("hud_panel_physics_speed_unit_show")) + { + //tmp_offset_y = 0; + tmp_size_x = mySize_x * (1 - 0.75); + tmp_size_y = mySize_y * 0.4; + drawstring_aspect(pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); + } + + //compute and draw top speed + if (cvar("hud_panel_physics_topspeed")) + { + if (autocvar__hud_configure) + { + top_speed = floor( max_speed * 0.75 + 0.5 ); + f = 1; + } + else + { + if (speed >= top_speed) + { + top_speed = speed; + top_speed_time = time; + } + if (top_speed == 0) //hide top speed 0, it would be stupid + f = 0; + else + { + f = max(1, cvar("hud_panel_physics_topspeed_time")); + // divide by f to make it start from 1 + f = cos( ((time - top_speed_time) / f) * PI/2 ); + } + } + if (f > 0) + { + //top speed progressbar peek + if(progressbar && speed < top_speed) + { + float peek_offset_x, peek_size_x; + if (speed_baralign) + peek_offset_x = (1 - min(top_speed, max_speed)/max_speed) * mySize_x; + else + peek_offset_x = min(top_speed, max_speed)/max_speed * mySize_x; + //if speed is not 0 the speed progressbar already fetched the color + if (speed == 0) + HUD_Panel_GetProgressBarColor(speed); + peek_size_x = mySize_x * 0.01; + drawfill(pos + speed_offset + eX * (peek_offset_x - peek_size_x), eX * peek_size_x + eY * mySize_y, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + + //top speed + tmp_offset_y = mySize_y * 0.4; + tmp_size_x = mySize_x * (1 - 0.75); + tmp_size_y = mySize_y - tmp_offset_y; + drawstring_aspect(pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL); + } + else + top_speed = 0; + } + + //draw acceleration + if(acceleration && progressbar) + { + if (acceleration < 0) + HUD_Panel_GetProgressBarColor(acceleration_neg); + else + HUD_Panel_GetProgressBarColor(acceleration); + HUD_Panel_DrawProgressBar(pos + acceleration_offset, mySize, fabs(acceleration)/max_acceleration, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + drawstring_aspect(pos + acceleration_offset, ftos_decimals(acceleration, 3), mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); + drawfont = hud_font; +} + /* ================== Main HUD system @@ -4909,10 +5121,6 @@ void HUD_ShowSpeed(void) drawfont = hud_font; } -vector acc_prevspeed; -float acc_prevtime; -float acc_avg; - void HUD_ShowAcceleration(void) { float acceleration, sz, scale, alpha, f; @@ -5000,6 +5208,8 @@ switch (id) {\ HUD_EngineInfo(); break;\ case (HUD_PANEL_INFOMESSAGES):\ HUD_InfoMessages(); break;\ + case (HUD_PANEL_PHYSICS):\ + HUD_Physics(); break;\ } ENDS_WITH_CURLY_BRACE void HUD_Main (void) diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 95fefe9f7..fc898ba64 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -98,6 +98,9 @@ switch(item) {\ case "shield": HUD_Panel_GetProgressBarColor(shield); break;\ case "fuel": HUD_Panel_GetProgressBarColor(fuel); break;\ case "nexball": HUD_Panel_GetProgressBarColor(nexball); break;\ + case "speed": HUD_Panel_GetProgressBarColor(speed); break;\ + case "acceleration": HUD_Panel_GetProgressBarColor(acceleration); break;\ + case "acceleration_neg": HUD_Panel_GetProgressBarColor(acceleration_neg); break;\ } ENDS_WITH_CURLY_BRACE // Get value for panel_bg: if "" fetch default, else use panel_bg_str @@ -270,6 +273,12 @@ if(menu_enabled == 2 && active_panel == highlightedPanel) {\ } ENDS_WITH_CURLY_BRACE // Update all common cvars of given panel id +#define HUD_Panel_UpdateCvarsForId_Part2(id) \ +switch(id) { \ + case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdateCvars(infomessages) break; \ + case HUD_PANEL_PHYSICS: HUD_Panel_UpdateCvars(physics); break;\ +} + #define HUD_Panel_UpdateCvarsForId(id) \ switch(id) { \ case HUD_PANEL_WEAPONS: HUD_Panel_UpdateCvars(weapons) break; \ @@ -286,8 +295,8 @@ switch(id) { \ case HUD_PANEL_PRESSEDKEYS: HUD_Panel_UpdateCvars(pressedkeys) break; \ case HUD_PANEL_CHAT: HUD_Panel_UpdateCvars(chat) break; \ case HUD_PANEL_ENGINEINFO: HUD_Panel_UpdateCvars(engineinfo) break; \ - case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdateCvars(infomessages) break; \ -} +}\ +HUD_Panel_UpdateCvarsForId_Part2(id) #define HUD_Panel_UpdatePosSize(name) \ panel_pos = stov(cvar_string("hud_panel_" #name "_pos")); \ @@ -301,6 +310,11 @@ panel_bg_border_str = cvar_string("hud_panel_" #name "_bg_border"); \ HUD_Panel_GetBorder() // Update pos and size of given panel id +#define HUD_Panel_UpdatePosSizeForId_Part2(id) \ +switch(id) { \ + case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdatePosSize(infomessages) break;\ + case HUD_PANEL_PHYSICS: HUD_Panel_UpdatePosSize(physics); break;\ +} #define HUD_Panel_UpdatePosSizeForId(id) \ switch(id) { \ case HUD_PANEL_WEAPONS: HUD_Panel_UpdatePosSize(weapons) break;\ @@ -317,5 +331,5 @@ switch(id) { \ case HUD_PANEL_PRESSEDKEYS: HUD_Panel_UpdatePosSize(pressedkeys) break;\ case HUD_PANEL_CHAT: HUD_Panel_UpdatePosSize(chat) break;\ case HUD_PANEL_ENGINEINFO: HUD_Panel_UpdatePosSize(engineinfo) break;\ - case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdatePosSize(infomessages)\ -} +}\ +HUD_Panel_UpdatePosSizeForId_Part2(id) diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 8cc24634c..5c6fe1da7 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -628,7 +628,8 @@ float HUD_PANEL_PRESSEDKEYS = 11; float HUD_PANEL_CHAT = 12; float HUD_PANEL_ENGINEINFO = 13; float HUD_PANEL_INFOMESSAGES = 14; -float HUD_PANEL_NUM = 15; // always last panel id + 1, please increment when adding a new panel +float HUD_PANEL_PHYSICS = 15; +float HUD_PANEL_NUM = 16; // always last panel id + 1, please increment when adding a new panel string HUD_PANELNAME_WEAPONS = "weapons"; string HUD_PANELNAME_AMMO = "ammo"; @@ -645,6 +646,7 @@ string HUD_PANELNAME_PRESSEDKEYS = "pressedkeys"; string HUD_PANELNAME_CHAT = "chat"; string HUD_PANELNAME_ENGINEINFO = "engineinfo"; string HUD_PANELNAME_INFOMESSAGES = "infomessages"; +string HUD_PANELNAME_PHYSICS = "physics"; float HUD_MENU_ENABLE = 0; diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index cfb955e35..f46dc6535 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -219,6 +219,7 @@ float get_model_parameters(string mod, float skn); // call with string_null to c switch(id) {\ case HUD_PANEL_ENGINEINFO: panel_name = HUD_PANELNAME_ENGINEINFO; break; \ case HUD_PANEL_INFOMESSAGES: panel_name = HUD_PANELNAME_INFOMESSAGES; break; \ + case HUD_PANEL_PHYSICS: panel_name = HUD_PANELNAME_PHYSICS; break; \ } ENDS_WITH_CURLY_BRACE // Get name of specified panel id -- 2.39.2