[quake3-commits] r1900 - trunk/code/qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Feb 23 13:09:18 EST 2011


Author: thilo
Date: 2011-02-23 13:09:17 -0500 (Wed, 23 Feb 2011)
New Revision: 1900

Modified:
   trunk/code/qcommon/common.c
   trunk/code/qcommon/net_ip.c
Log:
Make NET_Sleep wait 1ms less than requested, then busy-wait the last ms for better timeout precision.


Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c	2011-02-23 16:17:09 UTC (rev 1899)
+++ trunk/code/qcommon/common.c	2011-02-23 18:09:17 UTC (rev 1900)
@@ -2907,7 +2907,7 @@
 
 	int		msec, minMsec;
 	int		timeVal;
-	static int	lastTime = 0;
+	static int	lastTime = 0, bias = 0;
  
 	int		timeBeforeFirstEvents;
 	int		timeBeforeServer;
@@ -2953,18 +2953,14 @@
 				minMsec = 1;
 			
 			timeVal = com_frameTime - lastTime;
-			if(timeVal > minMsec)
-			{
-				// Adjust minMsec if previous frame took too long to render so
-				// that framerate is stable at the requested value.
-				timeVal -= minMsec;
-
-				if(timeVal > minMsec)
-					minMsec = 0;
-				else
-					minMsec -= timeVal;
-			}
+			bias += timeVal - minMsec;
 			
+			if(bias > minMsec)
+				bias = minMsec;
+			
+			// Adjust minMsec if previous frame took too long to render so
+			// that framerate is stable at the requested value.
+			minMsec -= bias;
 		}
 	}
 	else
@@ -2973,10 +2969,11 @@
 	timeVal = 0;
 	do
 	{
-		if(com_busyWait->integer)
+		// Busy sleep the last millisecond for better timeout precision
+		if(com_busyWait->integer || timeVal < 2)
 			NET_Sleep(0);
 		else
-			NET_Sleep(timeVal);
+			NET_Sleep(timeVal - 1);
 
 		msec = Sys_Milliseconds() - com_frameTime;
 		

Modified: trunk/code/qcommon/net_ip.c
===================================================================
--- trunk/code/qcommon/net_ip.c	2011-02-23 16:17:09 UTC (rev 1899)
+++ trunk/code/qcommon/net_ip.c	2011-02-23 18:09:17 UTC (rev 1900)
@@ -1707,18 +1707,9 @@
 	if(highestfd < 0)
 	{
 		// windows ain't happy when select is called without valid FDs
-	
-		if(msec > 0)
-			msec--;
-		
 		SleepEx(msec, 0);
 		return;
 	}
-
-	#define TVW32_BIAS 999
-	// windows adds a whole millisecond of latency, otherwise granularity seems to be fine.
-	if(timeout.tv_usec > TVW32_BIAS)
-		timeout.tv_usec -= TVW32_BIAS;
 #endif
 
 	retval = select(highestfd + 1, &fdr, NULL, NULL, &timeout);



More information about the quake3-commits mailing list