]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
strafehud: add slick detector
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sat, 4 Jul 2020 23:36:06 +0000 (01:36 +0200)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sat, 4 Jul 2020 23:36:06 +0000 (01:36 +0200)
_hud_common.cfg
qcsrc/client/autocvars.qh
qcsrc/client/hud/panel/strafehud.qc

index f011983776741bf659dba0b1d65cad9b2a7b4b87..88f9af8923193fe0f23e8d047c391cf0c4a48899 100644 (file)
@@ -150,6 +150,11 @@ seta hud_panel_strafehud_direction_color "0 0.5 1" "color of the direction caps
 seta hud_panel_strafehud_direction_alpha "1" "opacity of the direction caps which indicate the direction the player is currently strafing towards"
 seta hud_panel_strafehud_direction_width "0.25" "stroke width of the direction caps which indicate the direction the player is currently strafing towards (relative to the panel height)"
 seta hud_panel_strafehud_direction_length "0.02" "length of the horizontal component of the direction caps which indicate the direction the player is currently strafing towards (relative to the panel width)"
+seta hud_panel_strafehud_slickdetector_range "0" "range of the slick detector in qu, \"0\" to disable"
+seta hud_panel_strafehud_slickdetector_granularity "2" "value from 0 to 4 which defines how exact the search for slick should be, higher values may yield better results but require more computation"
+seta hud_panel_strafehud_slickdetector_color "0 1 1" "color of the slick detector indicator"
+seta hud_panel_strafehud_slickdetector_alpha "0.5" "opacity of the slick detector indicator"
+seta hud_panel_strafehud_slickdetector_height "0.125" "height of the slick detector indicator (relative to the panel height)"
 seta hud_panel_strafehud_timeout_air "0.1" "time after take off before changing to air strafe physics when not jumping (visually more consistent hud while on slick downwards ramps)"
 seta hud_panel_strafehud_timeout_ground "0.03333333" "time after landing before changing to non-air strafe physics (visually more consistent hud while strafe turning when touching the floor after every hop)"
 seta hud_panel_strafehud_timeout_turn "0.1" "time after releasing the strafe keys before changing mode (visually more consistent hud while switching between left/right strafe turning)"
index 63c2240458ed3816bbaf66ceb8c0bb27204d2728..753ff24d90f6731e7de922d4120563111f17b804 100644 (file)
@@ -348,6 +348,11 @@ vector autocvar_hud_panel_strafehud_direction_color = '0 0.5 1';
 float autocvar_hud_panel_strafehud_direction_alpha = 1;
 float autocvar_hud_panel_strafehud_direction_width = 0.25;
 float autocvar_hud_panel_strafehud_direction_length = 0.02;
+float autocvar_hud_panel_strafehud_slickdetector_range = 0;
+int autocvar_hud_panel_strafehud_slickdetector_granularity = 2;
+vector autocvar_hud_panel_strafehud_slickdetector_color = '0 1 1';
+float autocvar_hud_panel_strafehud_slickdetector_alpha = 0.5;
+float autocvar_hud_panel_strafehud_slickdetector_height = 0.125;
 float autocvar_hud_panel_strafehud_timeout_air = 0.1;
 float autocvar_hud_panel_strafehud_timeout_ground = 0.03333333;
 float autocvar_hud_panel_strafehud_timeout_turn = 0.1;
index e48462451ee5de39eb8b92d99f9daaa80411be39..d71318e7c1987ea50e8c0a3eafdbe35138ff5512 100644 (file)
@@ -137,6 +137,7 @@ void HUD_StrafeHUD()
         float  accelzone_width;
         float  overturn_offset;
         float  overturn_width;
+        float  slickdetector_height;
         vector direction_size_vertical       = '0 0 0';
         vector direction_size_horizontal     = '0 0 0';
         float  range_minangle;
@@ -556,6 +557,53 @@ void HUD_StrafeHUD()
             }
         }
 
+        slickdetector_height = panel_size.y * bound(0, autocvar_hud_panel_strafehud_slickdetector_height, 0.5);
+        if(autocvar_hud_panel_strafehud_slickdetector_range > 0 && autocvar_hud_panel_strafehud_slickdetector_alpha > 0 && slickdetector_height > 0 && panel_size.x > 0) // dunno if slick detection works in spectate
+        {
+            float slicksteps = 90 / pow(2, bound(0, autocvar_hud_panel_strafehud_slickdetector_granularity, 4));
+            vector slickoffset;
+            bool slickdetected = false;
+
+            slickdetected = IS_ONSLICK(strafeplayer); // don't need to traceline if already touching slick
+
+            // traceline into every direction
+            trace_dphitq3surfaceflags = 0;
+            for(float i = 0; i < 360 && !slickdetected; i += slicksteps)
+            {
+                float slickrotate;
+                slickoffset.z = -cos(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
+                slickrotate = sin(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
+                if(i != 0 && i != 180)
+                {
+                    for(float j = 0; j < 180 && !slickdetected; j += slicksteps)
+                    {
+                        slickoffset.x = sin(j * DEG2RAD) * slickrotate;
+                        slickoffset.y = cos(j * DEG2RAD) * slickrotate;
+
+                        traceline(strafeplayer.origin, strafeplayer.origin + slickoffset, MOVE_WORLDONLY, NULL);
+                        if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) slickdetected = true;
+                    }
+                }
+                else
+                {
+                    slickoffset.x = slickoffset.y = 0;
+                    traceline(strafeplayer.origin, strafeplayer.origin + slickoffset, MOVE_WORLDONLY, NULL);
+                    if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) slickdetected = true;
+                }
+            }
+
+            // if one traceline hit a slick surface
+            if(slickdetected)
+            {
+                vector slickdetector_size = panel_size;
+                slickdetector_size.y = slickdetector_height;
+                // top horizontal line
+                drawfill(panel_pos - eY * slickdetector_size.y, slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                // bottom horizontal line
+                drawfill(panel_pos + eY * panel_size.y, slickdetector_size, autocvar_hud_panel_strafehud_slickdetector_color, autocvar_hud_panel_strafehud_slickdetector_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+            }
+        }
+
         if(speed < (maxspeed + antiflicker_speed) && !immobile)
         {
             bestangle_anywhere = true; // moving forward should suffice to gain speed