From ee2632301ca8c3068048721974e8752a14cc0ca8 Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Fri, 2 Dec 2016 19:43:11 +0100 Subject: [PATCH] Fix fireBullet(), increase MAX_SHOT_DISTANCE Previously, when the nearest target was beyond MAX_SHOT_DISTANCE, the trace ended and the code assumed a wall was hit. It then proceeded to penetrate the non-existent wall up to g_ballistics_mindistance, dropping out of said wall and penetrating the next non-existent wall, repeatedly, until the weapon's solidpenetration was exhausted after going through 50 such walls with overkill's MG, resulting in massive FPS drops and lag spikes on large maps. Now, if nothing is hit, we just bail out immediately. Additionally, I increased MAX_SHOT_DISTANCE to make sure hitscan weapons like MG and vortex don't stop mid air even on large maps. --- qcsrc/common/weapons/weapon.qh | 3 ++- qcsrc/server/weapons/tracing.qc | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index b287b148f..b7a60df8a 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -175,7 +175,8 @@ ENDCLASS(OffhandWeapon) .OffhandWeapon offhand; #endif -const int MAX_SHOT_DISTANCE = 32768; +// distance from one corner of a 65536qu cube to the opposite corner is approx. 113512 qu +const int MAX_SHOT_DISTANCE = 120000; // weapon flags const int WEP_TYPE_OTHER = 0x00; // not for damaging people diff --git a/qcsrc/server/weapons/tracing.qc b/qcsrc/server/weapons/tracing.qc index b49ed88f5..2801971f2 100644 --- a/qcsrc/server/weapons/tracing.qc +++ b/qcsrc/server/weapons/tracing.qc @@ -399,6 +399,10 @@ void fireBullet(entity this, vector start, vector dir, float spread, float max_s start = trace_endpos; entity hit = trace_ent; + // traced up to MAX_SHOT_DISTANCE and didn't hit anything at all + if (trace_fraction == 1.0) + break; + // When hitting sky, stop. if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) break; -- 2.39.2