X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=host.c;h=58988498edf2d9728161c40d23dd4efa3988dae7;hb=73a27983818cae259317b91999f10f769fc792ee;hp=420984600c76383fdc8386415d8ad2d394ca7c5d;hpb=f4ca2e493b0fbe2e91293c727ac119c371feffda;p=xonotic%2Fdarkplaces.git diff --git a/host.c b/host.c index 42098460..58988498 100644 --- a/host.c +++ b/host.c @@ -112,7 +112,7 @@ void Host_Error (const char *error, ...) va_list argptr; va_start (argptr,error); - vsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr); + dpvsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr); va_end (argptr); Con_Printf("Host_Error: %s\n", hosterrorstring1); @@ -152,8 +152,6 @@ void Host_Error (const char *error, ...) longjmp (host_abortserver, 1); } -mempool_t *sv_clients_mempool = NULL; - void Host_ServerOptions (void) { int i, numplayers; @@ -216,8 +214,7 @@ void Host_ServerOptions (void) Cvar_SetValueQuick(&deathmatch, 1); svs.maxclients = numplayers; - sv_clients_mempool = Mem_AllocPool("server clients", 0, NULL); - svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients); + svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients); } /* @@ -229,7 +226,7 @@ void Host_SaveConfig_f(void); void Host_InitLocal (void) { Host_InitCommands (); - + Cmd_AddCommand("saveconfig", Host_SaveConfig_f); Cvar_RegisterVariable (&host_framerate); @@ -278,9 +275,10 @@ void Host_SaveConfig_f(void) // dedicated servers initialize the host but don't parse and set the // config.cfg cvars - if (host_initialized && cls.state != ca_dedicated) + // LordHavoc: save a config only after Host_Frame finished the first frame + if (host_initialized && host_loopactive && cls.state != ca_dedicated) { - f = FS_Open ("config.cfg", "w", false); + f = FS_Open ("config.cfg", "wb", false, false); if (!f) { Con_Print("Couldn't write config.cfg.\n"); @@ -323,7 +321,7 @@ void SV_ClientPrintf(const char *fmt, ...) char msg[4096]; va_start(argptr,fmt); - vsnprintf(msg,sizeof(msg),fmt,argptr); + dpvsnprintf(msg,sizeof(msg),fmt,argptr); va_end(argptr); SV_ClientPrint(msg); @@ -367,7 +365,7 @@ void SV_BroadcastPrintf(const char *fmt, ...) char msg[4096]; va_start(argptr,fmt); - vsnprintf(msg,sizeof(msg),fmt,argptr); + dpvsnprintf(msg,sizeof(msg),fmt,argptr); va_end(argptr); SV_BroadcastPrint(msg); @@ -386,7 +384,7 @@ void Host_ClientCommands(const char *fmt, ...) char string[1024]; va_start(argptr,fmt); - vsnprintf(string, sizeof(string), fmt, argptr); + dpvsnprintf(string, sizeof(string), fmt, argptr); va_end(argptr); MSG_WriteByte(&host_client->message, svc_stufftext); @@ -464,13 +462,13 @@ void SV_DropClient(qboolean crash) EntityFrame4_FreeDatabase(host_client->entitydatabase4); if (host_client->entitydatabase5) EntityFrame5_FreeDatabase(host_client->entitydatabase5); - + if (sv.active) { // clear a fields that matter to DP_SV_CLIENTNAME and DP_SV_CLIENTCOLORS, and also frags ED_ClearEdict(host_client->edict); } - + // clear the client struct (this sets active to false) memset(host_client, 0, sizeof(*host_client)); @@ -563,7 +561,7 @@ qboolean Host_FilterTime (double time) double timecap, timeleft; realtime += time; - if (sys_ticrate.value < 0.01 || sys_ticrate.value > 0.10001) + if (sys_ticrate.value < 0.00999 || sys_ticrate.value > 0.10001) Cvar_SetValue("sys_ticrate", bound(0.01, sys_ticrate.value, 0.1)); if (slowmo.value < 0) Cvar_SetValue("slowmo", 0); @@ -669,30 +667,28 @@ void Host_ServerFrame (void) { // never run more than 5 frames at a time as a sanity limit int framecount, framelimit = 5; - double advancetime, newtime; + double advancetime; if (!sv.active) + { + sv.timer = 0; return; - newtime = Sys_DoubleTime(); - // if this is the first frame of a new server, ignore the huge time difference - if (!sv.timer) - sv.timer = newtime; - // if we're already past the new time, don't run a frame - // (does not happen if cl.islocalgame) - if (sv.timer > newtime) - return; + } + sv.timer += host_realframetime; // run the world state // don't allow simulation to run too fast or too slow or logic glitches can occur - for (framecount = 0;framecount < framelimit && sv.timer < newtime;framecount++) + for (framecount = 0;framecount < framelimit && sv.timer > 0;framecount++) { if (cl.islocalgame) - advancetime = min(newtime - sv.timer, sys_ticrate.value); + advancetime = min(sv.timer, sys_ticrate.value); else advancetime = sys_ticrate.value; - sv.timer += advancetime; + sv.timer -= advancetime; // only advance time if not paused // the game also pauses in singleplayer when menu or console is used sv.frametime = advancetime * slowmo.value; + if (host_framerate.value) + sv.frametime = host_framerate.value; if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive))) sv.frametime = 0; @@ -719,8 +715,8 @@ void Host_ServerFrame (void) NetConn_Heartbeat(0); } // if we fell behind too many frames just don't worry about it - if (sv.timer < newtime) - sv.timer = newtime; + if (sv.timer > 0) + sv.timer = 0; } @@ -812,7 +808,7 @@ void _Host_Frame (float time) time2 = Sys_DoubleTime(); // update audio - if (cls.signon == SIGNONS && cl.viewentity >= 0 && cl.viewentity < MAX_EDICTS && cl_entities[cl.viewentity].state_current.active) + if (cls.signon == SIGNONS && cl_entities[cl.viewentity].state_current.active) { // LordHavoc: this used to use renderer variables (eww) S_Update(&cl_entities[cl.viewentity].render.matrix); @@ -900,18 +896,18 @@ void Host_Init (void) Cmd_Init(); Memory_Init_Commands(); - R_Modules_Init(); + Con_Init(); Cbuf_Init(); + R_Modules_Init(); V_Init(); COM_Init(); - Host_InitLocal(); Key_Init(); - Con_Init(); PR_Init(); PRVM_Init(); Mod_Init(); NetConn_Init(); SV_Init(); + Host_InitLocal(); Con_Printf("Builddate: %s\n", buildstring); @@ -928,11 +924,16 @@ void Host_Init (void) CL_Init(); } + Cbuf_Execute(); + // only cvars are executed when host_initialized == false if (gamemode == GAME_TEU) Cbuf_InsertText("exec teu.rc\n"); else Cbuf_InsertText("exec quake.rc\n"); + + Cbuf_Execute(); + Cbuf_Execute(); Cbuf_Execute(); host_initialized = true; @@ -942,11 +943,35 @@ void Host_Init (void) if (cls.state != ca_dedicated) { VID_Open(); + CDAudio_Startup(); CL_InitTEnts (); // We must wait after sound startup to load tent sounds SCR_BeginLoadingPlaque(); MR_Init(); } + // set up the default startmap_sp and startmap_dm aliases, mods can + // override these + if (gamemode == GAME_NEHAHRA) + { + Cbuf_InsertText ("alias startmap_sp \"map nehstart\"\n"); + Cbuf_InsertText ("alias startmap_dm \"map nehstart\"\n"); + } + else if (gamemode == GAME_TRANSFUSION) + { + Cbuf_InsertText ("alias startmap_sp \"map e1m1\"\n"); + Cbuf_InsertText ("alias startmap_dm \"map bb1\"\n"); + } + else if (gamemode == GAME_NEXUIZ) + { + Cbuf_InsertText ("alias startmap_sp \"map nexdm01\"\n"); + Cbuf_InsertText ("alias startmap_dm \"map nexdm01\"\n"); + } + else + { + Cbuf_InsertText ("alias startmap_sp \"map start\"\n"); + Cbuf_InsertText ("alias startmap_dm \"map start\"\n"); + } + // stuff it again so the first host frame will execute it again, this time // in its entirety if (gamemode == GAME_TEU) @@ -954,26 +979,41 @@ void Host_Init (void) else Cbuf_InsertText("exec quake.rc\n"); - if (!sv.active && (cls.state == ca_dedicated || COM_CheckParm("-listen"))) - { - if (gamemode == GAME_TRANSFUSION) - Cbuf_InsertText ("map bb1\n"); - else if (gamemode == GAME_NEXUIZ) - Cbuf_InsertText ("map nexdm01\n"); - else - Cbuf_InsertText ("map start\n"); - } + Cbuf_Execute(); + Cbuf_Execute(); + Cbuf_Execute(); + + // We must wait for the log_file cvar to be initialized to start the log + Log_Start (); + + if (cls.state == ca_dedicated || COM_CheckParm("-listen")) + if (!sv.active && !cls.demoplayback && !cls.connect_trying) + Cbuf_InsertText ("startmap_dm\n"); + + Cbuf_Execute(); // check for special benchmark mode // COMMANDLINEOPTION: Client: -benchmark runs a timedemo and quits, results of any timedemo can be found in gamedir/benchmark.log (for example id1/benchmark.log) i = COM_CheckParm("-benchmark"); if (i && i + 1 < com_argc) + if (!sv.active && !cls.demoplayback && !cls.connect_trying) Cbuf_InsertText(va("timedemo %s\n", com_argv[i + 1])); Cbuf_Execute(); - // We must wait for the log_file cvar to be initialized to start the log - Log_Start (); + if (!sv.active && !cls.demoplayback && !cls.connect_trying) + { + Cbuf_InsertText("togglemenu\n"); + if (gamemode == GAME_NEXUIZ) + { + Cbuf_InsertText("playvideo logo\n"); + Cbuf_InsertText("cd loop 1\n"); + } + } + + Cbuf_Execute(); + Cbuf_Execute(); + Cbuf_Execute(); } @@ -1014,7 +1054,10 @@ void Host_Shutdown(void) Host_SaveConfig_f(); CDAudio_Shutdown (); + S_Terminate (); NetConn_Shutdown (); + PR_Shutdown (); + Cbuf_Shutdown (); if (cls.state != ca_dedicated) { @@ -1026,5 +1069,7 @@ void Host_Shutdown(void) CL_Shutdown(); Sys_Shutdown(); Log_Close (); + COM_Shutdown (); + Memory_Shutdown(); }