[quake3-commits] r1711 - trunk/code/client

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Oct 26 19:20:06 EDT 2009


Author: thilo
Date: 2009-10-26 19:20:05 -0400 (Mon, 26 Oct 2009)
New Revision: 1711

Modified:
   trunk/code/client/snd_openal.c
Log:
Make not playing loop sources weaker in priority, so if we have reached the maximum number of sources, inaudible loops are removed first.


Modified: trunk/code/client/snd_openal.c
===================================================================
--- trunk/code/client/snd_openal.c	2009-10-26 21:59:03 UTC (rev 1710)
+++ trunk/code/client/snd_openal.c	2009-10-26 23:20:05 UTC (rev 1711)
@@ -884,34 +884,60 @@
 	int weakest = -1;
 	int weakest_time = Sys_Milliseconds();
 	int weakest_pri = 999;
+	qboolean weakest_isplaying = qtrue;
+	int weakest_numloops = 0;
+	src_t *curSource;
 
 	for(i = 0; i < srcCount; i++)
 	{
+		curSource = &srcList[i];
+		
 		// If it's locked, we aren't even going to look at it
-		if(srcList[i].isLocked)
+		if(curSource->isLocked)
 			continue;
 
 		// Is it empty or not?
-		if((!srcList[i].isActive) && (empty == -1))
+		if(!curSource->isActive)
+		{
 			empty = i;
-		else if(srcList[i].priority < priority)
+			break;
+		}
+
+		if(curSource->isPlaying)
 		{
-			// If it's older or has lower priority, flag it as weak
-			if((srcList[i].priority < weakest_pri) ||
-				(srcList[i].lastUsedTime < weakest_time))
+			if(weakest_isplaying && curSource->priority < priority &&
+			   (curSource->priority < weakest_pri || curSource->lastUsedTime < weakest_time))
 			{
-				weakest_pri = srcList[i].priority;
-				weakest_time = srcList[i].lastUsedTime;
+				// If it's older or has lower priority, flag it as weak
+				weakest_pri = curSource->priority;
+				weakest_time = curSource->lastUsedTime;
 				weakest = i;
 			}
 		}
+		else
+		{
+			weakest_isplaying = qfalse;
+			
+			if(knownSfx[curSource->sfx].loopCnt > weakest_numloops ||
+			   curSource->priority < weakest_pri ||
+			   curSource->lastUsedTime < weakest_time)
+			{
+				// Sources currently not playing of course have lowest priority
+				// also try to always keep at least one loop master for every loop sound
+				weakest_pri = curSource->priority;
+				weakest_time = curSource->lastUsedTime;
+				weakest_numloops = knownSfx[curSource->sfx].loopCnt;
+				weakest = i;
+				weakest_isplaying = qfalse;
+			}
+		}
 
 		// The channel system is not actually adhered to by baseq3, and not
 		// implemented in snd_dma.c, so while the following is strictly correct, it
 		// causes incorrect behaviour versus defacto baseq3
 #if 0
 		// Is it an exact match, and not on channel 0?
-		if((srcList[i].entity == entnum) && (srcList[i].channel == channel) && (channel != 0))
+		if((curSource->entity == entnum) && (curSource->channel == channel) && (channel != 0))
 		{
 			S_AL_SrcKill(i);
 			return i;



More information about the quake3-commits mailing list