[quakefs] Add a data parameter to gamedir callbacks

While this didn't fix the problem for which I needed the data pointer,
having data pointers in callbacks is far too useful to throw out the
change.
This commit is contained in:
Bill Currie 2022-06-04 16:06:04 +09:00
parent 18c64f7319
commit 94db9c8ab1
10 changed files with 30 additions and 24 deletions

View file

@ -85,7 +85,7 @@ extern gamedir_t *qfs_gamedir;
/** Function type of callback called on gamedir change.
\param phase 0 = before Cache_Flush(), 1 = after Cache_Flush()
*/
typedef void gamedir_callback_t (int phase);
typedef void gamedir_callback_t (int phase, void *data);
/** Base of the QFS user directory tree. The QFS functions, except for
QFS_FOpenFile() and _QFS_FOpenFile(), will never access a file outside of
@ -381,8 +381,9 @@ const char *QFS_FileExtension (const char *in) __attribute__((pure));
\param func The function to call every time the gamedir changes via
QFS_Gamedir().
\param data Opaque data pointer passed to the callback.
*/
void QFS_GamedirCallback (gamedir_callback_t *func);
void QFS_GamedirCallback (gamedir_callback_t *func, void *data);
/** Create a new file list.

View file

@ -455,7 +455,7 @@ Mus_VolChange (void *data, const cvar_t *bgmvolume)
}
static void
Mus_gamedir (int phase)
Mus_gamedir (int phase, void *data)
{
if (phase)
Load_Tracklist ();
@ -467,7 +467,7 @@ I_OGGMus_Init (void)
/* check list file cvar, open list file, create map, close file. */
Cvar_Register (&mus_ogglist_cvar, Mus_OggChange, 0);
Cvar_Register (&bgmvolume_cvar, Mus_VolChange, 0);
QFS_GamedirCallback (Mus_gamedir);
QFS_GamedirCallback (Mus_gamedir, 0);
}
static general_funcs_t plugin_info_general_funcs = {

View file

@ -345,7 +345,7 @@ s_playvol_f (void *_snd)
}
static void
s_channels_gamedir (int phase)
s_channels_gamedir (int phase, void *_snd)
{
//FIXME for some reason, a gamedir change causes semi-random
//"already released" cache errors. fortunatly, servers don't change
@ -381,7 +381,7 @@ SND_Channels_Init (snd_t *snd)
snd_num_free_channels = MAX_CHANNELS;
snd_total_channels = MAX_CHANNELS;
QFS_GamedirCallback (s_channels_gamedir);
QFS_GamedirCallback (s_channels_gamedir, snd);
}
static channel_t *

View file

@ -219,7 +219,7 @@ SND_PrecacheSound (snd_t *snd, const char *name)
}
static void
s_gamedir (int phase)
s_gamedir (int phase, void *data)
{
snd_num_sfx = 0;
}
@ -259,7 +259,7 @@ SND_SFX_Init (snd_t *snd)
snd_sfx_hash = Hash_NewTable (511, snd_sfx_getkey, snd_sfx_free, 0, 0);
Cvar_Register (&precache_cvar, 0, 0);
QFS_GamedirCallback (s_gamedir);
QFS_GamedirCallback (s_gamedir, 0);
Cmd_AddCommand ("soundlist", s_soundlist_f,
"Reports a list of sounds in the cache");

View file

