From 63194da5789fa949671e4a3cb7309ea0b6b15b68 Mon Sep 17 00:00:00 2001 From: molivier Date: Mon, 3 Jan 2005 14:20:56 +0000 Subject: [PATCH] Added S_Terminate to free all sound resources at shutdown git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4895 d7cf8633-e32d-0410-b094-e92efae38249 --- host.c | 1 + snd_main.c | 34 +++++++++++++++++++++++++++++----- snd_null.c | 4 ++++ sound.h | 2 ++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/host.c b/host.c index 42098460..f5cb873f 100644 --- 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) diff --git a/snd_main.c b/snd_main.c index 779d4b7a..019c59be 100644 --- a/snd_main.c +++ b/snd_main.c @@ -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; } diff --git a/snd_null.c b/snd_null.c index 0bd5157e..21e3f09f 100755 --- a/snd_null.c +++ b/snd_null.c @@ -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 b09d89dd..af734196 100644 --- 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); -- 2.39.2