*/
-// how many frames have occurred
-// (checked by Host_Error and Host_SaveConfig_f)
-int host_framecount = 0;
-
-// Cloudwalk: set when Host_Init is executed
-qboolean host_init = false;
-// LadyHavoc: set when quit is executed
-qboolean host_shuttingdown = false;
-
-// the accumulated mainloop time since application started (with filtering), without any slowmo or clamping
-double realtime;
-// the main loop wall time for this frame
-double host_dirtytime;
-
// current client
client_t *host_client;
-jmp_buf host_abortframe;
+host_t host;
// pretend frames take this amount of time (in seconds), 0 = realtime
cvar_t host_framerate = {CVAR_CLIENT | CVAR_SERVER, "host_framerate","0", "locks frame timing to this value in seconds, 0.05 is 20fps for example, note that this can easily run too fast, use cl_maxfps if you want to limit your framerate instead, or sys_ticrate to limit server speed"};
// in case we were previously nice, make us mean again
Sys_MakeProcessMean();
- longjmp (host_abortframe, 1);
+ longjmp (host.abortframe, 1);
}
/*
// LadyHavoc: if crashing very early, or currently shutting down, do
// Sys_Error instead
- if (host_framecount < 3 || host_shuttingdown)
+ if (host.framecount < 3 || host.state == host_shutdown)
Sys_Error ("Host_Error: %s", hosterrorstring1);
if (hosterror)
{
cls.state = ca_dedicated;
// check for -dedicated specifying how many players
- if (i && i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
- svs.maxclients = atoi (com_argv[i+1]);
+ if (i && i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1)
+ svs.maxclients = atoi (sys.argv[i+1]);
if (COM_CheckParm ("-listen"))
Con_Printf ("Only one of -dedicated or -listen can be specified\n");
// default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users)
if (i)
{
// default players unless specified
- if (i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
- svs.maxclients = atoi (com_argv[i+1]);
+ if (i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1)
+ svs.maxclients = atoi (sys.argv[i+1]);
}
else
{
// dedicated servers initialize the host but don't parse and set the
// config.cfg cvars
// LadyHavoc: don't save a config if it crashed in startup
- if (host_framecount >= 3 && cls.state != ca_dedicated && !COM_CheckParm("-benchmark") && !COM_CheckParm("-capturedemo"))
+ if (host.framecount >= 3 && cls.state != ca_dedicated && !COM_CheckParm("-benchmark") && !COM_CheckParm("-capturedemo"))
{
f = FS_OpenRealFile(file, "wb", false);
if (!f)
Host_Init();
- realtime = 0;
- host_dirtytime = Sys_DirtyTime();
- for (;;)
+ host.realtime = 0;
+ host.dirtytime = Sys_DirtyTime();
+
+ while(host.state != host_shutdown)
{
- if (setjmp(host_abortframe))
+ if (setjmp(host.abortframe))
{
SCR_ClearLoadingScreen(false);
continue; // something bad happened, or the server disconnected
}
- olddirtytime = host_dirtytime;
+ olddirtytime = host.dirtytime;
dirtytime = Sys_DirtyTime();
deltacleantime = dirtytime - olddirtytime;
if (deltacleantime < 0)
Con_Warnf("Host_Mingled: time stepped forward (went from %f to %f, difference %f)\n", olddirtytime, dirtytime, deltacleantime);
deltacleantime = 0;
}
- realtime += deltacleantime;
- host_dirtytime = dirtytime;
+ host.realtime += deltacleantime;
+ host.dirtytime = dirtytime;
cl_timer += deltacleantime;
sv_timer += deltacleantime;
// check for commands typed to the host
Host_GetConsoleCommands();
- // when a server is running we only execute console commands on server frames
- // (this mainly allows frikbot .way config files to work properly by staying in sync with the server qc)
- // otherwise we execute them on client frames
- if (sv.active ? sv_timer > 0 : cl_timer > 0)
- {
- // process console commands
-// R_TimeReport("preconsole");
- CL_VM_PreventInformationLeaks();
- Cbuf_Frame(&cmd_client);
- Cbuf_Frame(&cmd_server);
+ // process console commands
+// R_TimeReport("preconsole");
+ CL_VM_PreventInformationLeaks();
+ Cbuf_Frame(&cmd_client);
+ Cbuf_Frame(&cmd_server);
- if(sv.active)
- {
- Cbuf_Frame(&cmd_serverfromclient);
- }
+ if(sv.active)
+ Cbuf_Frame(&cmd_serverfromclient);
-// R_TimeReport("console");
- }
+// R_TimeReport("console");
//Con_Printf("%6.0f %6.0f\n", cl_timer * 1000000.0, sv_timer * 1000000.0);
// send all messages to the clients
SV_SendClientMessages();
- if (sv.paused == 1 && realtime > sv.pausedstart && sv.pausedstart > 0) {
- prog->globals.fp[OFS_PARM0] = realtime - sv.pausedstart;
+ if (sv.paused == 1 && host.realtime > sv.pausedstart && sv.pausedstart > 0) {
+ prog->globals.fp[OFS_PARM0] = host.realtime - sv.pausedstart;
PRVM_serverglobalfloat(time) = sv.time;
prog->ExecuteProgram(prog, PRVM_serverfunction(SV_PausedTic), "QC function SV_PausedTic is missing");
}
sv_timer = 0;
}
- host_framecount++;
+ host.framecount++;
}
+
+ Sys_Quit(0);
}
//============================================================================
Cvar_RegisterVariable(&locksession);
// load the session ID into the read-only cvar
- if ((i = COM_CheckParm("-sessionid")) && (i + 1 < com_argc))
+ if ((i = COM_CheckParm("-sessionid")) && (i + 1 < sys.argc))
{
- if(com_argv[i+1][0] == '.')
- Cvar_SetQuick(&sessionid, com_argv[i+1]);
+ if(sys.argv[i+1][0] == '.')
+ Cvar_SetQuick(&sessionid, sys.argv[i+1]);
else
{
- buf = (char *)Z_Malloc(strlen(com_argv[i+1]) + 2);
- dpsnprintf(buf, sizeof(buf), ".%s", com_argv[i+1]);
+ buf = (char *)Z_Malloc(strlen(sys.argv[i+1]) + 2);
+ dpsnprintf(buf, sizeof(buf), ".%s", sys.argv[i+1]);
Cvar_SetQuick(&sessionid, buf);
}
}
qboolean dedicated_server = COM_CheckParm("-dedicated") || !cl_available;
cmd_state_t *cmd = &cmd_client;
- host_init = true;
+ host.state = host_init;
if (COM_CheckParm("-profilegameonly"))
Sys_AllowProfiling(false);
// without crashing the whole game, so this should just be a short-time solution
// here comes the not so critical stuff
- if (setjmp(host_abortframe)) {
+ if (setjmp(host.abortframe)) {
return;
}
Cbuf_Execute(cmd);
}
- host_init = false;
+ host.state = host_active;
// run stuffcmds now, deferred previously because it can crash if a server starts that early
Cbuf_AddText(cmd,"stuffcmds\n");
// check for special benchmark mode
// COMMANDLINEOPTION: Client: -benchmark <demoname> 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 (i && i + 1 < sys.argc)
if (!sv.active && !cls.demoplayback && !cls.connect_trying)
{
- Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "timedemo %s\n", com_argv[i + 1]));
+ Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "timedemo %s\n", sys.argv[i + 1]));
Cbuf_Execute(&cmd_client);
}
// check for special demo mode
// COMMANDLINEOPTION: Client: -demo <demoname> runs a playdemo and quits
i = COM_CheckParm("-demo");
- if (i && i + 1 < com_argc)
+ if (i && i + 1 < sys.argc)
if (!sv.active && !cls.demoplayback && !cls.connect_trying)
{
- Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "playdemo %s\n", com_argv[i + 1]));
+ Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "playdemo %s\n", sys.argv[i + 1]));
Cbuf_Execute(&cmd_client);
}
// COMMANDLINEOPTION: Client: -capturedemo <demoname> captures a playdemo and quits
i = COM_CheckParm("-capturedemo");
- if (i && i + 1 < com_argc)
+ if (i && i + 1 < sys.argc)
if (!sv.active && !cls.demoplayback && !cls.connect_trying)
{
- Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "playdemo %s\ncl_capturevideo 1\n", com_argv[i + 1]));
+ Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "playdemo %s\ncl_capturevideo 1\n", sys.argv[i + 1]));
Cbuf_Execute(&cmd_client);
}
Con_Print("recursive shutdown\n");
return;
}
- if (setjmp(host_abortframe))
+ if (setjmp(host.abortframe))
{
Con_Print("aborted the quitting frame?!?\n");
return;