]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
-Added 2 builtins to make the hostcache stuff easier extensible.
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index 953f394360a2d1ee313eed13eadbba3acf175456..a1a9d129ac587f20359b4bd23692fe9adeb16cf2 100644 (file)
--- a/host.c
+++ b/host.c
@@ -112,7 +112,7 @@ void Host_Error (const char *error, ...)
        va_list argptr;
 
        va_start (argptr,error);
-       vsprintf (hosterrorstring1,error,argptr);
+       vsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr);
        va_end (argptr);
 
        Con_Printf("Host_Error: %s\n", hosterrorstring1);
@@ -351,7 +351,7 @@ void SV_BroadcastPrint(const char *msg)
        }
 
        if (sv_echobprint.integer && cls.state == ca_dedicated)
-               Sys_Print(msg);
+               Con_Print(msg);
 }
 
 /*
@@ -386,7 +386,7 @@ void Host_ClientCommands(const char *fmt, ...)
        char string[1024];
 
        va_start(argptr,fmt);
-       vsprintf(string, fmt,argptr);
+       vsnprintf(string, sizeof(string), fmt, argptr);
        va_end(argptr);
 
        MSG_WriteByte(&host_client->message, svc_stufftext);
@@ -563,7 +563,7 @@ qboolean Host_FilterTime (double time)
        double timecap, timeleft;
        realtime += time;
 
-       if (sys_ticrate.value < 0.01 || sys_ticrate.value > 0.1)
+       if (sys_ticrate.value < 0.01 || 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);
@@ -667,34 +667,40 @@ Host_ServerFrame
 */
 void Host_ServerFrame (void)
 {
-       // never run more than 20 frames at a time as a sanity limit
-       int framecount, framelimit = 20;
-       double advancetime;
-       static double frametimetotal = 0, lastservertime = 0;
-       frametimetotal += host_frametime;
-       // LordHavoc: cap server at sys_ticrate in networked games
-       if (frametimetotal < 0.001 || (!cl.islocalgame && cls.state == ca_connected && sv.active && ((realtime - lastservertime) < sys_ticrate.value)))
+       // never run more than 5 frames at a time as a sanity limit
+       int framecount, framelimit = 5;
+       double advancetime, newtime;
+       if (!sv.active)
+               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;
-       lastservertime = realtime;
-
-       // set the time and clear the general datagram
-       SV_ClearDatagram();
-
        // 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 && frametimetotal > 0;framecount++, frametimetotal -= advancetime)
+       for (framecount = 0;framecount < framelimit && sv.timer < newtime;framecount++)
        {
-               advancetime = min(frametimetotal, sys_ticrate.value);
+               if (cl.islocalgame)
+                       advancetime = min(newtime - sv.timer, sys_ticrate.value);
+               else
+                       advancetime = sys_ticrate.value;
+               sv.timer += advancetime;
 
                // only advance time if not paused
                // the game also pauses in singleplayer when menu or console is used
-               if (!sv.paused && (!cl.islocalgame || (key_dest == key_game && !key_consoleactive)))
-                       sv.frametime = advancetime;
-               else
+               sv.frametime = advancetime * slowmo.value;
+               if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive)))
                        sv.frametime = 0;
 
                pr_global_struct->frametime = sv.frametime;
 
+               // set the time and clear the general datagram
+               SV_ClearDatagram();
+
                // check for network packets to the server each world step incase they
                // come in midframe (particularly if host is running really slow)
                NetConn_ServerFrame();
@@ -705,13 +711,16 @@ void Host_ServerFrame (void)
                // move things around and think unless paused
                if (sv.frametime)
                        SV_Physics();
-       }
 
-       // send all messages to the clients
-       SV_SendClientMessages();
+               // send all messages to the clients
+               SV_SendClientMessages();
 
-       // send an heartbeat if enough time has passed since the last one
-       NetConn_Heartbeat(0);
+               // send an heartbeat if enough time has passed since the last one
+               NetConn_Heartbeat(0);
+       }
+       // if we fell behind too many frames just don't worry about it
+       if (sv.timer < newtime)
+               sv.timer = newtime;
 }
 
 
@@ -728,7 +737,6 @@ void _Host_Frame (float time)
        static double time2 = 0;
        static double time3 = 0;
        int pass1, pass2, pass3;
-       usercmd_t cmd; // Used for receiving input
 
        if (setjmp(host_abortserver))
                return;                 // something bad happened, or the server disconnected
@@ -749,14 +757,14 @@ void _Host_Frame (float time)
        IN_Commands();
 
        // Collect input into cmd
-       IN_ProcessMove(&cmd);
+       IN_ProcessMove();
 
        // process console commands
        Cbuf_Execute();
 
        // if running the server locally, make intentions now
        if (cls.state == ca_connected && sv.active)
-               CL_SendCmd(&cmd);
+               CL_SendCmd();
 
 //-------------------
 //
@@ -786,7 +794,7 @@ void _Host_Frame (float time)
                // if running the server remotely, send intentions now after
                // the incoming messages have been read
                if (!sv.active)
-                       CL_SendCmd(&cmd);
+                       CL_SendCmd();
                CL_ReadFromServer();
        }
 
@@ -934,6 +942,7 @@ void Host_Init (void)
        if (cls.state != ca_dedicated)
        {
                VID_Open();
+               CL_InitTEnts ();  // We must wait after sound startup to load tent sounds
                SCR_BeginLoadingPlaque();
                MR_Init();
        }
@@ -1000,6 +1009,7 @@ void Host_Shutdown(void)
        // AK shutdown PRVM
        // AK hmm, no PRVM_Shutdown(); yet
 
+       CL_Video_Shutdown();
 
        Host_SaveConfig_f();
 
@@ -1012,6 +1022,7 @@ void Host_Shutdown(void)
                VID_Shutdown();
        }
 
+       Cmd_Shutdown();
        Sys_Shutdown();
        Log_Close ();
 }