]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
cmd: always register server-only commands, don't register client-only commands on...
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index d2725cc2f85c07dc3eb7693f87de22149e8fd04f..e7dd4a421b0d311a76bdd83051a632aff5b0f777 100644 (file)
--- a/host.c
+++ b/host.c
@@ -133,6 +133,9 @@ void Host_Error (const char *error, ...)
        if (cls.state == ca_dedicated)
                Sys_Error ("Host_Error: %s",hosterrorstring2);  // dedicated servers exit
 
+       // prevent an endless loop if the error was triggered by a command
+       Cbuf_Clear(cmd_local->cbuf);
+
        CL_Disconnect();
        cls.demonum = -1;
 
@@ -156,7 +159,7 @@ static void Host_Quit_f(cmd_state_t *cmd)
 
 static void Host_Version_f(cmd_state_t *cmd)
 {
-       Con_Printf("Version: %s build %s\n", gamename, buildstring);
+       Con_Printf("Version: %s\n", engineversion);
 }
 
 static void Host_Framerate_c(cvar_t *var)
@@ -365,7 +368,6 @@ Host_Init
 static void Host_Init (void)
 {
        int i;
-       const char* os;
        char vabuf[1024];
 
        host.hook.ConnectLocal = NULL;
@@ -445,8 +447,7 @@ static void Host_Init (void)
        FS_Init();
 
        // construct a version string for the corner of the console
-       os = DP_OS_NAME;
-       dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
+       dpsnprintf (engineversion, sizeof (engineversion), "%s %s%s, buildstring: %s", gamename, DP_OS_NAME, cls.state == ca_dedicated ? " dedicated" : "", buildstring);
        Con_Printf("%s\n", engineversion);
 
        // initialize process nice level
@@ -503,6 +504,7 @@ static void Host_Init (void)
        {
                // put up the loading image so the user doesn't stare at a black screen...
                SCR_BeginLoadingPlaque(true);
+               S_Startup();
 #ifdef CONFIG_MENU
                MR_Init();
 #endif
@@ -643,60 +645,26 @@ static double Host_Frame(double time)
        // Run any downloads
        Curl_Frame();
 
+       // get new SDL events and add commands from keybindings to the cbuf
+       Sys_SDL_HandleEvents();
+
        // process console commands
        Cbuf_Frame(host.cbuf);
 
        R_TimeReport("---");
 
-       sv_wait = SV_Frame(time);
-       cl_wait = CL_Frame(time);
-
-//     Con_Printf("%6.0f %6.0f\n", cl_wait * 1000000.0, sv_wait * 1000000.0);
+       // if the accumulators haven't become positive yet, wait a while
+       sv_wait = - SV_Frame(time);
+       cl_wait = - CL_Frame(time);
 
        Mem_CheckSentinelsGlobal();
 
-       if(host.restless)
-               return 0;
-
-       // if the accumulators haven't become positive yet, wait a while
        if (cls.state == ca_dedicated)
-               return sv_wait * -1000000.0; // dedicated
+               return sv_wait; // dedicated
        else if (!sv.active || svs.threaded)
-               return cl_wait * -1000000.0; // connected to server, main menu, or server is on different thread
-       else
-               return max(cl_wait, sv_wait) * -1000000.0; // listen server or singleplayer
-}
-
-static inline void Host_Sleep(double time)
-{
-       double delta, time0;
-
-       if(host_maxwait.value <= 0)
-               time = min(time, 1000000.0);
+               return cl_wait; // connected to server, main menu, or server is on different thread
        else
-               time = min(time, host_maxwait.value * 1000.0);
-       if(time < 1)
-               time = 1; // because we cast to int
-
-       time0 = Sys_DirtyTime();
-       if (sv_checkforpacketsduringsleep.integer && !sys_usenoclockbutbenchmark.integer && !svs.threaded) {
-               NetConn_SleepMicroseconds((int)time);
-               if (cls.state != ca_dedicated)
-                       NetConn_ClientFrame(); // helps server browser get good ping values
-               // TODO can we do the same for ServerFrame? Probably not.
-       }
-       else
-       {
-               if (cls.state != ca_dedicated)
-                       Curl_Select(&time);
-               Sys_Sleep((int)time);
-       }
-       delta = Sys_DirtyTime() - time0;
-       if (delta < 0 || delta >= 1800)
-               delta = 0;
-       host.sleeptime = delta;
-//                     R_TimeReport("sleep");
-       return;
+               return min(cl_wait, sv_wait); // listen server or singleplayer
 }
 
 // Cloudwalk: Most overpowered function declaration...
@@ -722,7 +690,7 @@ static inline double Host_UpdateTime (double newtime, double oldtime)
 
 void Host_Main(void)
 {
-       double time, newtime, oldtime, sleeptime;
+       double time, oldtime, sleeptime;
 
        Host_Init(); // Start!
 
@@ -739,17 +707,14 @@ void Host_Main(void)
                        continue;
                }
 
-               newtime = host.dirtytime = Sys_DirtyTime();
-               host.realtime += time = Host_UpdateTime(newtime, oldtime);
+               host.dirtytime = Sys_DirtyTime();
+               host.realtime += time = Host_UpdateTime(host.dirtytime, oldtime);
+               oldtime = host.dirtytime;
 
                sleeptime = Host_Frame(time);
-               oldtime = newtime;
                ++host.framecount;
-
-               if (sleeptime >= 1)
-                       Host_Sleep(sleeptime);
-               else
-                       host.sleeptime = 0;
+               sleeptime -= Sys_DirtyTime() - host.dirtytime; // execution time
+               host.sleeptime = Sys_Sleep(sleeptime);
        }
 
        return;