Added a couple of function skeletons for the automatic unloading of unused sounds...
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 10 Feb 2004 07:14:03 +0000 (07:14 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 10 Feb 2004 07:14:03 +0000 (07:14 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3884 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
host.c
snd_dma.c
snd_mem.c
snd_null.c
sound.h

index dfe44a9..45a8587 100644 (file)
@@ -405,14 +405,16 @@ void CL_ParseServerInfo (void)
                CL_KeepaliveMessage();
                Mod_TouchModel(parse_model_precache[i]);
        }
+       Mod_PurgeUnused();
+
        // do the same for sounds
+       S_ClearUsed();
        for (i = 1;i < numsounds;i++)
        {
                CL_KeepaliveMessage();
                S_TouchSound(parse_sound_precache[i]);
        }
-       // purge anything that was not touched
-       Mod_PurgeUnused();
+       S_PurgeUnused();
 
        // now we try to load everything that is new
 
@@ -431,13 +433,11 @@ void CL_ParseServerInfo (void)
        }
 
        // sounds
-       S_BeginPrecaching ();
        for (i=1 ; i<numsounds ; i++)
        {
                CL_KeepaliveMessage();
                cl.sound_precache[i] = S_PrecacheSound(parse_sound_precache[i], true);
        }
-       S_EndPrecaching ();
 
        // local state
        ent = &cl_entities[0];
diff --git a/host.c b/host.c
index 09683f9..fbb6615 100644 (file)
--- a/host.c
+++ b/host.c
@@ -577,7 +577,7 @@ qboolean Host_FilterTime (double time)
                {
                        // don't totally hog the CPU
                        if (timeleft >= 0.02)
-                               Sys_Sleep(timeleft * 1000 - 5);
+                               Sys_Sleep((int)(timeleft * 1000) - 5);
                        return false;
                }
        }
index 59f4462..0c785bc 100644 (file)
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -275,7 +275,7 @@ void S_Init(void)
 
 /*
 =========
-S_IsCached
+S_GetCached
 
 =========
 */
@@ -343,8 +343,34 @@ S_TouchSound
 void S_TouchSound (char *name)
 {
        S_FindName(name);
+       // TODO: set the "used" flag for this sound
 }
 
+
+/*
+==================
+S_ClearUsed
+
+==================
+*/
+void S_ClearUsed (void)
+{
+       // TODO: reset the "used" flag of all precached sounds
+}
+
+
+/*
+==================
+S_PurgeUnused
+
+==================
+*/
+void S_PurgeUnused (void)
+{
+       // TODO: free all precached sounds without the "used" flag
+}
+
+
 /*
 ==================
 S_PrecacheSound
@@ -988,21 +1014,6 @@ void S_LocalSound (char *sound)
 }
 
 
-void S_ClearPrecache (void)
-{
-}
-
-
-void S_BeginPrecaching (void)
-{
-}
-
-
-void S_EndPrecaching (void)
-{
-}
-
-
 #define RAWSAMPLESBUFFER 32768
 short s_rawsamplesbuffer[RAWSAMPLESBUFFER * 2];
 int s_rawsamplesbuffer_start;
index 4e9f5cb..5eb1303 100644 (file)
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -285,8 +285,6 @@ sfxcache_t *S_LoadSound (sfx_t *s, int complain)
        if (s->sfxcache && (s->sfxcache->speed == shm->speed))
                return s->sfxcache;
 
-       s->silentlymissing = !complain;
-
        len = snprintf (namebuffer, sizeof (namebuffer), "sound/%s", s->name);
        if (len >= sizeof (namebuffer))
                return NULL;
@@ -307,6 +305,7 @@ sfxcache_t *S_LoadSound (sfx_t *s, int complain)
                return sc;
 
        // Can't load the sound!
+       s->silentlymissing = !complain;
        if (complain)
        {
                if (modified_name)
index b8627b9..68e0171 100755 (executable)
@@ -82,10 +82,6 @@ sfx_t *S_PrecacheSound (char *sample, int complain)
        return NULL;
 }
 
-void S_ClearPrecache (void)
-{
-}
-
 void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up)
 {
 }
@@ -94,14 +90,6 @@ void S_StopAllSounds (qboolean clear)
 {
 }
 
-void S_BeginPrecaching (void)
-{
-}
-
-void S_EndPrecaching (void)
-{
-}
-
 void S_ExtraUpdate (void)
 {
 }
diff --git a/sound.h b/sound.h
index e0ef6c7..d0c8418 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -46,7 +46,7 @@ typedef struct sfx_s
        char    name[MAX_QPATH];
        mempool_t       *mempool;
        sfxcache_t      *sfxcache;
-       int silentlymissing; // true if missing and loaded with complain = false
+       qboolean silentlymissing; // true if missing and loaded with complain = false
 } sfx_t;
 
 typedef struct
@@ -100,9 +100,8 @@ void S_ExtraUpdate (void);
 sfx_t *S_GetCached(const char *name);
 sfx_t *S_PrecacheSound (char *sample, int complain);
 void S_TouchSound (char *sample);
-void S_ClearPrecache (void);
-void S_BeginPrecaching (void);
-void S_EndPrecaching (void);
+void S_ClearUsed (void);
+void S_PurgeUnused (void);
 void S_PaintChannels(int endtime);
 void S_InitPaintChannels (void);