]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
New Physics panel
authorterencehill <piuntn@gmail.com>
Wed, 1 Dec 2010 08:15:13 +0000 (09:15 +0100)
committerterencehill <piuntn@gmail.com>
Wed, 1 Dec 2010 08:15:13 +0000 (09:15 +0100)
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
defaultXonotic.cfg
hud_luminos.cfg
hud_nexuiz.cfg
qcsrc/client/autocvars.qh
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/common/constants.qh
qcsrc/common/util.qh

index 33d85443e37f424cb14ad6cb4b5b268df6a0d033..9ad7ce37a8ce767fa76fad5e14b1bbd83145704c 100644 (file)
@@ -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"
index 37288a0647d6e12d0909fe1a56f55f22c1db52a2..cbec66e3d16bb004c3da6e3a6043de7a5666fcc6 100644 (file)
@@ -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"
 
index 45e7231194265799c40a9097cae7ef569f661f5e..6f68796545d7cc3b6032440a7f816e34d4ea330e 100644 (file)
@@ -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
index 8345b5b2da6deef78c6488731bfb0984a1856a8a..ee076a0ad7b3825eb33a994353a4a6f6b0b7754e 100644 (file)
@@ -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
index c7ca054b62b122925411907f7a697f5d6c475716..b15644de049843bd8d7ae52593f0b4f1b8cd73c7 100644 (file)
@@ -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;
index f739a5108da2f357b45717e7401150546c0ecd45..bbe82993a2bc47c605b5b881c6ef69bd4fd55642 100644 (file)
@@ -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)
index 95fefe9f7c847b7c93f781c3cb4057354e126500..fc898ba642f23fb7602dd66d688651609f8ddd61 100644 (file)
@@ -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)
index 8cc24634c307d7d929f376e068f21412f958d589..5c6fe1da75d452d0e93bb38c04d13b63762294c6 100644 (file)
@@ -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;
 
index cfb955e3566cb44d576ab6b09963eed1fe79c1b2..f46dc6535db74dc51a8e55938ee6dd85c0128e23 100644 (file)
@@ -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