]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fix csqc sound precaches which were being freed after the level loaded
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 13 Apr 2009 01:47:09 +0000 (01:47 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 13 Apr 2009 01:47:09 +0000 (01:47 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8919 d7cf8633-e32d-0410-b094-e92efae38249

cd_shared.c
cl_parse.c
prvm_cmds.c
snd_3dras.c
snd_main.c
snd_main.h
snd_null.c
sound.h

index c96f61ae3dbbeca9cfa00f9e593b61437166186d..c57be3393c59800225e96bbdb89c4e7d5b788ae9 100644 (file)
@@ -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)
index a8fc59af534e1c91b460d3707e2f2a97bddf5b8e..fe0c1c580285a84e198eef2dce5d789a2a5615c4 100644 (file)
@@ -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;
index aee1cb7cfb7febfa5483b15e72656844db3535f8..bba2a724fd5c3a0a3686ec166999f897711e9a62 100644 (file)
@@ -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;
index 30b3c4df9b595d1cc4bbc0ea83fa0785bf495d7a..cff3ec91569eee07b428534daf53353a54023a2f 100644 (file)
@@ -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;i<numsounds;++i){
                        Con_Printf("Loading :'%s'\n",serversound[i]);
                        // Load the ambient sounds
@@ -720,18 +720,12 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds){
                                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;
@@ -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);
index e6eb7699cd49cb6361dba6f235480b0340b75567..943dc5d19fc73ccbebf69711483aaf9106eac4e8 100644 (file)
@@ -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);
index a56227854fe9f0b72dbd3a97343dece28925c446..00a0afb0c3eb764f9987e275afc196df59467e26 100644 (file)
@@ -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
index 0e026f0c652250855a5829916c6e1f39f555dd4a..c8aa087420ca897e2e9a26e4c44992916bd2099a 100755 (executable)
@@ -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 5c60c1e7f7d543966cc866886d8311098c22bdb1..c77737e60d6f17d58295042b0a8788056afeeef3 100644 (file)
--- 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);