]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
host: Sleep at the end of the frame. Receive packets during server frame.
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 15 Jul 2020 02:44:16 +0000 (02:44 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 15 Jul 2020 02:44:16 +0000 (02:44 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12809 d7cf8633-e32d-0410-b094-e92efae38249

host.c

diff --git a/host.c b/host.c
index 717102312c3b21b74f4e8c06cf8546a015a20524..2192a6b3c50c7a17cecf38cd0b320bd38639131c 100644 (file)
--- a/host.c
+++ b/host.c
@@ -452,11 +452,6 @@ void Host_Main(void)
 
                Log_DestBuffer_Flush();
 
-               // receive packets on each main loop iteration, as the main loop may
-               // be undersleeping due to select() detecting a new packet
-               if (sv.active && !svs.threaded)
-                       NetConn_ServerFrame();
-
                Curl_Run();
 
                // check for commands typed to the host
@@ -475,37 +470,6 @@ void Host_Main(void)
 
                //Con_Printf("%6.0f %6.0f\n", cl_timer * 1000000.0, sv_timer * 1000000.0);
 
-               // if the accumulators haven't become positive yet, wait a while
-               wait = max(cl_timer, sv_timer) * -1000000.0;
-
-               if (!host.restless && wait >= 1)
-               {
-                       double time0, delta;
-
-                       if(host_maxwait.value <= 0)
-                               wait = min(wait, 1000000.0);
-                       else
-                               wait = min(wait, host_maxwait.value * 1000.0);
-                       if(wait < 1)
-                               wait = 1; // because we cast to int
-
-                       time0 = Sys_DirtyTime();
-                       if (sv_checkforpacketsduringsleep.integer && !sys_usenoclockbutbenchmark.integer && !svs.threaded) {
-                               NetConn_SleepMicroseconds((int)wait);
-                               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
-                               Sys_Sleep((int)wait);
-                       delta = Sys_DirtyTime() - time0;
-                       if (delta < 0 || delta >= 1800) 
-                               delta = 0;
-                       host.sleeptime += delta;
-//                     R_TimeReport("sleep");
-                       continue;
-               }
-
                R_TimeReport("---");
 
        //-------------------
@@ -565,7 +529,10 @@ void Host_Main(void)
                                double advancetime, aborttime = 0;
                                float offset;
                                prvm_prog_t *prog = SVVM_prog;
-
+                               // receive packets on each main loop iteration, as the main loop may
+                               // be undersleeping due to select() detecting a new packet
+                               if (sv.active && !svs.threaded)
+                                       NetConn_ServerFrame();
                                // run the world state
                                // don't allow simulation to run too fast or too slow or logic glitches can occur
 
@@ -805,6 +772,36 @@ void Host_Main(void)
                        Mem_CheckSentinelsGlobal();
 #endif
 
+               // if the accumulators haven't become positive yet, wait a while
+               wait = max(cl_timer, sv_timer) * -1000000.0;
+
+               if (!host.restless && wait >= 1)
+               {
+                       double time0, delta;
+
+                       if(host_maxwait.value <= 0)
+                               wait = min(wait, 1000000.0);
+                       else
+                               wait = min(wait, host_maxwait.value * 1000.0);
+                       if(wait < 1)
+                               wait = 1; // because we cast to int
+
+                       time0 = Sys_DirtyTime();
+                       if (sv_checkforpacketsduringsleep.integer && !sys_usenoclockbutbenchmark.integer && !svs.threaded) {
+                               NetConn_SleepMicroseconds((int)wait);
+                               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
+                               Sys_Sleep((int)wait);
+                       delta = Sys_DirtyTime() - time0;
+                       if (delta < 0 || delta >= 1800) 
+                               delta = 0;
+                       host.sleeptime += delta;
+//                     R_TimeReport("sleep");
+               }
+
                host.framecount++;
                oldtime = newtime;
        }