diff --git a/qw/include/host.h b/qw/include/host.h index 9fa3a7150..1e7149554 100644 --- a/qw/include/host.h +++ b/qw/include/host.h @@ -70,8 +70,6 @@ typedef struct { int argc; char **argv; - void *membase; - int memsize; } quakeparms_t; /* Host */ diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 4f453cc80..c6b524afd 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -115,6 +115,9 @@ qboolean noclip_anglehack; // remnant from old quake cvar_t *fs_globalcfg; cvar_t *fs_usercfg; + +cvar_t *cl_mem_size; + cvar_t *rcon_password; cvar_t *rcon_address; @@ -1553,29 +1556,49 @@ check_quakerc (void) return ret; } +void +CL_Init_Memory (void) +{ + int mem_parm = COM_CheckParm ("-mem"); + int mem_size; + void *mem_base; + + cl_mem_size = Cvar_Get ("cl_mem_size", "16", CVAR_NONE, NULL, + "Amount of memory (in MB) to allocate for the " + PROGRAM " heap"); + if (mem_parm) + Cvar_Set (cl_mem_size, com_argv[mem_parm + 1]); + + if (COM_CheckParm ("-minmemory")) + Cvar_SetValue (cl_mem_size, MINIMUM_MEMORY / (1024 * 1024.0)); + + Cvar_SetFlags (cl_mem_size, cl_mem_size->flags | CVAR_ROM); + + mem_size = (int) (cl_mem_size->value * 1024 * 1024); + + if (mem_size < MINIMUM_MEMORY) + Sys_Error ("Only %4.1f megs of memory reported, can't execute game", + mem_size / (float) 0x100000); + + mem_base = malloc (mem_size); + + if (!mem_base) + Sys_Error ("Can't allocate %d\n", mem_size); + + Memory_Init (mem_base, mem_size); +} + void Host_Init (void) { - if (COM_CheckParm ("-minmemory")) - host_parms.memsize = MINIMUM_MEMORY; - - if (host_parms.memsize < MINIMUM_MEMORY) - Sys_Error ("Only %4.1f megs of memory reported, can't execute game", - host_parms.memsize / (float) 0x100000); - Cvar_Init_Hash (); Cmd_Init_Hash (); - Memory_Init (host_parms.membase, host_parms.memsize); Cvar_Init (); Sys_Init_Cvars (); Sys_Init (); - cls.userinfo = Info_ParseString ("", MAX_INFO_STRING); - cl.serverinfo = Info_ParseString ("", MAX_INFO_STRING); - Cbuf_Init (); Cmd_Init (); - Locs_Init (); // execute +set as early as possible Cmd_StuffCmds_f (); @@ -1603,6 +1626,13 @@ Host_Init (void) Cmd_StuffCmds_f (); Cbuf_Execute_Sets (); + CL_Init_Memory (); + + cls.userinfo = Info_ParseString ("", MAX_INFO_STRING); + cl.serverinfo = Info_ParseString ("", MAX_INFO_STRING); + + Locs_Init (); + PI_Init (); CL_Cam_Init_Cvars (); @@ -1650,8 +1680,7 @@ Host_Init (void) CL_TimeFrames_Init(); // Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); - Con_Printf ("%4.1f megs RAM used.\n", host_parms.memsize / - (1024 * 1024.0)); + Con_Printf ("%4.1f megs RAM used.\n", cl_mem_size->value); vid_basepal = (byte *) COM_LoadHunkFile ("gfx/palette.lmp"); if (!vid_basepal) diff --git a/qw/source/cl_sys_sdl.c b/qw/source/cl_sys_sdl.c index 17aea71a9..3ce94d40e 100644 --- a/qw/source/cl_sys_sdl.c +++ b/qw/source/cl_sys_sdl.c @@ -161,7 +161,6 @@ Sys_LowFPPrecision (void) int SDL_main (int c, char **v) { - int j; double time, oldtime, newtime; #ifndef WIN32 @@ -174,18 +173,6 @@ SDL_main (int c, char **v) host_parms.argc = com_argc; host_parms.argv = com_argv; - host_parms.memsize = 16 * 1024 * 1024; // 16MB default heap - - j = COM_CheckParm ("-mem"); - if (j) - host_parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024); - host_parms.membase = malloc (host_parms.memsize); - - if (!host_parms.membase) { - Con_Printf ("Can't allocate memory for zone.\n"); - return 1; - } - #ifndef WIN32 noconinput = COM_CheckParm ("-noconinput"); if (!noconinput) diff --git a/qw/source/cl_sys_unix.c b/qw/source/cl_sys_unix.c index b6096b32e..a44f51810 100644 --- a/qw/source/cl_sys_unix.c +++ b/qw/source/cl_sys_unix.c @@ -157,7 +157,6 @@ main (int c, const char *v[]) { // static char cwd[1024]; double time, oldtime, newtime; - int j; // signal(SIGFPE, floating_point_exception_handler); signal (SIGFPE, SIG_IGN); @@ -168,18 +167,6 @@ main (int c, const char *v[]) host_parms.argc = com_argc; host_parms.argv = com_argv; - host_parms.memsize = 16 * 1024 * 1024; // 16MB default heap - - j = COM_CheckParm ("-mem"); - if (j) - host_parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024); - host_parms.membase = malloc (host_parms.memsize); - - if (!host_parms.membase) { - Con_Printf ("Can't allocate memory for zone.\n"); - return 1; - } - noconinput = COM_CheckParm ("-noconinput"); if (!noconinput) fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); diff --git a/qw/source/cl_sys_win.c b/qw/source/cl_sys_win.c index 41c3fc8b1..9fbb887f9 100644 --- a/qw/source/cl_sys_win.c +++ b/qw/source/cl_sys_win.c @@ -286,8 +286,6 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, // MSG msg; static char cwd[1024]; double time, oldtime, newtime; - int t; - MEMORYSTATUS lpBuffer; #ifdef SPLASH_SCREEN RECT rect; #endif @@ -299,9 +297,6 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, global_hInstance = hInstance; global_nCmdShow = nCmdShow; - lpBuffer.dwLength = sizeof (MEMORYSTATUS); - GlobalMemoryStatus (&lpBuffer); - if (!GetCurrentDirectory (sizeof (cwd), cwd)) Sys_Error ("Couldn't determine current directory"); @@ -355,32 +350,6 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, } #endif - // take the greater of all the available memory or half the total memory, - // but at least 8 Mb and no more than 16 Mb, unless they explicitly - // request otherwise - host_parms.memsize = lpBuffer.dwAvailPhys; - - if (host_parms.memsize < MINIMUM_WIN_MEMORY) - host_parms.memsize = MINIMUM_WIN_MEMORY; - - if (host_parms.memsize < (lpBuffer.dwTotalPhys >> 1)) - host_parms.memsize = lpBuffer.dwTotalPhys >> 1; - - if (host_parms.memsize > MAXIMUM_WIN_MEMORY) - host_parms.memsize = MAXIMUM_WIN_MEMORY; - - if (COM_CheckParm ("-mem")) { - t = COM_CheckParm ("-mem") + 1; - - if (t < com_argc) - host_parms.memsize = atoi (com_argv[t]) * 1024 * 1024; - } - - host_parms.membase = malloc (host_parms.memsize); - - if (!host_parms.membase) - Sys_Error ("Not enough memory free; check disk space\n"); - tevent = CreateEvent (NULL, FALSE, FALSE, NULL); if (!tevent) diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index 2e5e5d538..abf9b120f 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -105,6 +105,8 @@ double netdosvalues[DOSFLOODCMDS] = { 12, 1, 3, 1, 1, 1 }; cvar_t *fs_globalcfg; cvar_t *fs_usercfg; +cvar_t *sv_mem_size; + cvar_t *sv_console_plugin; cvar_t *sv_allow_status; @@ -2323,6 +2325,38 @@ SV_InitNet (void) // NET_StringToAdr ("192.246.40.70:27000", &idmaster_adr); } +void +SV_Init_Memory (void) +{ + int mem_parm = COM_CheckParm ("-mem"); + int mem_size; + void *mem_base; + + sv_mem_size = Cvar_Get ("sv_mem_size", "8", CVAR_NONE, NULL, + "Amount of memory (in MB) to allocate for the " + PROGRAM " heap"); + if (mem_parm) + Cvar_Set (sv_mem_size, com_argv[mem_parm + 1]); + + if (COM_CheckParm ("-minmemory")) + Cvar_SetValue (sv_mem_size, MINIMUM_MEMORY / (1024 * 1024.0)); + + Cvar_SetFlags (sv_mem_size, sv_mem_size->flags | CVAR_ROM); + + mem_size = (int) (sv_mem_size->value * 1024 * 1024); + + if (mem_size < MINIMUM_MEMORY) + Sys_Error ("Only %4.1f megs of memory reported, can't execute game", + mem_size / (float) 0x100000); + + mem_base = malloc (mem_size); + + if (!mem_base) + Sys_Error ("Can't allocate %d\n", mem_size); + + Memory_Init (mem_base, mem_size); +} + void SV_Init (void) { @@ -2330,30 +2364,18 @@ SV_Init (void) // COM_AddParm ("-game"); // COM_AddParm ("qw"); - if (COM_CheckParm ("-minmemory")) - host_parms.memsize = MINIMUM_MEMORY; - - if (host_parms.memsize < MINIMUM_MEMORY) - SV_Error ("Only %4.1f megs of memory reported, can't execute game", - host_parms.memsize / (float) 0x100000); - Sys_RegisterShutdown (SV_Shutdown); Cvar_Init_Hash (); Cmd_Init_Hash (); - Memory_Init (host_parms.membase, host_parms.memsize); Cvar_Init (); Sys_Init_Cvars (); Sys_Init (); Cvar_Get ("cmd_warncmd", "1", CVAR_NONE, NULL, NULL); - svs.info = Info_ParseString ("", MAX_SERVERINFO_STRING); - localinfo = Info_ParseString ("", 0); // unlimited - Cbuf_Init (); Cmd_Init (); - SV_InitOperatorCommands (); // execute +set as early as possible Cmd_StuffCmds_f (); @@ -2381,6 +2403,12 @@ SV_Init (void) Cmd_StuffCmds_f (); Cbuf_Execute_Sets (); + SV_Init_Memory (); + + svs.info = Info_ParseString ("", MAX_SERVERINFO_STRING); + localinfo = Info_ParseString ("", 0); // unlimited + SV_InitOperatorCommands (); + PI_Init (); sv_console_plugin = Cvar_Get ("sv_console_plugin", "server", @@ -2422,7 +2450,7 @@ SV_Init (void) host_initialized = true; // SV_Printf ("Exe: "__TIME__" "__DATE__"\n"); - SV_Printf ("%4.1f megabyte heap\n", host_parms.memsize / (1024 * 1024.0)); + SV_Printf ("%4.1f megabyte heap\n", sv_mem_size->value); SV_Printf ("\n"); SV_Printf ("%s server, Version %s (build %04d)\n", PROGRAM, VERSION, diff --git a/qw/source/sv_sys_unix.c b/qw/source/sv_sys_unix.c index ad6dc1ea9..f99e56214 100644 --- a/qw/source/sv_sys_unix.c +++ b/qw/source/sv_sys_unix.c @@ -107,7 +107,6 @@ main (int argc, const char *argv[]) { double time, oldtime, newtime; fd_set fdset; - int j; memset (&host_parms, 0, sizeof (host_parms)); @@ -115,14 +114,6 @@ main (int argc, const char *argv[]) host_parms.argc = com_argc; host_parms.argv = com_argv; - host_parms.memsize = 8 * 1024 * 1024; - - j = COM_CheckParm ("-mem"); - if (j) - host_parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024); - if ((host_parms.membase = malloc (host_parms.memsize)) == NULL) - Sys_Error ("Can't allocate %d\n", host_parms.memsize); - SV_Init (); Sys_RegisterShutdown (Net_LogStop); diff --git a/qw/source/sv_sys_win.c b/qw/source/sv_sys_win.c index 0238ad5ed..1434a2249 100644 --- a/qw/source/sv_sys_win.c +++ b/qw/source/sv_sys_win.c @@ -127,7 +127,7 @@ main (int argc, const char **argv) { double newtime, time, oldtime; fd_set fdset; - int sleep_msec, t; + int sleep_msec; struct timeval timeout; COM_InitArgv (argc, argv); @@ -135,16 +135,6 @@ main (int argc, const char **argv) host_parms.argc = com_argc; host_parms.argv = com_argv; - host_parms.memsize = 8 * 1024 * 1024; - - if ((t = COM_CheckParm ("-mem")) != 0 && t + 1 < com_argc) - host_parms.memsize = atoi (com_argv[t + 1]) * 1024 * 1024; - - host_parms.membase = malloc (host_parms.memsize); - - if (!host_parms.membase) - Sys_Error ("Insufficient memory.\n"); - SV_Init (); if (COM_CheckParm ("-nopriority")) {