From 847e897b6a32cbeeffd1b3d187ca4e437047cf79 Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 10 Apr 2009 19:25:08 +0000 Subject: [PATCH] do not unload models/sounds until signon is done, this prevents the 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 | 31 ++++++++++++++++--------------- cl_parse.c | 16 +++++++++++++--- model_shared.c | 6 +++--- snd_main.c | 14 +++++++++++++- snd_null.c | 5 +++++ sound.h | 1 + sv_main.c | 3 ++- 7 files changed, 53 insertions(+), 23 deletions(-) diff --git a/cd_shared.c b/cd_shared.c index 9ab0210a..c96f61ae 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -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 diff --git a/cl_parse.c b/cl_parse.c index f05189e4..a8fc59af 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -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 diff --git a/model_shared.c b/model_shared.c index e7a71648..5412d7df 100644 --- a/model_shared.c +++ b/model_shared.c @@ -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; diff --git a/snd_main.c b/snd_main.c index 1675b86d..21cf2033 100644 --- a/snd_main.c +++ b/snd_main.c @@ -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) diff --git a/snd_null.c b/snd_null.c index 542b0b15..0e026f0c 100755 --- a/snd_null.c +++ b/snd_null.c @@ -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 19f7e126..5c60c1e7 100644 --- 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 diff --git a/sv_main.c b/sv_main.c index b7fbd4df..4c0800d5 100644 --- 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) -- 2.39.2