X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=host.c;h=d4a0d4d10167c191f5dbae297a21f78f05841f4c;hb=ff5947f97081e10c4ce112d4d51c2d1fa14ebba8;hp=39730caa98c71ab0fa565a9c3a3e7540f1796b8e;hpb=8468ffaf8162a4fe8361127385c40141c375661d;p=xonotic%2Fdarkplaces.git diff --git a/host.c b/host.c index 39730caa..d4a0d4d1 100644 --- a/host.c +++ b/host.c @@ -35,7 +35,8 @@ Memory is cleared / released when a server or client begins, not when they end. quakeparms_t host_parms; qboolean host_initialized; // true if into command execution -qboolean hostloopactive = 0; // LordHavoc: used to turn Host_Error into Sys_Error if Host_Frame has not yet run +qboolean host_loopactive = false; // LordHavoc: used to turn Host_Error into Sys_Error if starting up or shutting down +qboolean host_shuttingdown = false; // LordHavoc: set when quit is executed double host_frametime; double host_realframetime; // LordHavoc: the real frametime, before slowmo and clamping are applied (used for console scrolling) @@ -43,11 +44,7 @@ double realtime; // without any filtering or bounding double oldrealtime; // last frame run int host_framecount; -double sv_frametime; - -int host_hunklevel; - -int minimum_memory; +int forcedeveloper; // used for -developer commandline parameter, hacky hacky client_t *host_client; // current client @@ -124,8 +121,9 @@ void Host_Error (char *error, ...) va_list argptr; static qboolean inerror = false; - // LordHavoc: if host_frame loop has not been run yet, do a Sys_Error instead - if (!hostloopactive) + // LordHavoc: if first frame has not been shown, or currently shutting + // down, do Sys_Error instead + if (!host_loopactive || host_shuttingdown) { char string[4096]; va_start (argptr,error); @@ -165,6 +163,8 @@ void Host_Error (char *error, ...) longjmp (host_abortserver, 1); } +static mempool_t *clients_mempool; + /* ================ Host_FindMaxClients @@ -175,7 +175,7 @@ void Host_FindMaxClients (void) int i; svs.maxclients = 1; - + i = COM_CheckParm ("-dedicated"); if (i) { @@ -208,7 +208,11 @@ void Host_FindMaxClients (void) svs.maxclientslimit = svs.maxclients; if (svs.maxclientslimit < MAX_SCOREBOARD) // LordHavoc: upped listen mode limit from 4 to MAX_SCOREBOARD svs.maxclientslimit = MAX_SCOREBOARD; - svs.clients = Hunk_AllocName (svs.maxclientslimit*sizeof(client_t), "clients"); + if (!clients_mempool) + clients_mempool = Mem_AllocPool("clients"); + if (svs.clients) + Mem_Free(svs.clients); + svs.clients = Mem_Alloc(clients_mempool, svs.maxclientslimit*sizeof(client_t)); if (svs.maxclients > 1) Cvar_SetValue ("deathmatch", 1.0); @@ -225,7 +229,7 @@ Host_InitLocal void Host_InitLocal (void) { Host_InitCommands (); - + Cvar_RegisterVariable (&host_framerate); Cvar_RegisterVariable (&host_speeds); Cvar_RegisterVariable (&slowmo); @@ -242,6 +246,8 @@ void Host_InitLocal (void) Cvar_RegisterVariable (&noexit); Cvar_RegisterVariable (&skill); Cvar_RegisterVariable (&developer); + if (forcedeveloper) // make it real now that the cvar is registered + Cvar_SetValue("developer", 1); Cvar_RegisterVariable (&deathmatch); Cvar_RegisterVariable (&coop); @@ -269,7 +275,7 @@ void Host_WriteConfiguration (void) // dedicated servers initialize the host but don't parse and set the // config.cfg cvars - if (host_initialized & !isDedicated) + if (host_initialized && cls.state != ca_dedicated) { f = Qopen (va("%s/config.cfg",com_gamedir), "w"); if (!f) @@ -436,8 +442,7 @@ void Host_ShutdownServer(qboolean crash) sv.active = false; // stop all client sounds immediately - if (cls.state == ca_connected) - CL_Disconnect (); + CL_Disconnect (); // flush any pending messages - like the score!!! start = Sys_DoubleTime(); @@ -498,8 +503,6 @@ void Host_ClearMemory (void) { Con_DPrintf ("Clearing memory\n"); Mod_ClearAll (); - if (host_hunklevel) - Hunk_FreeToLowMark (host_hunklevel); cls.signon = 0; memset (&sv, 0, sizeof(sv)); @@ -597,7 +600,7 @@ void Host_ServerFrame (void) static double frametimetotal = 0, lastservertime = 0; frametimetotal += host_frametime; // LordHavoc: cap server at sys_ticrate in listen games - if (!isDedicated && svs.maxclients > 1 && ((realtime - lastservertime) < sys_ticrate.value)) + if (cls.state != ca_dedicated && svs.maxclients > 1 && ((realtime - lastservertime) < sys_ticrate.value)) return; // run the world state sv.frametime = pr_global_struct->frametime = frametimetotal; @@ -640,7 +643,6 @@ void _Host_Frame (float time) if (setjmp (host_abortserver) ) return; // something bad happened, or the server disconnected - hostloopactive = 1; // keep the random time dependent rand (); @@ -698,12 +700,12 @@ void _Host_Frame (float time) ui_update(); // update video - if (host_speeds.value) + if (host_speeds.integer) time1 = Sys_DoubleTime (); - SCR_UpdateScreen (); + CL_UpdateScreen (); - if (host_speeds.value) + if (host_speeds.integer) time2 = Sys_DoubleTime (); // update audio @@ -717,7 +719,7 @@ void _Host_Frame (float time) CDAudio_Update(); - if (host_speeds.value) + if (host_speeds.integer) { pass1 = (time1 - time3)*1000000; time3 = Sys_DoubleTime (); @@ -728,6 +730,7 @@ void _Host_Frame (float time) } host_framecount++; + host_loopactive = true; } void Host_Frame (float time) @@ -737,12 +740,12 @@ void Host_Frame (float time) static int timecount; int i, c, m; - if (!serverprofile.value) + if (!serverprofile.integer) { _Host_Frame (time); return; } - + time1 = Sys_DoubleTime (); _Host_Frame (time); time2 = Sys_DoubleTime (); @@ -769,6 +772,7 @@ void Host_Frame (float time) //============================================================================ void Render_Init(void); +void QuakeIO_Init(void); /* ==================== @@ -777,60 +781,37 @@ Host_Init */ void Host_Init (void) { - int i; - /* - if (standard_quake) - minimum_memory = MINIMUM_MEMORY; - else - minimum_memory = MINIMUM_MEMORY_LEVELPAK; - - if (COM_CheckParm ("-minmemory")) - host_parms.memsize = minimum_memory; - - if (host_parms.memsize < minimum_memory) - Sys_Error ("Only %4.1f megs of memory available, can't execute game", host_parms.memsize / (float)0x100000); - */ - - host_parms.memsize = DEFAULTMEM * 1024 * 1024; - - i = COM_CheckParm("-mem"); - if (i) - host_parms.memsize = (int) (atof(com_argv[i+1]) * 1024 * 1024); - - i = COM_CheckParm("-winmem"); - if (i) - host_parms.memsize = (int) (atof(com_argv[i+1]) * 1024 * 1024); - - i = COM_CheckParm("-heapsize"); - if (i) - host_parms.memsize = (int) (atof(com_argv[i+1]) * 1024); - - host_parms.membase = qmalloc(host_parms.memsize); - if (!host_parms.membase) - Sys_Error("Not enough memory free, close some programs and try again, or free disk space\n"); - com_argc = host_parms.argc; com_argv = host_parms.argv; + // FIXME: this is evil, but possibly temporary + if (COM_CheckParm("-developer")) + { + forcedeveloper = true; + developer.integer = 1; + developer.value = 1; + } - Memory_Init (host_parms.membase, host_parms.memsize); + Memory_Init (); + Cmd_Init (); + Memory_Init_Commands(); + R_Modules_Init(); Cbuf_Init (); - Cmd_Init (); + QuakeIO_Init (); V_Init (); - Chase_Init (); - COM_Init (host_parms.basedir); + COM_Init (); Host_InitLocal (); W_LoadWadFile ("gfx.wad"); Key_Init (); - Con_Init (); - M_Init (); + Con_Init (); + Chase_Init (); + M_Init (); PR_Init (); Mod_Init (); NET_Init (); SV_Init (); Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); - Con_Printf ("%4.1f megabyte heap\n",host_parms.memsize/(1024*1024.0)); - + if (cls.state != ca_dedicated) { VID_InitCvars(); @@ -856,9 +837,6 @@ void Host_Init (void) Cbuf_InsertText ("exec quake.rc\n"); - Hunk_AllocName (0, "-HOST_HUNKLEVEL-"); - host_hunklevel = Hunk_LowMark (); - host_initialized = true; Sys_Printf ("========Quake Initialized=========\n");