From 97e0c21d0017889c39050c2433c89f6b3ebb2633 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 13 Apr 2009 01:47:09 +0000 Subject: [PATCH] fix csqc sound precaches which were being freed after the level loaded git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8919 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_shared.c | 2 +- cl_parse.c | 28 +++++++++++++--------------- prvm_cmds.c | 2 +- snd_3dras.c | 24 +++++++++--------------- snd_main.c | 27 ++++++++------------------- snd_main.h | 5 ++--- snd_null.c | 4 ++-- sound.h | 4 ++-- 8 files changed, 38 insertions(+), 58 deletions(-) diff --git a/cd_shared.c b/cd_shared.c index c96f61ae..c57be339 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -231,7 +231,7 @@ void CDAudio_Play_byName (const char *trackname, qboolean looping) 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) diff --git a/cl_parse.c b/cl_parse.c index a8fc59af..fe0c1c58 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -632,9 +632,8 @@ static void QW_CL_RequestNextDownload(void) 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); @@ -645,12 +644,9 @@ static void QW_CL_RequestNextDownload(void) 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(); @@ -1143,8 +1139,7 @@ void CL_BeginDownloads(qboolean aborteddownload) 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); @@ -1259,8 +1254,7 @@ void CL_BeginDownloads(qboolean aborteddownload) 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 @@ -1750,8 +1744,8 @@ void CL_ParseServerInfo (void) //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); @@ -1762,6 +1756,10 @@ void CL_ParseServerInfo (void) 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; @@ -3782,7 +3780,7 @@ void CL_ParseServerMessage(void) 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; diff --git a/prvm_cmds.c b/prvm_cmds.c index aee1cb7c..bba2a724 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -1090,7 +1090,7 @@ void VM_precache_sound (void) 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; diff --git a/snd_3dras.c b/snd_3dras.c index 30b3c4df..cff3ec91 100644 --- a/snd_3dras.c +++ b/snd_3dras.c @@ -268,7 +268,7 @@ static void S_Play_Common (float fvol, float attenuation){ i++; } - sfx = S_PrecacheSound (name, true, false); + sfx = S_PrecacheSound (name, true, true); if (sfx) S_StartSound (-1, 0, sfx, listener_location, fvol, attenuation); } @@ -686,11 +686,11 @@ int S_LoadSound(sfx_t *sfx, int complain){ } 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; @@ -702,12 +702,12 @@ sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock){ } 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;iflags & 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; @@ -905,7 +899,7 @@ qboolean S_LocalSound (const char *s){ 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); diff --git a/snd_main.c b/snd_main.c index e6eb7699..943dc5d1 100644 --- a/snd_main.c +++ b/snd_main.c @@ -254,7 +254,7 @@ static void S_Play_Common (float fvol, float attenuation) 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); @@ -1002,10 +1002,10 @@ void S_FreeSfx (sfx_t *sfx, qboolean force) /* ================== -S_ServerSounds +S_ClearUsed ================== */ -void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds) +void S_ClearUsed (void) { sfx_t *sfx; // sfx_t *sfxnext; @@ -1036,20 +1036,6 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds) 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; - } - } } /* @@ -1076,7 +1062,7 @@ void S_PurgeUnused(void) 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; @@ -1095,8 +1081,11 @@ sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock) // 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); diff --git a/snd_main.h b/snd_main.h index a5622785..00a0afb0 100644 --- a/snd_main.h +++ b/snd_main.h @@ -66,9 +66,8 @@ struct sfx_s // 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 diff --git a/snd_null.c b/snd_null.c index 0e026f0c..c8aa0874 100755 --- a/snd_null.c +++ b/snd_null.c @@ -49,7 +49,7 @@ void S_Shutdown (void) { } -void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds) +void S_ClearUsed (void) { } @@ -88,7 +88,7 @@ void S_SetChannelVolume (unsigned int ch_ind, float fvol) { } -sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean lock) +sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean serversound) { return NULL; } diff --git a/sound.h b/sound.h index 5c60c1e7..c77737e6 100644 --- a/sound.h +++ b/sound.h @@ -66,8 +66,8 @@ void S_UnloadAllSounds_f (void); 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); -- 2.39.2