From 19b7f27fdb89d41559c1e3e98f81cb78379dfcf5 Mon Sep 17 00:00:00 2001 From: terencehill Date: Tue, 25 Jun 2024 23:00:29 +0200 Subject: [PATCH] Arc code cleanup: compact max_allowed_segments calculation --- qcsrc/common/weapons/weapon/arc.qc | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/qcsrc/common/weapons/weapon/arc.qc b/qcsrc/common/weapons/weapon/arc.qc index 02090a411..72b2c94ba 100644 --- a/qcsrc/common/weapons/weapon/arc.qc +++ b/qcsrc/common/weapons/weapon/arc.qc @@ -356,16 +356,12 @@ void W_Arc_Beam_Think(entity this) this.SendFlags |= ARC_SF_BEAMDIR; // calculate how many segments are needed - float max_allowed_segments; - + float max_allowed_segments = ARC_MAX_SEGMENTS; if(WEP_CVAR(arc, beam_distancepersegment)) { - max_allowed_segments = min( - ARC_MAX_SEGMENTS, - 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))) - ); + max_allowed_segments = 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))); + max_allowed_segments = bound(1, max_allowed_segments, ARC_MAX_SEGMENTS); } - else { max_allowed_segments = ARC_MAX_SEGMENTS; } if(WEP_CVAR(arc, beam_degreespersegment)) { @@ -1047,16 +1043,12 @@ void Draw_ArcBeam(entity this) } // calculate how many segments are needed - float max_allowed_segments; - + float max_allowed_segments = ARC_MAX_SEGMENTS; if(this.beam_distancepersegment) { - max_allowed_segments = min( - ARC_MAX_SEGMENTS, - 1 + (vlen(wantdir / this.beam_distancepersegment)) - ); + max_allowed_segments = 1 + (vlen(wantdir / this.beam_distancepersegment)); + max_allowed_segments = bound(1, max_allowed_segments, ARC_MAX_SEGMENTS); } - else { max_allowed_segments = ARC_MAX_SEGMENTS; } if(this.beam_degreespersegment) { @@ -1095,16 +1087,12 @@ void Draw_ArcBeam(entity this) float angle = vlen(wantdir - beamdir) * RAD2DEG; // calculate how many segments are needed - float max_allowed_segments; - + float max_allowed_segments = ARC_MAX_SEGMENTS; if(this.beam_distancepersegment) { - max_allowed_segments = min( - ARC_MAX_SEGMENTS, - 1 + (vlen(wantdir / this.beam_distancepersegment)) - ); + max_allowed_segments = 1 + (vlen(wantdir / this.beam_distancepersegment)); + max_allowed_segments = bound(1, max_allowed_segments, ARC_MAX_SEGMENTS); } - else { max_allowed_segments = ARC_MAX_SEGMENTS; } if(this.beam_degreespersegment) { -- 2.39.2