From 686bcce57e3129dc39a148d8329b9d8dec149ec4 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 2 Jun 2024 01:42:24 +0200 Subject: [PATCH] Reduce repeated operations in a few places, mostly in the slick detector loop of the strafehud --- qcsrc/client/hud/panel/strafehud.qc | 16 ++++++++-------- qcsrc/common/util.qc | 5 +++-- qcsrc/common/weapons/weapon/blaster.qc | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 057c2aadf..a9a8ce3aa 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -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) diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 76cedfd1e..1bc669d83 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -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); } diff --git a/qcsrc/common/weapons/weapon/blaster.qc b/qcsrc/common/weapons/weapon/blaster.qc index 3c134a3db..6ac1415df 100644 --- a/qcsrc/common/weapons/weapon/blaster.qc +++ b/qcsrc/common/weapons/weapon/blaster.qc @@ -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); -- 2.39.2