do not unload models/sounds until signon is done, this prevents the
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 10 Apr 2009 19:25:08 +0000 (19:25 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 10 Apr 2009 19:25:08 +0000 (19:25 +0000)
reloading of music tracks on level change, as well as the reloading of
csqc-precached models and sounds

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8897 d7cf8633-e32d-0410-b094-e92efae38249

cd_shared.c
cl_parse.c
model_shared.c
snd_main.c
snd_null.c
sound.h
sv_main.c

index 9ab0210..c96f61a 100644 (file)
@@ -146,6 +146,7 @@ void CDAudio_Play_byName (const char *trackname, qboolean looping)
 {
        unsigned int track;
        sfx_t* sfx;
+       char filename[MAX_QPATH];
 
        Host_StartVideo();
 
@@ -213,25 +214,24 @@ void CDAudio_Play_byName (const char *trackname, qboolean looping)
        // Try playing a fake track (sound file) first
        if(track >= 1)
        {
-               sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, false);
-               if (sfx == NULL || !S_IsSoundPrecached (sfx))
-                       sfx = S_PrecacheSound (va ("cdtracks/track%03u.wav", track), false, false);
-               if (sfx == NULL || !S_IsSoundPrecached (sfx))
-                       sfx = S_PrecacheSound (va ("cdtracks/track%02u", track), false, false);
-               if (sfx == NULL || !S_IsSoundPrecached (sfx))
-                       sfx = S_PrecacheSound (va ("cdtracks/track%03u", track), false, false);
+                                             dpsnprintf(filename, sizeof(filename), "sound/cdtracks/track%03u.wav", track);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/cdtracks/track%03u.ogg", track);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/cdtracks/track%02u.wav", track);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/cdtracks/track%02u.ogg", track);
        }
        else
        {
-               sfx = S_PrecacheSound (va("cdtracks/%s.wav", trackname), false, false);
-               if (sfx == NULL || !S_IsSoundPrecached (sfx))
-                       sfx = S_PrecacheSound (va("cdtracks/%s", trackname), false, false);
-               if (sfx == NULL || !S_IsSoundPrecached (sfx))
-                       sfx = S_PrecacheSound (va("%s.wav", trackname), false, false);
-               if (sfx == NULL || !S_IsSoundPrecached (sfx))
-                       sfx = S_PrecacheSound (va("%s", trackname), false, false);
+                                             dpsnprintf(filename, sizeof(filename), "%s", trackname);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "%s.wav", trackname);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "%s.ogg", trackname);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/%s", trackname);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/%s.wav", trackname);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/%s.ogg", trackname);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/cdtracks/%s", trackname);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/cdtracks/%s.wav", trackname);
+               if (!FS_FileExists(filename)) dpsnprintf(filename, sizeof(filename), "sound/cdtracks/%s.ogg", trackname);
        }
-       if (sfx != NULL)
+       if (FS_FileExists(filename) && (sfx = S_PrecacheSound (filename, false, false)))
        {
                faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0);
                if (faketrack != -1)
@@ -239,6 +239,7 @@ void CDAudio_Play_byName (const char *trackname, qboolean looping)
                        if (looping)
                                S_SetChannelFlag (faketrack, CHANNELFLAG_FORCELOOP, true);
                        S_SetChannelFlag (faketrack, CHANNELFLAG_FULLVOLUME, true);
+                       S_SetChannelFlag (faketrack, CHANNELFLAG_LOCALSOUND, true); // not pausable
                        if(track >= 1)
                        {
                                if(cdaudio.integer != 0 || developer.integer) // we don't need these messages if only fake tracks can be played anyway
index f05189e..a8fc59a 100644 (file)
@@ -576,7 +576,9 @@ static void QW_CL_RequestNextDownload(void)
                cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, NULL);
                cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, NULL);
                cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, NULL);
