if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/cdtracks/%s.wav", trackname);
if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/cdtracks/%s.ogg", trackname);
}
- if (FS_FileExists(filename) && (sfx = S_PrecacheSound (filename, false, false)))
+ if (FS_FileExists(filename) && (sfx = S_PrecacheSound (filename, false, true)))
{
faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0);
if (faketrack != -1)
cls.qw_downloadtype = dl_none;
- // load new sounds and unload old ones
- // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
- S_ServerSounds(cl.sound_name, cls.qw_downloadnumber);
+ // clear sound usage flags for purging of unused sounds
+ S_ClearUsed();
// precache any sounds used by the client
cl.sfx_wizhit = S_PrecacheSound(cl_sound_wizardhit.string, false, true);
cl.sfx_ric3 = S_PrecacheSound(cl_sound_ric3.string, false, true);
cl.sfx_r_exp3 = S_PrecacheSound(cl_sound_r_exp3.string, false, true);
- // sounds
+ // sounds used by the game
for (i = 1;i < MAX_SOUNDS && cl.sound_name[i][0];i++)
- {
- // Don't lock the sfx here, S_ServerSounds already did that
- cl.sound_precache[i] = S_PrecacheSound(cl.sound_name[i], true, false);
- }
+ cl.sound_precache[i] = S_PrecacheSound(cl.sound_name[i], true, true);
// we purge the models and sounds later in CL_SignonReply
//S_PurgeUnused();
continue;
}
CL_KeepaliveMessage(true);
- // Don't lock the sfx here, S_ServerSounds already did that
- cl.sound_precache[cl.loadsound_current] = S_PrecacheSound(cl.sound_name[cl.loadsound_current], false, false);
+ cl.sound_precache[cl.loadsound_current] = S_PrecacheSound(cl.sound_name[cl.loadsound_current], false, true);
SCR_PopLoadingScreen(false);
}
SCR_PopLoadingScreen(false);
return;
}
}
- // Don't lock the sfx here, S_ServerSounds already did that
- cl.sound_precache[cl.downloadsound_current] = S_PrecacheSound(cl.sound_name[cl.downloadsound_current], false, false);
+ cl.sound_precache[cl.downloadsound_current] = S_PrecacheSound(cl.sound_name[cl.downloadsound_current], false, true);
}
// finished loading sounds
//Mod_PurgeUnused();
//S_PurgeUnused();
- // do the same for sounds
- S_ServerSounds (cl.sound_name, numsounds);
+ // clear sound usage flags for purging of unused sounds
+ S_ClearUsed();
// precache any sounds used by the client
cl.sfx_wizhit = S_PrecacheSound(cl_sound_wizardhit.string, false, true);
cl.sfx_ric3 = S_PrecacheSound(cl_sound_ric3.string, false, true);
cl.sfx_r_exp3 = S_PrecacheSound(cl_sound_r_exp3.string, false, true);
+ // sounds used by the game
+ for (i = 1;i < MAX_SOUNDS && cl.sound_name[i][0];i++)
+ cl.sound_precache[i] = S_PrecacheSound(cl.sound_name[i], true, true);
+
// now we try to load everything that is new
cl.loadmodel_current = 1;
cl.downloadmodel_current = 1;
i -= 32768;
if (i >= 1 && i < MAX_SOUNDS)
{
- sfx_t *sfx = S_PrecacheSound (s, true, false);
+ sfx_t *sfx = S_PrecacheSound (s, true, true);
if (!sfx && snd_initialized.integer)
Con_DPrintf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
cl.sound_precache[i] = sfx;
PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
VM_CheckEmptyString(s);
- if(snd_initialized.integer && !S_PrecacheSound(s, true, false))
+ if(snd_initialized.integer && !S_PrecacheSound(s, true, true))
{
VM_Warning("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
return;
i++;
}
- sfx = S_PrecacheSound (name, true, false);
+ sfx = S_PrecacheSound (name, true, true);
if (sfx)
S_StartSound (-1, 0, sfx, listener_location, fvol, attenuation);
}
}
return false;
}
-sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock){
+sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean serversound){
sfx_t *sfx;
if(ras_version>0 && ras_dll){
#ifdef RAS_PRINT
- Con_Printf("Called S_PrecacheSound %s, %i, %i\n",name,complain,lock);
+ Con_Printf("Called S_PrecacheSound %s, %i, %i\n",name,complain,serversound);
#endif
if (name == NULL || name[0] == 0)
return NULL;
}
return NULL;
}
-void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds){
+void S_ClearUsed (void){
sfx_t *prev_s, *now_s;
unsigned int i;
if(ras_version>0 && ras_dll){
- Con_Printf("Called S_ServerSounds\n");
+ Con_Printf("Called S_ClearUsed\n");
for(i=0;i<numsounds;++i){
Con_Printf("Loading :'%s'\n",serversound[i]);
// Load the ambient sounds
if (now_s->flags & SFXFLAG_SERVERSOUND) now_s->flags &= ~SFXFLAG_SERVERSOUND;
sfx_next(&prev_s,&now_s);
}
-
- // Add 1 lock and the SFXFLAG_SERVERSOUND flag to each sfx in "serversound"
- for (i = 1; i < numsounds; i++){
- now_s = S_FindName (serversound[i]);
- if (now_s != NULL)
- now_s->flags |= SFXFLAG_SERVERSOUND;
- }
-
- Free_Unlocked_Sfx();
}
}
}
+void S_PurgeUnused(void){
+ Free_Unlocked_Sfx();
+}
qboolean S_IsSoundPrecached (const sfx_t *sfx){
if(ras_version>0 && ras_dll){
return !sfx->rasptr;
Con_Printf("Called S_LocalSound %s\n",s);
#endif
- sfx = S_PrecacheSound (s, true, false);
+ sfx = S_PrecacheSound (s, true, true);
if (!sfx)
{
Con_Printf("S_LocalSound: can't precache %s\n", s);
i++;
}
- sfx = S_PrecacheSound (name, true, false);
+ sfx = S_PrecacheSound (name, true, true);
if (sfx)
{
ch_ind = S_StartSound (-1, 0, sfx, listener_origin, fvol, attenuation);
/*
==================
-S_ServerSounds
+S_ClearUsed
==================
*/
-void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
+void S_ClearUsed (void)
{
sfx_t *sfx;
// sfx_t *sfxnext;
S_UnlockSfx (sfx);
sfx->flags &= ~SFXFLAG_SERVERSOUND;
}
-
- // Add 1 lock and the SFXFLAG_SERVERSOUND flag to each sfx in "serversound"
- for (i = 1; i < numsounds; i++)
- {
- sfx = S_FindName (serversound[i]);
- if (sfx != NULL)
- {
- // clear the FILEMISSING flag so that S_LoadSound will try again on a
- // previously missing file
- sfx->flags &= ~ SFXFLAG_FILEMISSING;
- S_LockSfx (sfx);
- sfx->flags |= SFXFLAG_SERVERSOUND;
- }
- }
}
/*
S_PrecacheSound
==================
*/
-sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock)
+sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean serversound)
{
sfx_t *sfx;
// previously missing file
sfx->flags &= ~ SFXFLAG_FILEMISSING;
- if (lock)
+ if (serversound && !(sfx->flags & SFXFLAG_SERVERSOUND))
+ {
S_LockSfx (sfx);
+ sfx->flags |= SFXFLAG_SERVERSOUND;
+ }
if (!nosound.integer && snd_precache.integer)
S_LoadSound(sfx, complain);
// One lock is automatically granted while the sfx is
// playing (and removed when stopped). Locks can also be
- int locks; // added by S_PrecacheSound and S_ServerSounds.
- // A SFX with no lock and no SFXFLAG_PERMANENTLOCK is
- // freed at level change by S_ServerSounds.
+ int locks; // added by S_PrecacheSound.
+ // A SFX with no lock, no SFXFLAG_PERMANENTLOCK, and not precached after a level change is freed
unsigned int flags; // cf SFXFLAG_* defines
unsigned int loopstart; // in sample frames. equals total_length if not looped
{
}
-void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
+void S_ClearUsed (void)
{
}
{
}
-sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean lock)
+sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean serversound)
{
return NULL;
}
void S_Update(const matrix4x4_t *listenermatrix);
void S_ExtraUpdate (void);
-sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean lock);
-void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds);
+sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean serversound);
+void S_ClearUsed (void);
void S_PurgeUnused (void);
qboolean S_IsSoundPrecached (const sfx_t *sfx);