/*
-A server can allways be started, even if the system started out as a client
+A server can always be started, even if the system started out as a client
to a remote system.
A client can NOT be started if the system started as a dedicated server.
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
double host_frametime;
+double host_realframetime; // LordHavoc: the real frametime, before slowmo and clamping are applied (used for console scrolling)
double host_time;
double realtime; // without any filtering or bounding
double oldrealtime; // last frame run
cvar_t host_framerate = {"host_framerate","0"}; // set for slow motion
cvar_t host_speeds = {"host_speeds","0"}; // set for running times
cvar_t slowmo = {"slowmo", "1.0"}; // LordHavoc: framerate independent slowmo
+cvar_t host_minfps = {"host_minfps", "10"}; // LordHavoc: game logic lower cap on framerate (if framerate is below this is, it pretends it is this, so game logic will run normally)
+cvar_t host_maxfps = {"host_maxfps", "1000"}; // LordHavoc: framerate upper cap
cvar_t sys_ticrate = {"sys_ticrate","0.05"};
cvar_t serverprofile = {"serverprofile","0"};
This shuts down both the client and server
================
*/
-char hosterrorstring[1024];
+char hosterrorstring[4096];
+extern qboolean hostloopactive;
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)
+ {
+ char string[4096];
+ va_start (argptr,error);
+ vsprintf (string,error,argptr);
+ va_end (argptr);
+ Sys_Error ("%s", string);
+ }
+
if (inerror)
{
- char string[1024];
+ char string[4096];
va_start (argptr,error);
vsprintf (string,error,argptr);
va_end (argptr);
Cvar_RegisterVariable (&host_framerate);
Cvar_RegisterVariable (&host_speeds);
Cvar_RegisterVariable (&slowmo);
+ Cvar_RegisterVariable (&host_minfps);
+ Cvar_RegisterVariable (&host_maxfps);
Cvar_RegisterVariable (&sys_ticrate);
Cvar_RegisterVariable (&serverprofile);
// this will set the body to a dead frame, among other things
saveSelf = pr_global_struct->self;
pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
- PR_ExecuteProgram (pr_global_struct->ClientDisconnect);
+ PR_ExecuteProgram (pr_global_struct->ClientDisconnect, "QC function ClientDisconnect is missing");
pr_global_struct->self = saveSelf;
}
{
realtime += time;
-// if (!cls.timedemo && realtime - oldrealtime < (1.0 / 72.0))
-// return false; // framerate is too high
+ if (slowmo.value < 0.0f)
+ Cvar_SetValue("slowmo", 0.0f);
+ if (host_minfps.value < 10.0f)
+ Cvar_SetValue("host_minfps", 10.0f);
+ if (host_maxfps.value < host_minfps.value)
+ Cvar_SetValue("host_maxfps", host_minfps.value);
+
+ if ((!cls.timedemo) && ((realtime - oldrealtime) < (1.0 / host_maxfps.value)))
+ return false; // framerate is too high
- host_frametime = (realtime - oldrealtime) * slowmo.value; // LordHavoc: slowmo cvar
+ host_realframetime = host_frametime = realtime - oldrealtime; // LordHavoc: copy into host_realframetime as well
oldrealtime = realtime;
+ if (cls.timedemo)
+ return true; // disable time effects
+
if (host_framerate.value > 0)
host_frametime = host_framerate.value;
else
- { // don't allow really long or short frames
- if (host_frametime > 0.1)
- host_frametime = 0.1;
- if (host_frametime < 0.001)
- host_frametime = 0.001;
+ {
+ // don't allow really short frames
+ if (host_frametime > (1.0 / host_minfps.value))
+ host_frametime = (1.0 / host_minfps.value);
}
+
+ host_frametime *= slowmo.value;
+ cl.frametime = host_frametime;
return true;
}
==================
*/
-double frametimetotal = 0, lastservertime = 0;
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))
return;
// run the world state
- sv_frametime = pr_global_struct->frametime = frametimetotal;
+ sv.frametime = pr_global_struct->frametime = frametimetotal;
frametimetotal = 0;
+ lastservertime = realtime;
// pr_global_struct->frametime = host_frametime;
// set the time and clear the general datagram
if (setjmp (host_abortserver) )
return; // something bad happened, or the server disconnected
+ hostloopactive = 1;
// keep the random time dependent
rand ();
// fetch results from server
if (cls.state == ca_connected)
- {
CL_ReadFromServer ();
- }
// update video
if (host_speeds.value)
if (host_speeds.value)
{
- pass1 = (time1 - time3)*1000;
+ pass1 = (time1 - time3)*1000000;
time3 = Sys_FloatTime ();
- pass2 = (time2 - time1)*1000;
- pass3 = (time3 - time2)*1000;
- Con_Printf ("%3i tot %3i server %3i gfx %3i snd\n",
+ pass2 = (time2 - time1)*1000000;
+ pass3 = (time3 - time2)*1000000;
+ Con_Printf ("%6ius total %6ius server %6ius gfx %6ius snd\n",
pass1+pass2+pass3, pass1, pass2, pass3);
}
Sys_Error("Invalid signature in vcr file\n");
Sys_FileRead (vcrFile, &com_argc, sizeof(int));
- com_argv = malloc(com_argc * sizeof(char *));
+ com_argv = qmalloc(com_argc * sizeof(char *));
com_argv[0] = host_parms.argv[0];
for (i = 0; i < com_argc; i++)
{
Sys_FileRead (vcrFile, &len, sizeof(int));
- p = malloc(len);
+ p = qmalloc(len);
Sys_FileRead (vcrFile, p, len);
com_argv[i+1] = p;
}
*/
void Host_Init ()
{
-
+ int i;
+ /*
if (standard_quake)
minimum_memory = MINIMUM_MEMORY;
else
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;
if (cls.state != ca_dedicated)
{
- R_ShutdownModules();
+ R_Modules_Shutdown();
VID_Shutdown();
}
}