-               Mod_PurgeUnused();
+
+               // we purge the models and sounds later in CL_SignonReply
+               //Mod_PurgeUnused();
 
                // now we try to load everything that is new
 
@@ -650,6 +652,9 @@ static void QW_CL_RequestNextDownload(void)
                        cl.sound_precache[i] = S_PrecacheSound(cl.sound_name[i], true, false);
                }
 
+               // we purge the models and sounds later in CL_SignonReply
+               //S_PurgeUnused();
+
                // check memory integrity
                Mem_CheckSentinelsGlobal();
 
@@ -1541,7 +1546,10 @@ static void CL_SignonReply (void)
        case 4:
                // after the level has been loaded, we shouldn't need the shaders, and
                // if they are needed again they will be automatically loaded...
+               // we also don't need the unused models or sounds from the last level
                Mod_FreeQ3Shaders();
+               Mod_PurgeUnused();
+               S_PurgeUnused();
 
                Con_ClearNotify();
                if (COM_CheckParm("-profilegameonly"))
@@ -1737,10 +1745,12 @@ void CL_ParseServerInfo (void)
                cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, NULL);
                cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, NULL);
                cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, NULL);
-               Mod_PurgeUnused();
+
+               // we purge the models and sounds later in CL_SignonReply
+               //Mod_PurgeUnused();
+               //S_PurgeUnused();
 
                // do the same for sounds
-               // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
                S_ServerSounds (cl.sound_name, numsounds);
 
                // precache any sounds used by the client
index e7a7164..5412d7d 100644 (file)
@@ -329,9 +329,6 @@ dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk)
                Mem_Free(buf);
 
                Mod_BuildVBOs();
-
-               // no fatal errors occurred, so this model is ready to use.
-               mod->loaded = true;
        }
        else if (crash)
        {
@@ -339,6 +336,9 @@ dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk)
                Con_Printf ("Mod_LoadModel: %s not found\n", mod->name);
        }
 
+       // no fatal errors occurred, so this model is ready to use.
+       mod->loaded = true;
+
        SCR_PopLoadingScreen(false);
 
        return mod;
index 1675b86..21cf203 100644 (file)
@@ -1050,6 +1050,17 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
                        sfx->flags |= SFXFLAG_SERVERSOUND;
                }
        }
+}
+
+/*
+==================
+S_PurgeUnused
+==================
+*/
+void S_PurgeUnused(void)
+{
+       sfx_t *sfx;
+       sfx_t *sfxnext;
 
        // Free all unlocked sfx
        for (sfx = known_sfx;sfx;sfx = sfxnext)
@@ -1497,7 +1508,8 @@ qboolean S_SetChannelFlag (unsigned int ch_ind, unsigned int flag, qboolean valu
 
        if (flag != CHANNELFLAG_FORCELOOP &&
                flag != CHANNELFLAG_PAUSED &&
-               flag != CHANNELFLAG_FULLVOLUME)
+               flag != CHANNELFLAG_FULLVOLUME &&
+               flag != CHANNELFLAG_LOCALSOUND)
                return false;
 
        if (value)
index 542b0b1..0e026f0 100755 (executable)
@@ -53,6 +53,11 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
 {
 }
 
+void S_PurgeUnused (void)
+{
+}
+
+
 void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
 {
 }
diff --git a/sound.h b/sound.h
index 19f7e12..5c60c1e 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -68,6 +68,7 @@ void S_ExtraUpdate (void);
 
 sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean lock);
 void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds);
+void S_PurgeUnused (void);
 qboolean S_IsSoundPrecached (const sfx_t *sfx);
 
 // S_StartSound returns the channel index, or -1 if an error occurred
index b7fbd4d..4c0800d 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -2940,7 +2940,8 @@ void SV_SpawnServer (const char *server)
                SV_Physics ();
        }
 
-       Mod_PurgeUnused();
+       if (cls.state == ca_dedicated)
+               Mod_PurgeUnused();
 
 // create a baseline for more efficient communications
        if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3)