]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
host: Simplify wait timer calculation, removing client/server code from common code
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 16 Oct 2020 22:46:04 +0000 (22:46 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 16 Oct 2020 22:46:04 +0000 (22:46 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13019 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
host.c
sv_main.c

index 2a2b9976d204dd82cc6e41bf67c9c3e1b1e6cf50..2f99a303b1507690e8cf4dfcf4899647142072da 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -2754,6 +2754,9 @@ double CL_Frame (double time)
        static double wait;
        int pass1, pass2, pass3;
 
+       if(!host_isclient.integer)
+               return 0;
+
        CL_VM_PreventInformationLeaks();
 
        // get new key events
diff --git a/host.c b/host.c
index 8cf8593d5836b0e6b9242dfe26417097cb0a3c0b..92537f39369e82e843a1542a24f1b6a5523ad916 100644 (file)
--- a/host.c
+++ b/host.c
@@ -363,12 +363,10 @@ double Host_Frame(double time)
        Mem_CheckSentinelsGlobal();
 
        // if the accumulators haven't become positive yet, wait a while
-       if (cls.state == ca_dedicated)
-               wait = sv_timer * -1000000.0; // dedicated
-       else if (!sv.active || svs.threaded)
-               wait = cl_timer * -1000000.0; // connected to server, main menu, or server is on different thread
+       if(!sv_timer || !cl_timer)
+               wait = min(cl_timer, sv_timer) * -1000000.0;
        else
-               wait = max(cl_timer, sv_timer) * -1000000.0; // listen server or singleplayer
+               wait = max(cl_timer, sv_timer) * -1000000.0;
 
        if (!host.restless && wait >= 1)
                return wait;
@@ -389,7 +387,8 @@ static inline void Host_Sleep(double time)
                time = 1; // because we cast to int
 
        time0 = Sys_DirtyTime();
-       if (sv_checkforpacketsduringsleep.integer && !sys_usenoclockbutbenchmark.integer && !svs.threaded) {
+       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
index 6fbd146d1191d3501dbb7d87fbbefc92b6aec496..05134680cb1e4473a666aa3b4a45dd3fcd4fb1bc 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -2480,6 +2480,9 @@ double SV_Frame(double time)
        char vabuf[1024];
        qbool playing = false;
 
+       if(!sv.active)
+               return 0;
+
        if (!svs.threaded)
        {
                svs.perf_acc_sleeptime = host.sleeptime;
@@ -2522,11 +2525,8 @@ double SV_Frame(double time)
                 * Receive packets on each main loop iteration, as the main loop may
                 * be undersleeping due to select() detecting a new packet
                 */
-               if (sv.active)
-               {
-                       NetConn_ServerFrame();
-                       SV_CheckTimeouts();
-               }
+               NetConn_ServerFrame();
+               SV_CheckTimeouts();
        }
 
        /*
@@ -2545,7 +2545,7 @@ double SV_Frame(double time)
                sv_timer = 0.1;
        }
 
-       if (sv.active && sv_timer > 0 && !svs.threaded)
+       if (sv_timer > 0 && !svs.threaded)
        {
                /*
                 * Execute one or more server frames, with an upper limit on how much