Grievre's gamedir callback patch to fix mangled sounds on gamedir change

plus a couple minor tweaks I notcied needed doing.
This commit is contained in:
Bill Currie 2004-02-03 03:01:06 +00:00
parent c16fc91328
commit 9784ba5954
8 changed files with 89 additions and 20 deletions

View file

@ -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);

View file

@ -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 = {

View file

@ -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 ======================================================

View file

@ -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)
{

View file

@ -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

View file

@ -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 ();

View file

@ -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;

View file

@ -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)
{