*/
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;
}
==================
S_ClearUsed
+Reset the "used" flag of all precached sounds
==================
*/
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;
}
==================
S_PurgeUnused
+Free all precached sounds without the "used" flag
==================
*/
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);
+ }
}
// 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;
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));
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)
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;
- qboolean silentlymissing; // true if missing and loaded with complain = false
+ unsigned int flags; // cf SFXFLAG_* defines
} sfx_t;
typedef struct