[quakefs] Take in the pointer to the global hunk

This is needed for cleaning up excess memsets when loading files because
Hunk_RawAllocName has nonnull on its hunk pointer (as the rest of the
hunk functions really should, but not just yet).
This commit is contained in:
Bill Currie 2021-12-13 09:13:39 +09:00
parent 39c020908c
commit 2086125e0b
12 changed files with 38 additions and 28 deletions

View file

@ -107,6 +107,7 @@ extern int qfs_filesize;
struct cache_user_s;
struct dstring_s;
struct memhunk_s;
/** Initialize the Quake Filesystem.
@ -114,13 +115,14 @@ struct dstring_s;
\c fs_dirconf Cvars. It then loads the \ref dirconf and parses the
\c -game command line option.
\param hunk Memory pool to use for hunk-based allocations.
\param game The game type used for searching the directory
configuration. Currently, this is \"qw\" for
quakeworld clients and servers, and one of \"nq\",
\"hexen\", \"rogue\" or \"abyss\" for the netquake
clients and servers.
*/
void QFS_Init (const char *game);
void QFS_Init (struct memhunk_s *hunk, const char *game);
/** Change the current game directory.

View file

@ -68,9 +68,9 @@ init (void)
COM_ParseConfig (testsound_cbuf);
Cvar_Get ("cmd_warncmd", "1", CVAR_NONE, NULL, NULL);
Memory_Init (Sys_Alloc (MEMSIZE), MEMSIZE);
memhunk_t *hunk = Memory_Init (Sys_Alloc (MEMSIZE), MEMSIZE);
QFS_Init ("qw");
QFS_Init (hunk, "qw");
PI_Init ();
S_Init_Cvars ();

View file

@ -122,6 +122,7 @@ int fnmatch (const char *__pattern, const char *__string, int __flags);
// QUAKE FILESYSTEM
static memhunk_t *qfs_hunk;
static cvar_t *fs_userpath;
static cvar_t *fs_sharepath;
static cvar_t *fs_dirconf;
@ -1427,10 +1428,12 @@ qfs_shutdown (void *data)
}
VISIBLE void
QFS_Init (const char *game)
QFS_Init (memhunk_t *hunk, const char *game)
{
int i;
qfs_hunk = hunk;
fs_sharepath = Cvar_Get ("fs_sharepath", FS_SHAREPATH, CVAR_ROM,
qfs_path_cvar,
"location of shared (read-only) game "

View file

@ -158,6 +158,7 @@ extern qboolean isDedicated;
extern qboolean standard_quake;
extern struct cvar_s *registered;
void Game_Init (void);
struct memhunk_s;
void Game_Init (struct memhunk_s *hunk);
#endif // __game_h

View file

@ -72,7 +72,7 @@ Game_CheckRegistered (void)
}
void
Game_Init (void)
Game_Init (memhunk_t *hunk)
{
int i;
const char *game = "nq";
@ -89,7 +89,7 @@ Game_Init (void)
} else if ((i = COM_CheckParm ("-abyss"))) {
game = "abyss";
}
QFS_Init (game);
QFS_Init (hunk, game);
registered = Cvar_Get ("registered", "0", CVAR_NONE, NULL,
"Is the game the registered version. 1 yes 0 no");

View file

@ -808,7 +808,7 @@ Host_InitVCR (quakeparms_t *parms)
}
static void
static memhunk_t *
Host_Init_Memory (void)
{
int mem_parm = COM_CheckParm ("-mem");
@ -843,9 +843,10 @@ Host_Init_Memory (void)
Sys_Error ("Can't allocate %zd", mem_size);
Sys_PageIn (mem_base, mem_size);
Memory_Init (mem_base, mem_size);
memhunk_t *hunk = Memory_Init (mem_base, mem_size);
Sys_Printf ("%4.1f megabyte heap\n", host_mem_size->value);
return hunk;
}
static void
@ -887,11 +888,11 @@ Host_Init (void)
GIB_Key_Init ();
COM_ParseConfig (host_cbuf);
Host_Init_Memory ();
memhunk_t *hunk = Host_Init_Memory ();
PI_Init ();
Game_Init ();
Game_Init (hunk);
if (!isDedicated)
CL_InitCvars ();

View file

@ -202,7 +202,7 @@ qtv_end_redirect (void)
qtv_redirect_client = 0;
}
static void
static memhunk_t *
qtv_memory_init (void)
{
int mem_size;
@ -217,7 +217,7 @@ qtv_memory_init (void)
mem_base = Sys_Alloc (mem_size);
if (!mem_base)
Sys_Error ("Can't allocate %d", mem_size);
Memory_Init (mem_base, mem_size);
return Memory_Init (mem_base, mem_size);
}
static void
@ -258,9 +258,9 @@ qtv_init (void)
COM_ParseConfig (qtv_cbuf);
Cvar_Get ("cmd_warncmd", "1", CVAR_NONE, NULL, NULL);
qtv_memory_init ();
memhunk_t *hunk = qtv_memory_init ();
QFS_Init ("qw");
QFS_Init (hunk, "qw");
PI_Init ();
qtv_console_plugin = Cvar_Get ("qtv_console_plugin", "server",

View file

@ -1756,7 +1756,7 @@ Host_Frame (float time)
fps_count++;
}
static void
static memhunk_t *
CL_Init_Memory (void)
{
int mem_parm = COM_CheckParm ("-mem");
@ -1786,9 +1786,10 @@ CL_Init_Memory (void)
Sys_Error ("Can't allocate %zd", mem_size);
Sys_PageIn (mem_base, mem_size);
Memory_Init (mem_base, mem_size);
memhunk_t *hunk = Memory_Init (mem_base, mem_size);
Sys_Printf ("%4.1f megabyte heap.\n", cl_mem_size->value);
return hunk;
}
static void
@ -1822,11 +1823,11 @@ Host_Init (void)
GIB_Key_Init ();
COM_ParseConfig (cl_cbuf);
CL_Init_Memory ();
memhunk_t *hunk = CL_Init_Memory ();
pr_gametype = "quakeworld";
QFS_Init ("qw");
QFS_Init (hunk, "qw");
QFS_GamedirCallback (CL_Autoexec);
PI_Init ();

View file

@ -2446,7 +2446,7 @@ SV_InitNet (void)
sv_net_initialized = 1;
}
static void
static memhunk_t *
SV_Init_Memory (void)
{
int mem_parm = COM_CheckParm ("-mem");
@ -2475,7 +2475,7 @@ SV_Init_Memory (void)
if (!mem_base)
Sys_Error ("Can't allocate %zd", mem_size);
Memory_Init (mem_base, mem_size);
return Memory_Init (mem_base, mem_size);
}
void
@ -2495,7 +2495,7 @@ SV_Init (void)
// snax: Init experimental object system and run a test
//Object_Init();
SV_Init_Memory ();
memhunk_t *hunk = SV_Init_Memory ();
QFS_GamedirCallback (gamedir_f);
svs.maxclients = MAX_CLIENTS;
@ -2504,7 +2504,7 @@ SV_Init (void)
SV_InitOperatorCommands ();
SV_GIB_Init ();
QFS_Init ("qw");
QFS_Init (hunk, "qw");
PI_Init ();
sv_console_plugin = Cvar_Get ("sv_console_plugin", "server",

View file

@ -151,13 +151,13 @@ bi_shutdown (void *data)
}
void
BI_Init (progs_t *pr)
BI_Init (memhunk_t *hunk, progs_t *pr)
{
byte *basepal, *colormap;
PR_RegisterBuiltins (pr, builtins);
QFS_Init ("nq");
QFS_Init (hunk, "nq");
PI_Init ();
PI_RegisterPlugins (client_plugin_list);

View file

@ -114,7 +114,8 @@ init_qf (void)
//Cvar_Set (developer, "1");
Memory_Init (Sys_Alloc (8 * 1024 * 1024), 8 * 1024 * 1024);
size_t memsize = 8 * 1024 * 1024;
memhunk_t *hunk = Memory_Init (Sys_Alloc (memsize), memsize);
Cvar_Get ("pr_debug", "2", 0, 0, 0);
Cvar_Get ("pr_boundscheck", "0", 0, 0, 0);
@ -131,7 +132,7 @@ init_qf (void)
PR_Init (&pr);
RUA_Init (&pr, 0);
PR_Cmds_Init (&pr);
BI_Init (&pr);
BI_Init (hunk, &pr);
}
static int

View file

@ -23,7 +23,8 @@ typedef struct qwaq_thread_s {
typedef struct qwaq_thread_set_s DARRAY_TYPE(qwaq_thread_t *) qwaq_thread_set_t;
void BI_Init (progs_t *pr);
struct memhunk_s;
void BI_Init (struct memhunk_s *hunk, progs_t *pr);
void BI_Curses_Init (progs_t *pr);
void BI_Input_Init (progs_t *pr);
void QWAQ_EditBuffer_Init (progs_t *pr);