Make not playing loop sources weaker in priority, so if we have reached the maximum number of sources, inaudible loops are removed first.

This commit is contained in:
Thilo Schulz 2009-10-26 23:20:05 +00:00
parent 2fecf6d6bc
commit 0ecfcfa872

View file

@ -884,34 +884,60 @@ srcHandle_t S_AL_SrcAlloc( alSrcPriority_t priority, int entnum, int channel )
int weakest = -1; int weakest = -1;
int weakest_time = Sys_Milliseconds(); int weakest_time = Sys_Milliseconds();
int weakest_pri = 999; int weakest_pri = 999;
qboolean weakest_isplaying = qtrue;
int weakest_numloops = 0;
src_t *curSource;
for(i = 0; i < srcCount; i++) for(i = 0; i < srcCount; i++)
{ {
curSource = &srcList[i];
// If it's locked, we aren't even going to look at it // If it's locked, we aren't even going to look at it
if(srcList[i].isLocked) if(curSource->isLocked)
continue; continue;
// Is it empty or not? // Is it empty or not?
if((!srcList[i].isActive) && (empty == -1)) if(!curSource->isActive)
empty = i;
else if(srcList[i].priority < priority)
{ {
// If it's older or has lower priority, flag it as weak empty = i;
if((srcList[i].priority < weakest_pri) || break;
(srcList[i].lastUsedTime < weakest_time)) }
if(curSource->isPlaying)
{
if(weakest_isplaying && curSource->priority < priority &&
(curSource->priority < weakest_pri || curSource->lastUsedTime < weakest_time))
{ {
weakest_pri = srcList[i].priority; // If it's older or has lower priority, flag it as weak
weakest_time = srcList[i].lastUsedTime; weakest_pri = curSource->priority;
weakest_time = curSource->lastUsedTime;
weakest = i; 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 // 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 // implemented in snd_dma.c, so while the following is strictly correct, it
// causes incorrect behaviour versus defacto baseq3 // causes incorrect behaviour versus defacto baseq3
#if 0 #if 0
// Is it an exact match, and not on channel 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); S_AL_SrcKill(i);
return i; return i;