]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reduce repeated operations in a few places, mostly in the slick detector loop of...
authorterencehill <piuntn@gmail.com>
Sat, 1 Jun 2024 23:42:24 +0000 (01:42 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 1 Jun 2024 23:42:24 +0000 (01:42 +0200)
qcsrc/client/hud/panel/strafehud.qc
qcsrc/common/util.qc
qcsrc/common/weapons/weapon/blaster.qc

index 057c2aadf2a581da59c88fd47a4b751a58de324c..a9a8ce3aa92377f1285ee571b37aa8dfa2074a55 100644 (file)
@@ -786,27 +786,27 @@ void HUD_StrafeHUD()
 
                        if(!autocvar_hud_panel_strafehud_uncapped)
                                slicksteps = min(slicksteps, 4);
-                       slicksteps = 90 / 2 ** slicksteps;
+                       slicksteps = 90 * DEG2RAD / 2 ** slicksteps;
 
                        slickdetected = real_onslick; // don't need to traceline if already touching slick
 
                        // traceline into every direction
                        trace_dphitq3surfaceflags = 0;
                        vector traceorigin = strafeplayer.origin + eZ * strafeplayer.mins.z;
-                       for(float i = 0; i < 90 && !slickdetected; i += slicksteps)
+                       for(float i = 0; i < 90 * DEG2RAD - 0.00001 && !slickdetected; i += slicksteps)
                        {
                                vector slickoffset;
                                float slickrotate;
-                               slickoffset.z = -cos(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
-                               slickrotate = sin(i * DEG2RAD) * autocvar_hud_panel_strafehud_slickdetector_range;
+                               slickoffset.z = -cos(i) * autocvar_hud_panel_strafehud_slickdetector_range;
+                               slickrotate = sin(i) * autocvar_hud_panel_strafehud_slickdetector_range;
 
-                               for(float j = 0; j < 360 && !slickdetected; j += slicksteps)
+                               for(float j = 0; j < 360 * DEG2RAD - 0.00001 && !slickdetected; j += slicksteps)
                                {
-                                       slickoffset.x = sin(j * DEG2RAD) * slickrotate;
-                                       slickoffset.y = cos(j * DEG2RAD) * slickrotate;
+                                       slickoffset.x = sin(j) * slickrotate;
+                                       slickoffset.y = cos(j) * slickrotate;
 
                                        traceline(traceorigin, traceorigin + slickoffset, MOVE_NOMONSTERS, strafeplayer);
-                                       if((PHYS_FRICTION(strafeplayer) == 0 && trace_fraction < 1) 
+                                       if((PHYS_FRICTION(strafeplayer) == 0 && trace_fraction < 1)
                                        || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK))
                                                slickdetected = true;
                                        if(i == 0)
index 76cedfd1ebb598f5c3d28f96fb8cc8870898cce5..1bc669d83777665b334990e6aa2e566a33536efe 100644 (file)
@@ -459,8 +459,9 @@ vector decompressShortVector(int data)
        {
                q = M_PI / 16 * q;
                p = M_PI / 16 * p - M_PI_2;
-               out.x = cos(q) *  cos(p);
-               out.y = sin(q) *  cos(p);
+               float cos_p = cos(p);
+               out.x = cos(q) *  cos_p;
+               out.y = sin(q) *  cos_p;
                out.z =          -sin(p);
        }
 
index 3c134a3db37b85bb21848a322098b4ba81ba7c19..6ac1415df865dde8258f32fdacc7b9a15c723219 100644 (file)
@@ -45,9 +45,9 @@ void W_Blaster_Attack(
        float atk_deathtype)
 {
        bool isprimary = !(atk_deathtype & HITTYPE_SECONDARY);
-       float atk_shotangle = WEP_CVAR_BOTH(blaster, isprimary, shotangle);
+       float atk_shotangle_rad = WEP_CVAR_BOTH(blaster, isprimary, shotangle) * DEG2RAD;
        float atk_damage = WEP_CVAR_BOTH(blaster, isprimary, damage);
-       vector s_forward = v_forward * cos(atk_shotangle * DEG2RAD) + v_up * sin(atk_shotangle * DEG2RAD);
+       vector s_forward = v_forward * cos(atk_shotangle_rad) + v_up * sin(atk_shotangle_rad);
 
        W_SetupShot_Dir(actor, weaponentity, s_forward, false, 3, SND_LASERGUN_FIRE, CH_WEAPON_B, atk_damage, atk_deathtype);
        W_MuzzleFlash(WEP_BLASTER, actor, weaponentity, w_shotorg, w_shotdir);