r4565 - trunk/data/qcsrc/client

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Oct 1 02:06:36 EDT 2008


Author: div0
Date: 2008-10-01 02:06:36 -0400 (Wed, 01 Oct 2008)
New Revision: 4565

Added:
   trunk/data/qcsrc/client/interpolate.qc
   trunk/data/qcsrc/client/interpolate.qh
Log:
forgot this


Added: trunk/data/qcsrc/client/interpolate.qc
===================================================================
--- trunk/data/qcsrc/client/interpolate.qc	                        (rev 0)
+++ trunk/data/qcsrc/client/interpolate.qc	2008-10-01 06:06:36 UTC (rev 4565)
@@ -0,0 +1,78 @@
+// FIXME make this generic code, to be used for other entities too?
+.vector iorigin1, iorigin2;
+.vector ivelocity1, ivelocity2;
+.vector iforward1, iforward2;
+.vector iright1, iright2;
+.float itime1, itime2;
+void InterpolateOrigin_Note()
+{
+	float dt;
+
+	dt = time - self.itime1;
+
+	self.iorigin1 = self.iorigin2;
+	self.iorigin2 = self.origin;
+
+	if(self.iflags & IFLAG_ANGLES)
+	{
+		fixedmakevectors(self.angles);
+		self.iforward1 = self.iforward2;
+		self.iright1 = self.iright2;
+		self.iforward2 = v_forward;
+		self.iright2 = v_right;
+	}
+
+	if(self.iflags & IFLAG_VELOCITY)
+	{
+		self.ivelocity1 = self.ivelocity2;
+		self.ivelocity2 = self.velocity;
+	}
+
+	if(vlen(self.iorigin2 - self.iorigin1) > 1000)
+	{
+		self.itime1 = self.itime2 = time; // don't lerp
+	}
+
+	if((self.iflags & IFLAG_VELOCITY) && (vlen(self.ivelocity2 - self.ivelocity1) > 1000))
+	{
+		self.itime1 = self.itime2 = time; // don't lerp
+	}
+
+	if(dt < 0.2)
+	{
+		self.itime1 = time;
+		self.itime2 = time + getstatf(STAT_SYS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
+	}
+	else
+	{
+		// don't lerp
+		self.itime1 = self.itime2 = time;
+	}
+}
+void InterpolateOrigin_Do()
+{
+	vector forward, right;
+	if(self.itime1 && self.itime2 && self.itime1 != self.itime2)
+	{
+		float f;
+		f = bound(0, (time - self.itime1) / (self.itime2 - self.itime1), 1);
+		self.origin = (1 - f) * self.iorigin1 + f * self.iorigin2;
+		if(self.iflags & IFLAG_ANGLES)
+		{
+			forward = (1 - f) * self.iforward1 + f * self.iforward2;
+			right = (1 - f) * self.iright1 + f * self.iright2;
+			self.angles = fixedvectoangles2(forward, right);
+		}
+		if(self.iflags & IFLAG_VELOCITY)
+			self.velocity = (1 - f) * self.ivelocity1 + f * self.ivelocity2;
+	}
+}
+void InterpolateOrigin_Undo()
+{
+	self.origin = self.iorigin2;
+	if(self.iflags & IFLAG_ANGLES)
+		self.angles = fixedvectoangles2(self.iforward2, self.iright2);
+	if(self.iflags & IFLAG_VELOCITY)
+		self.velocity = self.ivelocity2;
+}
+

Added: trunk/data/qcsrc/client/interpolate.qh
===================================================================
--- trunk/data/qcsrc/client/interpolate.qh	                        (rev 0)
+++ trunk/data/qcsrc/client/interpolate.qh	2008-10-01 06:06:36 UTC (rev 4565)
@@ -0,0 +1,12 @@
+.float iflags;
+#define IFLAG_VELOCITY 1
+#define IFLAG_ANGLES 2
+
+// call this BEFORE reading an entity update
+void InterpolateOrigin_Undo();
+
+// call this AFTER receiving an entity update
+void InterpolateOrigin_Note();
+
+// call this BEFORE drawing
+void InterpolateOrigin_Do();




More information about the nexuiz-commits mailing list