*/
-// how many frames have occurred
-// (checked by Host_Error and Host_SaveConfig_f)
-int host_framecount = 0;
-// 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);
}
/*
dpvsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr);
va_end (argptr);
- Con_Printf("Host_Error: %s\n", hosterrorstring1);
+ Con_Errorf("Host_Error: %s\n", hosterrorstring1);
// 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
{
extern cvar_t r_texture_jpeg_fastpicmip;
static void Host_InitLocal (void)
{
- Cmd_AddCommand(&cmd_client, "saveconfig", Host_SaveConfig_f, "save settings to config.cfg (or a specified filename) immediately (also automatic when quitting)");
- Cmd_AddCommand(&cmd_client, "loadconfig", Host_LoadConfig_f, "reset everything and reload configs");
- Cmd_AddCommand(&cmd_server, "saveconfig", Host_SaveConfig_f, "save settings to config.cfg (or a specified filename) immediately (also automatic when quitting)");
- Cmd_AddCommand(&cmd_server, "loadconfig", Host_LoadConfig_f, "reset everything and reload configs");
-
+ Cmd_AddCommand(CMD_SHARED, "saveconfig", Host_SaveConfig_f, "save settings to config.cfg (or a specified filename) immediately (also automatic when quitting)");
+ Cmd_AddCommand(CMD_SHARED, "loadconfig", Host_LoadConfig_f, "reset everything and reload configs");
Cvar_RegisterVariable (&cl_maxphysicsframesperserverframe);
Cvar_RegisterVariable (&host_framerate);
Cvar_RegisterVariable (&host_speeds);
// 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)
{
- Con_Printf("Couldn't write %s.\n", file);
+ Con_Errorf("Couldn't write %s.\n", file);
return;
}
Cbuf_InsertText(cmd, "alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec teu.rc\n");
else
Cbuf_InsertText(cmd, "alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec " STARTCONFIGFILENAME "\n");
+ Cbuf_Execute(cmd);
}
/*
double time2 = 0;
double time3 = 0;
double cl_timer = 0, sv_timer = 0;
- double clframetime, deltacleantime, olddirtytime, dirtytime;
+ double clframetime, time, oldtime, newtime;
double wait;
int pass1, pass2, pass3, i;
char vabuf[1024];
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;
- dirtytime = Sys_DirtyTime();
- deltacleantime = dirtytime - olddirtytime;
- if (deltacleantime < 0)
+ oldtime = host.dirtytime;
+ newtime = Sys_DirtyTime();
+ time = newtime - oldtime;
+ if (time < 0)
{
// warn if it's significant
- if (deltacleantime < -0.01)
- Con_Printf("Host_Mingled: time stepped backwards (went from %f to %f, difference %f)\n", olddirtytime, dirtytime, deltacleantime);
- deltacleantime = 0;
+ if (time < -0.01)
+ Con_Warnf("Host_Mingled: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, time);
+ time = 0;
}
- else if (deltacleantime >= 1800)
+ else if (time >= 1800)
{
- Con_Printf("Host_Mingled: time stepped forward (went from %f to %f, difference %f)\n", olddirtytime, dirtytime, deltacleantime);
- deltacleantime = 0;
+ Con_Warnf("Host_Mingled: time stepped forward (went from %f to %f, difference %f)\n", oldtime, newtime, time);
+ time = 0;
}
- realtime += deltacleantime;
- host_dirtytime = dirtytime;
+ host.realtime += time;
+ host.dirtytime = newtime;
- cl_timer += deltacleantime;
- sv_timer += deltacleantime;
+ cl_timer += time;
+ sv_timer += time;
if (!svs.threaded)
{
- svs.perf_acc_realtime += deltacleantime;
+ svs.perf_acc_realtime += time;
// Look for clients who have spawned
playing = false;
}
}
- if (slowmo.value < 0.00001 && slowmo.value != 0)
- Cvar_SetValueQuick(&slowmo, 0);
if (host_framerate.value < 0.00001 && host_framerate.value != 0)
Cvar_SetValueQuick(&host_framerate, 0);
// 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);
-
- if(sv.active)
- {
- Cbuf_Frame(&cmd_serverfromclient);
- }
+ // process console commands
+// R_TimeReport("preconsole");
+ CL_VM_PreventInformationLeaks();
+ Cbuf_Frame(&cmd_client);
+ Cbuf_Frame(&cmd_server);
- if(cls.netcon)
- {
- Cbuf_Frame(&cmd_clientfromserver);
- }
+ 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);
framelimit = cl_maxphysicsframesperserverframe.integer;
aborttime = Sys_DirtyTime() + 0.1;
}
- if(slowmo.value > 0 && slowmo.value < 1)
- advancetime = min(advancetime, 0.1 / slowmo.value);
+ if(host_timescale.value > 0 && host_timescale.value < 1)
+ advancetime = min(advancetime, 0.1 / host_timescale.value);
else
advancetime = min(advancetime, 0.1);
if(advancetime > 0)
{
- offset = Sys_DirtyTime() - dirtytime;if (offset < 0 || offset >= 1800) offset = 0;
+ offset = Sys_DirtyTime() - newtime;if (offset < 0 || offset >= 1800) offset = 0;
offset += sv_timer;
++svs.perf_acc_offset_samples;
svs.perf_acc_offset += offset;
// only advance time if not paused
// the game also pauses in singleplayer when menu or console is used
- sv.frametime = advancetime * slowmo.value;
+ sv.frametime = advancetime * host_timescale.value;
if (host_framerate.value)
sv.frametime = host_framerate.value;
if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive || cl.csqc_paused)))
// 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");
}
// scale playback speed of demos by slowmo cvar
if (cls.demoplayback)
{
- clframetime *= slowmo.value;
+ clframetime *= host_timescale.value;
// if demo playback is paused, don't advance time at all
if (cls.demopaused)
clframetime = 0;
R_TimeReport("client");
CL_UpdateScreen();
- CL_MeshEntities_Reset();
R_TimeReport("render");
if (host_speeds.integer)
sv_timer = 0;
}
- host_framecount++;
+ host.framecount++;
}
+
+ Sys_Quit(0);
}
//============================================================================
static void Host_InitSession(void)
{
int i;
+ char *buf;
Cvar_RegisterVariable(&sessionid);
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))
{
- char vabuf[1024];
- 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
- Cvar_SetQuick(&sessionid, va(vabuf, sizeof(vabuf), ".%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);
+ }
}
}
void Host_LockSession(void)
{
if(locksession.integer == 2)
{
- Con_Printf("WARNING: session lock %s could not be acquired. Please run with -sessionid and an unique session name. Continuing anyway.\n", p);
+ Con_Warnf("WARNING: session lock %s could not be acquired. Please run with -sessionid and an unique session name. Continuing anyway.\n", p);
}
else
{
qboolean dedicated_server = COM_CheckParm("-dedicated") || !cl_available;
cmd_state_t *cmd = &cmd_client;
+ host.state = host_init;
+
if (COM_CheckParm("-profilegameonly"))
Sys_AllowProfiling(false);
Thread_Init();
TaskQueue_Init();
- if (cls.state == ca_dedicated)
- {
- cmd = &cmd_server;
- Cmd_AddCommand(&cmd_server, "disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)");
- }
- else
- {
- Con_DPrintf("Initializing client\n");
-
- R_Modules_Init();
- Palette_Init();
-#ifdef CONFIG_MENU
- MR_Init_Commands();
-#endif
- VID_Shared_Init();
- VID_Init();
- Render_Init();
- S_Init();
- CDAudio_Init();
- Key_Init();
- CL_Init();
- }
+ CL_Init();
// save off current state of aliases, commands and cvars for later restore if FS_GameDir_f is called
// NOTE: menu commands are freed by Cmd_RestoreInitState
// 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;
}
Host_AddConfigText(cmd);
- Cbuf_Execute(cmd);
- // if stuffcmds wasn't run, then quake.rc is probably missing, use default
- if (!host_stuffcmdsrun)
+ // if quake.rc is missing, use default
+ if (!FS_FileExists("quake.rc"))
{
- Cbuf_AddText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\nstuffcmds\n");
+ Cbuf_AddText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n");
Cbuf_Execute(cmd);
}
+ host.state = host_active;
+
Log_Start();
// put up the loading image so the user doesn't stare at a black screen...
// 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;