]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Added automatic unloading of unused sounds. The "silentlymissing" boolean is now...
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 11 Feb 2004 07:25:20 +0000 (07:25 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 11 Feb 2004 07:25:20 +0000 (07:25 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3892 d7cf8633-e32d-0410-b094-e92efae38249

snd_dma.c
snd_mem.c
sound.h

index 0c785bcc579cc629eb721be273399c49deb19c15..e3b4a09b439aab65cbba8b6072660f897ffb73db 100644 (file)
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -342,8 +342,13 @@ S_TouchSound
 */
 void S_TouchSound (char *name)
 {
 */
 void S_TouchSound (char *name)
 {
-       S_FindName(name);
-       // TODO: set the "used" flag for this sound
+       sfx_t *sfx;
+
+       sfx = S_FindName (name);
+
+       // Set the "used" flag for this sound
+       if (sfx != NULL)
+               sfx->flags |= SFXFLAG_USED;
 }
 
 
 }
 
 
@@ -351,11 +356,15 @@ void S_TouchSound (char *name)
 ==================
 S_ClearUsed
 
 ==================
 S_ClearUsed
 
+Reset the "used" flag of all precached sounds
 ==================
 */
 void S_ClearUsed (void)
 {
 ==================
 */
 void S_ClearUsed (void)
 {
-       // TODO: reset the "used" flag of all precached sounds
+       int i;
+
+       for (i = 0; i < num_sfx; i++)
+               known_sfx[i].flags &= ~SFXFLAG_USED;
 }
 
 
 }
 
 
@@ -363,11 +372,20 @@ void S_ClearUsed (void)
 ==================
 S_PurgeUnused
 
 ==================
 S_PurgeUnused
 
+Free all precached sounds without the "used" flag
 ==================
 */
 void S_PurgeUnused (void)
 {
 ==================
 */
 void S_PurgeUnused (void)
 {
-       // TODO: free all precached sounds without the "used" flag
+       int i;
+       sfx_t *sfx;
+
+       for (i = 0; i < num_sfx; i++)
+       {
+               sfx = &known_sfx[i];
+               if (! (sfx->flags & SFXFLAG_USED))
+                       S_UnloadSound (sfx);
+       }
 }
 
 
 }
 
 
@@ -718,7 +736,8 @@ void S_UpdateAmbientSounds (void)
 // calc ambient sound levels
        for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
        {
 // calc ambient sound levels
        for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
        {
-               if (ambient_sfx[ambient_channel] && ambient_sfx[ambient_channel]->silentlymissing)
+               if (ambient_sfx[ambient_channel] &&
+                       (ambient_sfx[ambient_channel]->flags & SFXFLAG_SILENTLYMISSING))
                        continue;
                chan = &channels[ambient_channel];
                chan->forceloop = true;
                        continue;
                chan = &channels[ambient_channel];
                chan->forceloop = true;
index 5eb1303827815d2c06a00d9eae04b4f64f9d184c..c620d23664392e2f530a2922f0b4545b1984ed21 100644 (file)
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -242,7 +242,6 @@ sfxcache_t *S_LoadWavFile (const char *filename, sfx_t *s)
        len = (int) ((double) info.samples * (double) shm->speed / (double) info.rate);
        len = len * info.width * info.channels;
 
        len = (int) ((double) info.samples * (double) shm->speed / (double) info.rate);
        len = len * info.width * info.channels;
 
-       // FIXME: add S_UnloadSounds or something?
        Mem_FreePool(&s->mempool);
        s->mempool = Mem_AllocPool(s->name);
        sc = s->sfxcache = Mem_Alloc(s->mempool, len + sizeof(sfxcache_t));
        Mem_FreePool(&s->mempool);
        s->mempool = Mem_AllocPool(s->name);
        sc = s->sfxcache = Mem_Alloc(s->mempool, len + sizeof(sfxcache_t));
@@ -305,7 +304,10 @@ sfxcache_t *S_LoadSound (sfx_t *s, int complain)
                return sc;
 
        // Can't load the sound!
                return sc;
 
        // Can't load the sound!
-       s->silentlymissing = !complain;
+       if (!complain)
+               s->flags |= SFXFLAG_SILENTLYMISSING;
+       else
+               s->flags &= ~SFXFLAG_SILENTLYMISSING;
        if (complain)
        {
                if (modified_name)
        if (complain)
        {
                if (modified_name)
diff --git a/sound.h b/sound.h
index d0c8418c311c98fef96a76a7f92d0fe4592dc62e..075719ab8d7275ddf1e647ff20ed5b50aa34d3e3 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -41,12 +41,16 @@ typedef struct
        qbyte   data[1];                // variable sized
 } sfxcache_t;
 
        qbyte   data[1];                // variable sized
 } sfxcache_t;
 
+// sfx_t flags
+#define SFXFLAG_SILENTLYMISSING        (1 << 0) // if the sfx is missing and loaded with complain = false
+#define SFXFLAG_USED                   (1 << 1)
+
 typedef struct sfx_s
 {
        char    name[MAX_QPATH];
        mempool_t       *mempool;
        sfxcache_t      *sfxcache;
 typedef struct sfx_s
 {
        char    name[MAX_QPATH];
        mempool_t       *mempool;
        sfxcache_t      *sfxcache;
-       qboolean silentlymissing; // true if missing and loaded with complain = false
+       unsigned int flags;  // cf SFXFLAG_* defines
 } sfx_t;
 
 typedef struct
 } sfx_t;
 
 typedef struct