]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Added S_Terminate to free all sound resources at shutdown
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 3 Jan 2005 14:20:56 +0000 (14:20 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 3 Jan 2005 14:20:56 +0000 (14:20 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4895 d7cf8633-e32d-0410-b094-e92efae38249

host.c
snd_main.c
snd_null.c
sound.h

diff --git a/host.c b/host.c
index 420984600c76383fdc8386415d8ad2d394ca7c5d..f5cb873f1b72d8f184944fe938d29a082658e8f9 100644 (file)
--- a/host.c
+++ b/host.c
@@ -1014,6 +1014,7 @@ void Host_Shutdown(void)
        Host_SaveConfig_f();
 
        CDAudio_Shutdown ();
+       S_Terminate ();
        NetConn_Shutdown ();
 
        if (cls.state != ca_dedicated)
index 779d4b7a7d7cf0eff9509c54bbd3fa47a06b5eec..019c59be499c6531d7f5a931b6a6b453eaba1747 100644 (file)
@@ -89,6 +89,9 @@ const char* ambient_names [2] = { "sound/ambience/water1.wav", "sound/ambience/w
 // Functions
 // ====================================================================
 
+void S_FreeSfx (sfx_t *sfx, qboolean force);
+
+
 void S_SoundInfo_f(void)
 {
        if (!sound_started)
@@ -219,6 +222,27 @@ void S_Init(void)
 }
 
 
+/*
+================
+S_Terminate
+
+Shutdown and free all resources
+================
+*/
+void S_Terminate (void)
+{
+       S_Shutdown ();
+       OGG_CloseLibrary ();
+
+       // Free all SFXs
+       while (known_sfx != NULL)
+               S_FreeSfx (known_sfx, true);
+
+       Cvar_SetValueQuick (&snd_initialized, false);
+       Mem_FreePool (&snd_mempool);
+}
+
+
 // =======================================================================
 // Load a sound
 // =======================================================================
@@ -262,10 +286,10 @@ S_FreeSfx
 
 ==================
 */
-void S_FreeSfx (sfx_t *sfx)
+void S_FreeSfx (sfx_t *sfx, qboolean force)
 {
-       // Never free a locked sfx
-       if (sfx->locks > 0 || (sfx->flags & SFXFLAG_PERMANENTLOCK))
+       // Never free a locked sfx unless forced
+       if (!force && (sfx->locks > 0 || (sfx->flags & SFXFLAG_PERMANENTLOCK)))
                return;
 
        Con_DPrintf ("S_FreeSfx: freeing %s\n", sfx->name);
@@ -351,7 +375,7 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
                crtsfx = sfx;
                sfx = sfx->next;
 
-               S_FreeSfx (crtsfx);
+               S_FreeSfx (crtsfx, false);
        }
 }
 
@@ -968,7 +992,7 @@ static void S_Play_Common(float fvol, float attenuation)
 
                        // Free the sfx if the file didn't exist
                        if (ch_ind < 0)
-                               S_FreeSfx (sfx);
+                               S_FreeSfx (sfx, false);
                        else
                                channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND;
                }
index 0bd5157ed22ee50f5ce8a4efc09386110d84e9aa..21e3f09f2d10b6d81bb2e2750ccf632ffb79d910 100755 (executable)
@@ -36,6 +36,10 @@ void S_Init (void)
        Cvar_RegisterVariable(&snd_initialized);
 }
 
+void S_Terminate (void)
+{
+}
+
 void S_Startup (void)
 {
 }
diff --git a/sound.h b/sound.h
index b09d89dd7a876e82ab464228db3d7960860850d3..af734196cc8fcddfab8aee88a4aa82198a34c3fc 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -56,6 +56,8 @@ extern cvar_t snd_staticvolume;
 // ====================================================================
 
 void S_Init (void);
+void S_Terminate (void);
+
 void S_Startup (void);
 void S_Shutdown (void);