]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix fireBullet(), increase MAX_SHOT_DISTANCE
authorMartin Taibr <taibr.martin@gmail.com>
Fri, 2 Dec 2016 18:43:11 +0000 (19:43 +0100)
committerMartin Taibr <taibr.martin@gmail.com>
Fri, 2 Dec 2016 18:43:11 +0000 (19:43 +0100)
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
qcsrc/server/weapons/tracing.qc

index b287b148f3175727cebf8fa1e44a288099ae8e2b..b7a60df8abd2604639e3cb85ea0e8aa804f3ef85 100644 (file)
@@ -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
index b49ed88f596ca00a7ef4e6b3467b7e5a3f36c2e2..2801971f218bed2fb6d8d288e76a68ff23966bea 100644 (file)
@@ -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;