r5305 - trunk/data/qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Thu Dec 25 08:25:06 EST 2008


Author: div0
Date: 2008-12-25 08:25:06 -0500 (Thu, 25 Dec 2008)
New Revision: 5305

Modified:
   trunk/data/qcsrc/server/g_subs.qc
   trunk/data/qcsrc/server/w_common.qc
Log:
factor the ballistic bullet tracing into a separate inverted traceline function


Modified: trunk/data/qcsrc/server/g_subs.qc
===================================================================
--- trunk/data/qcsrc/server/g_subs.qc	2008-12-24 23:10:38 UTC (rev 5304)
+++ trunk/data/qcsrc/server/g_subs.qc	2008-12-25 13:25:06 UTC (rev 5305)
@@ -280,6 +280,58 @@
 	traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
 }
 
+void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent)
+{
+	vector pos, dir, t;
+	float nudge;
+
+	//nudge = 2 * cvar("collision_impactnudge"); // why not?
+	nudge = 0.5;
+
+	dir = normalize(v2 - v1);
+
+	pos = v1 + dir * nudge;
+
+	for(;;)
+	{
+		if((pos - v1) * dir >= (v2 - v1) * dir)
+		{
+			// went too far
+			trace_fraction = 1;
+			return;
+		}
+
+		traceline(pos, v2, nomonsters, forent);
+
+		if(trace_startsolid)
+		{
+			// we started inside solid.
+			// then trace from endpos to pos
+			t = trace_endpos;
+			traceline(t, pos, nomonsters, forent);
+			if(trace_startsolid)
+			{
+				// t is inside solid? bad
+				// force advance, then
+				pos = pos + dir * nudge;
+			}
+			else
+			{
+				// we actually LEFT solid!
+				trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
+				return;
+			}
+		}
+		else
+		{
+			// pos is outside solid?!? but why?!? never mind, just return it.
+			trace_endpos = pos;
+			trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
+			return;
+		}
+	}
+}
+
 /*
 ==================
 findbetterlocation

Modified: trunk/data/qcsrc/server/w_common.qc
===================================================================
--- trunk/data/qcsrc/server/w_common.qc	2008-12-24 23:10:38 UTC (rev 5304)
+++ trunk/data/qcsrc/server/w_common.qc	2008-12-25 13:25:06 UTC (rev 5305)
@@ -186,7 +186,6 @@
 {
 	// move the entity along its velocity until it's out of solid, then let it resume
 	
-	vector tracevel, org, skiporg, endorg, t;
 	float dt, dst, velfactor, v0, vs;
 	float maxdist;
 	float E0_m, Es_m;
@@ -202,50 +201,14 @@
 	if(maxdist <= 0.5)
 		return 0;
 
-	tracevel = normalize(vel);
+	traceline_inverted (self.origin, self.origin + normalize(vel) * maxdist, MOVE_NORMAL, self);
 
-	org = self.origin;
-	skiporg = org + tracevel;
-	endorg = org + tracevel * maxdist;
+	if(trace_fraction == 1) // 1: we never got out of solid
+		return 0;
 
-	for(;;)
-	{
-		traceline(skiporg, endorg, MOVE_NORMAL, self);
-		t = trace_endpos;
+	self.W_BallisticBullet_LeaveSolid_origin = trace_endpos;
 
-		if(trace_startsolid)
-		{
-			// good: skiporg is actually in solid
-			traceline(t, skiporg, MOVE_NORMAL, self);
-			t = trace_endpos;
-
-			if(trace_startsolid)
-			{
-				// we're stuck inside solid :(
-				// force advance by 1 unit, and retry
-				// CAN we go by 1 unit?
-				if(vlen(skiporg + tracevel - org) < maxdist)
-					skiporg = skiporg + tracevel;
-				else
-					return 0;
-			}
-			else
-			{
-				// we managed to leave solid
-				// so trace_endpos is good
-				self.W_BallisticBullet_LeaveSolid_origin = t;
-				break;
-			}
-		}
-		else
-		{
-			// bad: skiporg is outside solid. Then imagine it's alright.
-			self.W_BallisticBullet_LeaveSolid_origin = skiporg;
-			break;
-		}
-	}
-
-	dst = vlen(self.W_BallisticBullet_LeaveSolid_origin - org);
+	dst = vlen(trace_endpos - self.origin);
 	// E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
 	Es_m = E0_m - constant * dst;
 	if(Es_m <= 0)




More information about the nexuiz-commits mailing list