MCPcopy Create free account
hub / github.com/JACoders/OpenJK / S_PickChannel

Function S_PickChannel

code/client/snd_dma.cpp:1093–1160  ·  view source on GitHub ↗

================= S_PickChannel ================= */

Source from the content-addressed store, hash-verified

1091=================
1092*/
1093channel_t *S_PickChannel(int entnum, int entchannel)
1094{
1095 int ch_idx;
1096 channel_t *ch, *firstToDie;
1097 qboolean foundChan = qfalse;
1098
1099#ifdef USE_OPENAL
1100 if (s_UseOpenAL)
1101 return S_OpenALPickChannel(entnum, entchannel);
1102#endif
1103
1104 if ( entchannel<0 ) {
1105 Com_Error (ERR_DROP, "S_PickChannel: entchannel<0");
1106 }
1107
1108 // Check for replacement sound, or find the best one to replace
1109
1110 firstToDie = &s_channels[0];
1111
1112 for ( int pass = 0; (pass < ((entchannel == CHAN_AUTO || entchannel == CHAN_LESS_ATTEN)?1:2)) && !foundChan; pass++ )
1113 {
1114 for (ch_idx = 0, ch = &s_channels[0]; ch_idx < MAX_CHANNELS ; ch_idx++, ch++ )
1115 {
1116 if ( entchannel == CHAN_AUTO || entchannel == CHAN_LESS_ATTEN || pass > 0 )
1117 {//if we're on the second pass, just find the first open chan
1118 if ( !ch->thesfx )
1119 {//grab the first open channel
1120 firstToDie = ch;
1121 break;
1122 }
1123
1124 }
1125 else if ( ch->entnum == entnum && S_CheckChannelStomp( ch->entchannel, entchannel ) )
1126 {
1127 // always override sound from same entity
1128 if ( s_show->integer == 1 && ch->thesfx ) {
1129 Com_Printf( S_COLOR_YELLOW"...overrides %s\n", ch->thesfx->sSoundName );
1130 ch->thesfx = 0; //just to clear the next error msg
1131 }
1132 firstToDie = ch;
1133 foundChan = qtrue;
1134 break;
1135 }
1136
1137 // don't let anything else override local player sounds
1138 if ( ch->entnum == listener_number && entnum != listener_number && ch->thesfx) {
1139 continue;
1140 }
1141
1142 // don't override loop sounds
1143 if ( ch->loopSound ) {
1144 continue;
1145 }
1146
1147 if ( ch->startSample < firstToDie->startSample ) {
1148 firstToDie = ch;
1149 }
1150 }

Callers 4

S_StartAmbientSoundFunction · 0.70
S_StartSoundFunction · 0.70
S_AddLoopSoundsFunction · 0.70
UpdateLoopingSoundsFunction · 0.70

Calls 5

S_OpenALPickChannelFunction · 0.70
S_CheckChannelStompFunction · 0.70
Channel_ClearFunction · 0.70
Com_ErrorFunction · 0.50
Com_PrintfFunction · 0.50

Tested by

no test coverage detected