@ -132,7 +132,7 @@ CL_TEnts_Precache (void)
}
static void
cl_tents_precache (int phase)
cl_tents_precache (int phase, void *data)
{
if (!phase) {
return;
@ -143,7 +143,7 @@ cl_tents_precache (int phase)
void
CL_TEnts_Init (void)
{
QFS_GamedirCallback (cl_tents_precache);
QFS_GamedirCallback (cl_tents_precache, 0);
for (int i = 0; i < 360; i++) {
float ang = i * M_PI / 360;
beam_rolls[i] = (vec4f_t) { sin (ang), 0, 0, cos (ang) };

View file

@ -259,9 +259,13 @@ static const char *qfs_default_dirconf =
" };"
"}";
typedef struct {
gamedir_callback_t *callback;
void *data;
} gdcallback_t;
#define GAMEDIR_CALLBACK_CHUNK 16
static gamedir_callback_t **gamedir_callbacks;
static gdcallback_t *gamedir_callbacks;
static int num_gamedir_callbacks;
static int max_gamedir_callbacks;
@ -1404,20 +1408,20 @@ QFS_Gamedir (const char *gamedir)
// Make sure everyone else knows we've changed gamedirs
for (i = 0; i < num_gamedir_callbacks; i++) {
gamedir_callbacks[i] (0);
gamedir_callbacks[i].callback (0, gamedir_callbacks[i].data);
}
Cache_Flush ();
for (i = 0; i < num_gamedir_callbacks; i++) {
gamedir_callbacks[i] (1);
gamedir_callbacks[i].callback (1, gamedir_callbacks[i].data);
}
}
VISIBLE void
QFS_GamedirCallback (gamedir_callback_t *func)
QFS_GamedirCallback (gamedir_callback_t *func, void *data)
{
if (num_gamedir_callbacks == max_gamedir_callbacks) {
size_t size = (max_gamedir_callbacks + GAMEDIR_CALLBACK_CHUNK)
* sizeof (gamedir_callback_t *);
* sizeof (gdcallback_t);
gamedir_callbacks = realloc (gamedir_callbacks, size);
if (!gamedir_callbacks)
Sys_Error ("Too many gamedir callbacks!\n");
@ -1428,7 +1432,8 @@ QFS_GamedirCallback (gamedir_callback_t *func)
Sys_Error ("null gamedir callback\n");
}
gamedir_callbacks[num_gamedir_callbacks] = func;
gamedir_callbacks[num_gamedir_callbacks].callback = func;
gamedir_callbacks[num_gamedir_callbacks].data = data;
num_gamedir_callbacks++;
}

View file

@ -206,7 +206,7 @@ gl_Draw_PicFromWad (const char *name)
}
static void
Draw_ClearCache (int phase)
Draw_ClearCache (int phase, void *data)
{
cachepic_t *pic;
int i;
@ -356,7 +356,7 @@ gl_Draw_Init (void)
Cmd_AddCommand ("gl_texturemode", &GL_TextureMode_f,
"Texture mipmap quality.");
QFS_GamedirCallback (Draw_ClearCache);
QFS_GamedirCallback (Draw_ClearCache, 0);
// 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

View file

@ -365,7 +365,7 @@ glsl_Draw_TextBox (int x, int y, int width, int lines, byte alpha)
}
static void
Draw_ClearCache (int phase)
Draw_ClearCache (int phase, void *data)
{
if (phase)
return;
@ -382,7 +382,7 @@ glsl_Draw_Init (void)
//FIXME glpic_t *gl;
pic_cache = Hash_NewTable (127, cachepic_getkey, cachepic_free, 0, 0);
QFS_GamedirCallback (Draw_ClearCache);
QFS_GamedirCallback (Draw_ClearCache, 0);
//FIXME temporary work around for the timing of cvar creation and palette
//loading
//crosshaircolor->callback (crosshaircolor);

View file

@ -2057,7 +2057,7 @@ CL_Init_Memory (void)
}
static void
CL_Autoexec (int phase)
CL_Autoexec (int phase, void *data)
{
if (!phase)
return;
@ -2092,7 +2092,7 @@ Host_Init (void)
pr_gametype = "quakeworld";
QFS_Init (hunk, "qw");
QFS_GamedirCallback (CL_Autoexec);
QFS_GamedirCallback (CL_Autoexec, 0);
PI_Init ();
Sys_RegisterShutdown (Net_LogStop, 0);

View file

@ -2338,7 +2338,7 @@ maxclients_f (void *data, const cvar_t *cvar)
}
static void
gamedir_f (int phase)
gamedir_f (int phase, void *data)
{
if (!phase)
return;
@ -2679,7 +2679,7 @@ SV_Init (void)
memhunk_t *hunk = SV_Init_Memory ();
QFS_GamedirCallback (gamedir_f);
QFS_GamedirCallback (gamedir_f, 0);
svs.maxclients = MAX_CLIENTS;
svs.info = Info_ParseString ("", MAX_SERVERINFO_STRING, 0);
localinfo = Info_ParseString ("", 0, 0); // unlimited