From 9784ba595463ba35dba1acb6ceb429941d9406b4 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 3 Feb 2004 03:01:06 +0000 Subject: [PATCH] Grievre's gamedir callback patch to fix mangled sounds on gamedir change plus a couple minor tweaks I notcied needed doing. --- include/QF/quakefs.h | 6 ++++++ libs/audio/cd/cd_file.c | 13 +++++++++++++ libs/audio/renderer/snd_dma.c | 9 +++++++++ libs/util/quakefs.c | 33 +++++++++++++++++++++++++++++++- libs/video/renderer/gl/gl_draw.c | 4 +++- qw/source/cl_main.c | 17 ++++++++++++++++ qw/source/cl_parse.c | 16 ---------------- qw/source/cl_tent.c | 11 +++++++++-- 8 files changed, 89 insertions(+), 20 deletions(-) diff --git a/include/QF/quakefs.h b/include/QF/quakefs.h index 610a41abd..10ba8e305 100644 --- a/include/QF/quakefs.h +++ b/include/QF/quakefs.h @@ -38,6 +38,8 @@ #define MAX_OSPATH 128 // max length of a filesystem pathname +#define MAX_GAMEDIR_CALLBACKS 128 // most QFS_GamedirCallback calls. + typedef struct searchpath_s { char filename[MAX_OSPATH]; struct pack_s *pack; // only one of filename / pack will be used @@ -58,6 +60,8 @@ typedef struct gamedir_s { } dir; } gamedir_t; +typedef void gamedir_callback_t (void); + extern searchpath_t *qfs_searchpaths; extern gamedir_t *qfs_gamedir; @@ -103,6 +107,8 @@ char *QFS_CompressPath (const char *pth); const char *QFS_SkipPath (const char *pathname); const char *QFS_FileExtension (const char *in); +void QFS_GamedirCallback (gamedir_callback_t *); + // FIXME: This is here temporarily until fs_usercfg gets sorted out char *expand_squiggle (const char *path); diff --git a/libs/audio/cd/cd_file.c b/libs/audio/cd/cd_file.c index 6c6354811..2a20a6e2a 100644 --- a/libs/audio/cd/cd_file.c +++ b/libs/audio/cd/cd_file.c @@ -178,6 +178,11 @@ I_OGGMus_Stop (void) wasPlaying = false; playing = false; + + if (cd_sfx) { + cd_sfx->close (cd_sfx); + cd_channel->sfx = cd_sfx = NULL; + } } /* start playing, if we've got a trackmap. @@ -459,6 +464,12 @@ Mus_VolChange (cvar_t *bgmvolume) set_volume (); } +static void +Mus_gamedir (void) +{ + Mus_OggChange (mus_ogglist); +} + static void I_OGGMus_Init (void) { @@ -476,6 +487,8 @@ I_OGGMus_Init (void) "filename of track to music file map"); bgmvolume = Cvar_Get ("bgmvolume", "1", CVAR_ARCHIVE, Mus_VolChange, "Volume of CD music"); + + QFS_GamedirCallback (Mus_gamedir); } static general_funcs_t plugin_info_general_funcs = { diff --git a/libs/audio/renderer/snd_dma.c b/libs/audio/renderer/snd_dma.c index aadf95877..5ac92f908 100644 --- a/libs/audio/renderer/snd_dma.c +++ b/libs/audio/renderer/snd_dma.c @@ -51,6 +51,7 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/sound.h" #include "QF/plugin.h" #include "QF/va.h" +#include "QF/quakefs.h" #include "snd_render.h" @@ -884,6 +885,12 @@ s_unblock_sound (void) } } +static void +s_gamedir (void) +{ + num_sfx = 0; +} + static void s_init (void) { @@ -990,6 +997,8 @@ s_init (void) ambient_sfx[AMBIENT_SKY] = s_precache_sound ("ambience/wind2.wav"); s_stop_all_sounds (true); + + QFS_GamedirCallback (s_gamedir); } // Shutdown sound engine ====================================================== diff --git a/libs/util/quakefs.c b/libs/util/quakefs.c index c6929826e..66a1213ad 100644 --- a/libs/util/quakefs.c +++ b/libs/util/quakefs.c @@ -171,6 +171,10 @@ static const char *qfs_default_dirconf = " };" "}"; + +static gamedir_callback_t *gamedir_callbacks[MAX_GAMEDIR_CALLBACKS]; +static int num_gamedir_callbacks; + static const char * qfs_var_get_key (void *_v, void *unused) { @@ -1126,13 +1130,40 @@ QFS_AddGameDirectory (const char *dir) void QFS_Gamedir (const char *dir) { + int i; const char *list[2] = {dir, 0}; qfs_build_gamedir (list); - // flush all data, so it will be forced to reload + + // Make sure everyone else knows we've changed gamedirs + for (i = 0; i < num_gamedir_callbacks; i++) { + gamedir_callbacks[i] (); + } + + // Flush cache last, so other things get a chance to deal with it Cache_Flush (); } +/* + QFS_GamedirCallback + + Kludge to fix all the stuff that changing gamedirs breaks +*/ +void +QFS_GamedirCallback (gamedir_callback_t *func) +{ + if (num_gamedir_callbacks == MAX_GAMEDIR_CALLBACKS) { + Sys_Error ("Too many gamedir callbacks!\n"); + } + + if (!func) { + Sys_Error ("null gamedir callback\n"); + } + + gamedir_callbacks[num_gamedir_callbacks] = func; + num_gamedir_callbacks++; +} + char * expand_squiggle (const char *path) { diff --git a/libs/video/renderer/gl/gl_draw.c b/libs/video/renderer/gl/gl_draw.c index 993754455..2e89c92c2 100644 --- a/libs/video/renderer/gl/gl_draw.c +++ b/libs/video/renderer/gl/gl_draw.c @@ -324,12 +324,14 @@ Draw_TextBox (int x, int y, int width, int lines, byte alpha) void Draw_Init (void) { - int i; + int i; tex_t *image; Cmd_AddCommand ("gl_texturemode", &GL_TextureMode_f, "Texture mipmap quality."); + QFS_GamedirCallback (Draw_ClearCache); + // load the console background and the charset by hand, because we need to // write the version string into the background before turning it into a // texture diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index fae0dab1a..9a3ca0796 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1611,6 +1611,22 @@ CL_Init_Memory (void) Memory_Init (mem_base, mem_size); } +static void +CL_Autoexec (void) +{ + int cmd_warncmd_val = cmd_warncmd->int_val; + + Cbuf_AddText (cl_cbuf, "cmd_warncmd 0\n"); + Cbuf_AddText (cl_cbuf, "exec config.cfg\n"); + Cbuf_AddText (cl_cbuf, "exec frontend.cfg\n"); + + if (cl_autoexec->int_val) { + Cbuf_AddText (cl_cbuf, "exec autoexec.cfg\n"); + } + + Cbuf_AddText (cl_cbuf, va ("cmd_warncmd %d\n", cmd_warncmd_val)); +} + void Host_Init (void) { @@ -1661,6 +1677,7 @@ Host_Init (void) cl.serverinfo = Info_ParseString ("", MAX_INFO_STRING, 0); QFS_Init ("qw"); + QFS_GamedirCallback (CL_Autoexec); PI_Init (); CL_Cam_Init_Cvars (); diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index 106a7a31c..2047f489a 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -667,7 +667,6 @@ CL_ClearBaselines (void) static void CL_ParseServerData (void) { - char fn[MAX_OSPATH]; const char *str; int protover; qboolean cflag = false; @@ -695,25 +694,10 @@ CL_ParseServerData (void) // save current config Host_WriteConfiguration (); cflag = true; - Draw_ClearCache (); QFS_Gamedir (str); } - // ZOID--run the autoexec.cfg in the gamedir if it exists - if (cflag) { - int cmd_warncmd_val = cmd_warncmd->int_val; - - Cbuf_AddText (cl_cbuf, "cmd_warncmd 0\n"); - Cbuf_AddText (cl_cbuf, "exec config.cfg\n"); - Cbuf_AddText (cl_cbuf, "exec frontend.cfg\n"); - if (cl_autoexec->int_val) { - Cbuf_AddText (cl_cbuf, "exec autoexec.cfg\n"); - } - snprintf (fn, sizeof (fn), "cmd_warncmd %d\n", cmd_warncmd_val); - Cbuf_AddText (cl_cbuf, fn); - } - if (cls.demoplayback2) { realtime = cls.basetime = MSG_ReadFloat (net_message); cl.playernum = 31; diff --git a/qw/source/cl_tent.c b/qw/source/cl_tent.c index 80b04fc61..e18e31911 100644 --- a/qw/source/cl_tent.c +++ b/qw/source/cl_tent.c @@ -92,8 +92,8 @@ model_t *cl_mod_bolt2; model_t *cl_mod_bolt3; model_t *cl_spr_explod; -void -CL_TEnts_Init (void) +static void +CL_TEnts_Precache (void) { cl_sfx_wizhit = S_PrecacheSound ("wizard/hit.wav"); cl_sfx_knighthit = S_PrecacheSound ("hknight/hit.wav"); @@ -112,6 +112,13 @@ CL_TEnts_Init (void) cl_mod_beam = cl_mod_bolt; } +void +CL_TEnts_Init (void) +{ + QFS_GamedirCallback (CL_TEnts_Precache); + CL_TEnts_Precache (); +} + void CL_Init_Entity (entity_t *ent) {