/* * SF_FindName */ static sfx_t *SF_FindName( const char *name ) { int i; sfx_t *sfx; if( !name ) S_Error( "SF_FindName: NULL" ); if( !name[0] != '\0' ) { assert( name[0] != '\0' ); S_Error( "SF_FindName: empty name" ); } if( strlen( name ) >= MAX_QPATH ) S_Error( "Sound name too long: %s", name ); // see if already loaded for( i = 0; i < num_sfx; i++ ) { if( !strcmp( known_sfx[i].name, name ) ) return &known_sfx[i]; } // find a free sfx for( i = 0; i < num_sfx; i++ ) { if( !known_sfx[i].name[0] ) break; } if( i == num_sfx ) { if( num_sfx == MAX_SFX ) S_Error( "S_FindName: out of sfx_t" ); num_sfx++; } sfx = &known_sfx[i]; memset( sfx, 0, sizeof( *sfx ) ); Q_strncpyz( sfx->name, name, sizeof( sfx->name ) ); sfx->isUrl = trap_FS_IsUrl( name ); return sfx; }
static sfx_t *buffer_find_free( void ) { int i; for( i = 0; i < MAX_SFX; i++ ) { if( knownSfx[i].filename[0] == '\0' ) return &knownSfx[i]; } S_Error( "Sound Limit Exceeded.\n" ); return NULL; }
/* * S_PickChannel * * Picks a channel based on priorities, empty slots, number of channels */ channel_t *S_PickChannel( int entnum, int entchannel ) { int ch_idx; int first_to_die; int life_left; channel_t *ch; if( entchannel < 0 ) S_Error( "S_PickChannel: entchannel < 0" ); // Check for replacement sound, or find the best one to replace first_to_die = -1; life_left = 0x7fffffff; for( ch_idx = 0; ch_idx < MAX_CHANNELS; ch_idx++ ) { if( entchannel != 0 // channel 0 never overrides && channels[ch_idx].entnum == entnum && channels[ch_idx].entchannel == entchannel ) { // always override sound from same entity first_to_die = ch_idx; break; } // don't let monster sounds override player sounds // wsw: Medar: Disabled. Don't wanna use cl.playernum much in client code, because of chasecam and stuff //if (channels[ch_idx].entnum == cl.playernum+1 && entnum != cl.playernum+1 && channels[ch_idx].sfx) // continue; if( channels[ch_idx].end < life_left + paintedtime ) { life_left = channels[ch_idx].end - paintedtime; first_to_die = ch_idx; } } if( first_to_die == -1 ) return NULL; ch = &channels[first_to_die]; memset( ch, 0, sizeof( *ch ) ); return ch; }