]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/main.qc
Merge branch 'bones_was_here/sv_playerthink_optimise' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / main.qc
index bee15d6cc867c685687ef5edf487914d4e4bc026..40e14c906bf858e544c321cf475cada1526a9024 100644 (file)
@@ -5,6 +5,7 @@
 #include <common/deathtypes/all.qh>
 #include <common/debug.qh>
 #include <common/mapinfo.qh>
+#include <common/mapobjects/_mod.qh>
 #include <common/monsters/sv_monsters.qh>
 #include <common/util.qh>
 #include <common/vehicles/all.qh>
@@ -187,12 +188,14 @@ void CreatureFrame_All()
        });
 }
 
+// called shortly after map change in dedicated
 void Pause_TryPause_Dedicated(entity this)
 {
-       if (player_count == 0)
+       if (player_count == 0 && !intermission_running && !autocvar__endmatch)
                setpause(1);
 }
 
+// called every normal frame in singleplayer/listen
 void Pause_TryPause()
 {
        int n = 0, p = 0;
@@ -207,9 +210,12 @@ void Pause_TryPause()
                setpause(0);
 }
 
+// called every paused frame by DP
 void SV_PausedTic(float elapsedtime)
 {
-       if (!server_is_dedicated)
+       if (autocvar__endmatch) // `endmatch` while paused
+               setpause(0); // proceed to intermission
+       else if (!server_is_dedicated)
        {
                if (autocvar_sv_autopause)
                        Pause_TryPause();
@@ -288,12 +294,14 @@ void systems_update();
 void sys_phys_update(entity this, float dt);
 void StartFrame()
 {
-       // TODO: if move is more than 50ms, split it into two moves (this matches QWSV behavior and the client prediction)
-       IL_EACH(g_players, IS_FAKE_CLIENT(it), sys_phys_update(it, frametime));
-       IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPreThink(it));
+       FOREACH_CLIENT(IS_FAKE_CLIENT(it),
+       {
+               // DP calls these for real clients only
+               sys_phys_update(it, frametime); // called by SV_PlayerPhysics for players
+               PlayerPreThink(it);
+       });
 
        execute_next_frame();
-       if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause();
 
        delete_fn = remove_unsafely; // not during spawning!
        serverprevtime = servertime;
@@ -346,6 +354,10 @@ void StartFrame()
        CreatureFrame_All();
        CheckRules_World();
 
+       // after CheckRules_World() as it may set intermission_running, and after RedirectionThink() in case listen server is closing
+       if (autocvar_sv_autopause && !server_is_dedicated && !intermission_running)
+               Pause_TryPause();
+
        if (warmup_stage && !game_stopped && warmup_limit > 0 && time - game_starttime >= warmup_limit) {
                ReadyRestart(true);
                return;
@@ -356,8 +368,13 @@ void StartFrame()
        MUTATOR_CALLHOOK(SV_StartFrame);
 
        GlobalStats_updateglobal();
-       FOREACH_CLIENT(true, GlobalStats_update(it));
-       IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPostThink(it));
+       FOREACH_CLIENT(true,
+       {
+               GlobalStats_update(it);
+               if (IS_FAKE_CLIENT(it))
+                       PlayerPostThink(it); // DP calls this for real clients only
+               PlayerFrame(it);
+       });
 }
 
 .vector originjitter;