mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
give nq host_mem_size so -mem can be a cvar (similar to sv_mem_size and
cl_mem_size in qw).
This commit is contained in:
parent
9aace57b07
commit
b6c331736a
10 changed files with 91 additions and 118 deletions
|
@ -78,6 +78,7 @@ void Sys_Init_Cvars (void);
|
|||
// memory protection
|
||||
//
|
||||
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length);
|
||||
void Sys_PageIn (void *ptr, int size);
|
||||
|
||||
//
|
||||
// system IO
|
||||
|
|
|
@ -71,6 +71,8 @@ cvar_t *sys_extrasleep;
|
|||
cvar_t *sys_dead_sleep;
|
||||
cvar_t *sys_sleep;
|
||||
|
||||
int sys_checksum;
|
||||
|
||||
static sys_printf_t sys_printf_function = Sys_StdPrintf;
|
||||
|
||||
typedef struct shutdown_list_s {
|
||||
|
@ -365,3 +367,24 @@ Sys_TimeID (void) //FIXME I need a new name, one that doesn't make me feel 3 fee
|
|||
#endif
|
||||
return val;
|
||||
}
|
||||
|
||||
void
|
||||
Sys_PageIn (void *ptr, int size)
|
||||
{
|
||||
//may or may not be useful in linux #ifdef WIN32
|
||||
byte *x;
|
||||
int m, n;
|
||||
|
||||
// touch all the memory to make sure it's there. The 16-page skip is to
|
||||
// keep Win 95 from thinking we're trying to page ourselves in (we are
|
||||
// doing that, of course, but there's no reason we shouldn't)
|
||||
x = (byte *) ptr;
|
||||
|
||||
for (n = 0; n < 4; n++) {
|
||||
for (m = 0; m < (size - 16 * 0x1000); m += 4) {
|
||||
sys_checksum += *(int *) &x[m];
|
||||
sys_checksum += *(int *) &x[m + 16 * 0x1000];
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ extern double realtime; // not bounded in any way, changed at
|
|||
void Host_ClearMemory (void);
|
||||
void Host_ServerFrame (void);
|
||||
void Host_InitCommands (void);
|
||||
void Host_Init (quakeparms_t *parms);
|
||||
void Host_Init ();
|
||||
void Host_Skin_Init (void);
|
||||
void Host_Skin_Init_Cvars (void);
|
||||
void Host_Shutdown(void);
|
||||
|
|
|
@ -96,6 +96,8 @@ byte *vid_basepal;
|
|||
cvar_t *fs_globalcfg;
|
||||
cvar_t *fs_usercfg;
|
||||
|
||||
cvar_t *host_mem_size;
|
||||
|
||||
cvar_t *host_framerate;
|
||||
cvar_t *host_speeds;
|
||||
|
||||
|
@ -279,7 +281,7 @@ Host_WriteConfiguration (void)
|
|||
|
||||
// dedicated servers initialize the host but don't parse and set the
|
||||
// config.cfg cvars
|
||||
if (!isDedicated && cl_writecfg->int_val && host_initialized) {
|
||||
if (host_initialized && !isDedicated && cl_writecfg->int_val) {
|
||||
char *path = va ("%s/config.cfg", com_gamedir);
|
||||
f = Qopen (path, "w");
|
||||
if (!f) {
|
||||
|
@ -859,24 +861,47 @@ check_quakerc (void)
|
|||
}
|
||||
|
||||
void
|
||||
Host_Init (quakeparms_t *parms)
|
||||
CL_Init_Memory (void)
|
||||
{
|
||||
int mem_parm = COM_CheckParm ("-mem");
|
||||
int mem_size;
|
||||
void *mem_base;
|
||||
|
||||
if (standard_quake)
|
||||
minimum_memory = MINIMUM_MEMORY;
|
||||
else
|
||||
minimum_memory = MINIMUM_MEMORY_LEVELPAK;
|
||||
|
||||
host_mem_size = Cvar_Get ("host_mem_size", "16", CVAR_NONE, NULL,
|
||||
"Amount of memory (in MB) to allocate for the "
|
||||
PROGRAM " heap");
|
||||
if (mem_parm)
|
||||
Cvar_Set (host_mem_size, com_argv[mem_parm + 1]);
|
||||
|
||||
if (COM_CheckParm ("-minmemory"))
|
||||
parms->memsize = minimum_memory;
|
||||
Cvar_SetValue (host_mem_size, minimum_memory / (1024 * 1024.0));
|
||||
|
||||
host_parms = *parms;
|
||||
Cvar_SetFlags (host_mem_size, host_mem_size->flags | CVAR_ROM);
|
||||
|
||||
if (parms->memsize < minimum_memory)
|
||||
Sys_Error ("Only %4.1fMB of memory available, can't execute game",
|
||||
parms->memsize / (float) 0x100000);
|
||||
mem_size = (int) (host_mem_size->value * 1024 * 1024);
|
||||
|
||||
com_argc = parms->argc;
|
||||
com_argv = parms->argv;
|
||||
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);
|
||||
|
||||
Sys_PageIn (mem_base, mem_size);
|
||||
Memory_Init (mem_base, mem_size);
|
||||
}
|
||||
|
||||
void
|
||||
Host_Init (void)
|
||||
{
|
||||
Con_Printf ("Host_Init\n");
|
||||
|
||||
Cvar_Init_Hash ();
|
||||
Cmd_Init_Hash ();
|
||||
|
@ -913,7 +938,7 @@ Host_Init (quakeparms_t *parms)
|
|||
Cmd_StuffCmds_f ();
|
||||
Cbuf_Execute_Sets ();
|
||||
|
||||
Memory_Init (parms->membase, parms->memsize);
|
||||
CL_Init_Memory ();
|
||||
|
||||
pr_gametype = "netquake";
|
||||
|
||||
|
@ -958,7 +983,7 @@ Host_Init (quakeparms_t *parms)
|
|||
|
||||
GIB_Init ();
|
||||
|
||||
Host_InitVCR (parms);
|
||||
Host_InitVCR (&host_parms);
|
||||
Host_InitLocal ();
|
||||
|
||||
NET_Init ();
|
||||
|
@ -972,7 +997,7 @@ Host_Init (quakeparms_t *parms)
|
|||
SV_Init ();
|
||||
|
||||
// Con_Printf ("Exe: " __TIME__ " " __DATE__ "\n");
|
||||
Con_Printf ("%4.1f megabyte heap\n", parms->memsize / (1024 * 1024.0));
|
||||
Con_Printf ("%4.1f megabyte heap\n", host_mem_size->value);
|
||||
|
||||
if (cls.state != ca_dedicated) {
|
||||
vid_basepal = (byte *) COM_LoadHunkFile ("gfx/palette.lmp");
|
||||
|
|
|
@ -164,7 +164,6 @@ Sys_LowFPPrecision (void)
|
|||
int
|
||||
SDL_main (int c, char **v)
|
||||
{
|
||||
int j;
|
||||
double time, oldtime, newtime;
|
||||
|
||||
#ifndef WIN32
|
||||
|
@ -177,18 +176,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)
|
||||
|
@ -198,7 +185,7 @@ SDL_main (int c, char **v)
|
|||
Sys_RegisterShutdown (Host_Shutdown);
|
||||
Sys_RegisterShutdown (shutdown);
|
||||
|
||||
Host_Init (&host_parms);
|
||||
Host_Init ();
|
||||
|
||||
oldtime = Sys_DoubleTime ();
|
||||
while (1) {
|
||||
|
|
|
@ -150,34 +150,23 @@ main (int c, const char *v[])
|
|||
{
|
||||
|
||||
double time, oldtime, newtime;
|
||||
quakeparms_t parms;
|
||||
int j;
|
||||
|
||||
signal (SIGFPE, SIG_IGN);
|
||||
|
||||
memset (&parms, 0, sizeof (parms));
|
||||
memset (&host_parms, 0, sizeof (host_parms));
|
||||
|
||||
COM_InitArgv (c, v);
|
||||
parms.argc = com_argc;
|
||||
parms.argv = com_argv;
|
||||
host_parms.argc = com_argc;
|
||||
host_parms.argv = com_argv;
|
||||
|
||||
isDedicated = (COM_CheckParm ("-dedicated") != 0);
|
||||
|
||||
parms.memsize = 16 * 1024 * 1024;
|
||||
|
||||
j = COM_CheckParm ("-mem");
|
||||
if (j)
|
||||
parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024);
|
||||
if ((parms.membase = malloc (parms.memsize)) == NULL)
|
||||
Sys_Error ("Can't allocate %d\n", parms.memsize);
|
||||
|
||||
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
||||
|
||||
Sys_RegisterShutdown (Host_Shutdown);
|
||||
Sys_RegisterShutdown (shutdown);
|
||||
|
||||
Con_Printf ("Host_Init\n");
|
||||
Host_Init (&parms);
|
||||
Host_Init ();
|
||||
|
||||
if (!sys_nostdout->int_val) {
|
||||
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
||||
|
|
|
@ -143,43 +143,33 @@ int
|
|||
main (int argc, const char **argv)
|
||||
{
|
||||
double time, oldtime, newtime;
|
||||
quakeparms_t parms;
|
||||
const char *newargv[256];
|
||||
int j;
|
||||
|
||||
signal (SIGFPE, SIG_IGN);
|
||||
|
||||
memset (&parms, 0, sizeof (parms));
|
||||
memset (&host_parms, 0, sizeof (host_parms));
|
||||
|
||||
COM_InitArgv (argc, argv);
|
||||
|
||||
// dedicated server ONLY!
|
||||
if (!COM_CheckParm ("-dedicated")) {
|
||||
const char **newargv;
|
||||
|
||||
newargv = malloc ((argc + 2) * sizeof (*newargv));
|
||||
memcpy (newargv, argv, argc * 4);
|
||||
newargv[argc] = "-dedicated";
|
||||
argc++;
|
||||
newargv[argc++] = "-dedicated";
|
||||
newargv[argc] = 0;
|
||||
argv = newargv;
|
||||
COM_InitArgv (argc, argv);
|
||||
host_parms.argc = com_argc;
|
||||
host_parms.argv = com_argv;
|
||||
}
|
||||
|
||||
parms.argc = com_argc;
|
||||
parms.argv = com_argv;
|
||||
|
||||
parms.memsize = 16 * 1024 * 1024;
|
||||
|
||||
j = COM_CheckParm ("-mem");
|
||||
if (j)
|
||||
parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024);
|
||||
if ((parms.membase = malloc (parms.memsize)) == NULL)
|
||||
Sys_Error ("Can't allocate %d\n", parms.memsize);
|
||||
|
||||
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
||||
|
||||
Sys_RegisterShutdown (Host_Shutdown);
|
||||
Sys_RegisterShutdown (shutdown);
|
||||
|
||||
Sys_Printf ("Host_Init\n");
|
||||
Host_Init (&parms);
|
||||
Host_Init ();
|
||||
|
||||
oldtime = Sys_DoubleTime () - 0.1;
|
||||
while (1) { // Main message loop
|
||||
|
|
|
@ -77,27 +77,6 @@ void MaskExceptions (void);
|
|||
void Sys_PushFPCW_SetHigh (void);
|
||||
void Sys_PopFPCW (void);
|
||||
|
||||
volatile int sys_checksum;
|
||||
|
||||
|
||||
void
|
||||
Sys_PageIn (void *ptr, int size)
|
||||
{
|
||||
byte *x;
|
||||
int m, n;
|
||||
|
||||
// touch all the memory to make sure it's there. The 16-page skip is to
|
||||
// keep Win 95 from thinking we're trying to page ourselves in (we are
|
||||
// doing that, of course, but there's no reason we shouldn't)
|
||||
x = (byte *) ptr;
|
||||
|
||||
for (n = 0; n < 4; n++) {
|
||||
for (m = 0; m < (size - 16 * 0x1000); m += 4) {
|
||||
sys_checksum += *(int *) &x[m];
|
||||
sys_checksum += *(int *) &x[m + 16 * 0x1000];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE IO ====================================================================
|
||||
|
||||
|
@ -293,7 +272,6 @@ int WINAPI
|
|||
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
quakeparms_t parms;
|
||||
double time, oldtime, newtime;
|
||||
MEMORYSTATUS lpBuffer;
|
||||
static char cwd[1024];
|
||||
|
@ -316,16 +294,16 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
|||
if (cwd[strlen (cwd) - 1] == '/')
|
||||
cwd[strlen (cwd) - 1] = 0;
|
||||
|
||||
parms.argc = 1;
|
||||
host_parms.argc = 1;
|
||||
argv[0] = empty_string;
|
||||
|
||||
while (*lpCmdLine && (parms.argc < MAX_NUM_ARGVS)) {
|
||||
while (*lpCmdLine && (host_parms.argc < MAX_NUM_ARGVS)) {
|
||||
while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
|
||||
lpCmdLine++;
|
||||
|
||||
if (*lpCmdLine) {
|
||||
argv[parms.argc] = lpCmdLine;
|
||||
parms.argc++;
|
||||
argv[host_parms.argc] = lpCmdLine;
|
||||
host_parms.argc++;
|
||||
|
||||
while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
|
||||
lpCmdLine++;
|
||||
|
@ -337,12 +315,9 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
|||
}
|
||||
}
|
||||
|
||||
parms.argv = argv;
|
||||
|
||||
COM_InitArgv (parms.argc, (const char**)parms.argv);
|
||||
|
||||
parms.argc = com_argc;
|
||||
parms.argv = com_argv;
|
||||
COM_InitArgv (host_parms.argc, (const char**)host_parms.argv);
|
||||
host_parms.argc = com_argc;
|
||||
host_parms.argv = com_argv;
|
||||
|
||||
isDedicated = (COM_CheckParm ("-dedicated") != 0);
|
||||
|
||||
|
@ -365,6 +340,7 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
|||
SetForegroundWindow (hwnd_dialog);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// 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
|
||||
|
@ -378,20 +354,7 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
|||
|
||||
if (parms.memsize > MAXIMUM_WIN_MEMORY)
|
||||
parms.memsize = MAXIMUM_WIN_MEMORY;
|
||||
|
||||
if (COM_CheckParm ("-mem")) {
|
||||
t = COM_CheckParm ("-mem") + 1;
|
||||
|
||||
if (t < com_argc)
|
||||
parms.memsize = atoi (com_argv[t]) * 1024 * 1024;
|
||||
}
|
||||
|
||||
parms.membase = malloc (parms.memsize);
|
||||
|
||||
if (!parms.membase)
|
||||
Sys_Error ("Not enough memory free; check disk space\n");
|
||||
|
||||
Sys_PageIn (parms.membase, parms.memsize);
|
||||
#endif
|
||||
|
||||
tevent = CreateEvent (NULL, FALSE, FALSE, NULL);
|
||||
|
||||
|
@ -431,8 +394,7 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
|||
Sys_RegisterShutdown (Host_Shutdown);
|
||||
Sys_RegisterShutdown (shutdown);
|
||||
|
||||
Con_Printf ("Host_Init\n");
|
||||
Host_Init (&parms);
|
||||
Host_Init ();
|
||||
|
||||
oldtime = Sys_DoubleTime ();
|
||||
|
||||
|
|
|
@ -126,14 +126,10 @@ const char *newargv[256];
|
|||
int
|
||||
main (int argc, const char **argv)
|
||||
{
|
||||
quakeparms_t parms;
|
||||
double time, oldtime;
|
||||
|
||||
memset (&parms, 0, sizeof (parms));
|
||||
memset (&host_parms, 0, sizeof (host_parms));
|
||||
|
||||
parms.memsize = 16384 * 1024;
|
||||
if (!(parms.membase = malloc (parms.memsize)))
|
||||
Sys_Error ("Can't allocate %d\n", parms.memsize);
|
||||
#if 0
|
||||
_getcwd (cwd, sizeof (cwd));
|
||||
if (cwd[Q_strlen (cwd) - 1] == '\\')
|
||||
|
@ -150,14 +146,13 @@ main (int argc, const char **argv)
|
|||
COM_InitArgv (argc, argv);
|
||||
}
|
||||
|
||||
parms.argc = com_argc;
|
||||
parms.argv = com_argv;
|
||||
host_parms.argc = com_argc;
|
||||
host_parms.argv = com_argv;
|
||||
|
||||
Sys_RegisterShutdown (Host_Shutdown);
|
||||
Sys_RegisterShutdown (shutdown);
|
||||
|
||||
Con_Printf ("Host_Init\n");
|
||||
Host_Init (&parms);
|
||||
Host_Init ();
|
||||
|
||||
oldtime = Sys_DoubleTime ();
|
||||
|
||||
|
|
|
@ -1598,6 +1598,7 @@ CL_Init_Memory (void)
|
|||
if (!mem_base)
|
||||
Sys_Error ("Can't allocate %d\n", mem_size);
|
||||
|
||||
Sys_PageIn (mem_base, mem_size);
|
||||
Memory_Init (mem_base, mem_size);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue