]> git.lizzy.rs Git - minetest.git/commitdiff
Restart map-send cycle if visible blocks are soon to be unloaded. (#13277)
authorlhofhansl <larsh@apache.org>
Thu, 30 Mar 2023 16:19:13 +0000 (09:19 -0700)
committerGitHub <noreply@github.com>
Thu, 30 Mar 2023 16:19:13 +0000 (09:19 -0700)
* Restart map-send cycle if visible blocks are soon to be unloaded.
* Reset completion timer when camera or position changed.

Co-authored-by: sfan5 <sfan5@live.de>
src/clientiface.cpp

index 49b668cf039b22002133eca3bc21bd199b8d5393..ee54e986c308e372874bc9edf16ff78e77242acf 100644 (file)
@@ -101,6 +101,16 @@ void RemoteClient::GetNextBlocks (
        m_nothing_to_send_pause_timer -= dtime;
        m_map_send_completion_timer += dtime;
 
+       if (m_map_send_completion_timer > g_settings->getFloat("server_unload_unused_data_timeout") * 0.8f) {
+               infostream << "Server: Player " << m_name << ", peer_id=" << peer_id
+                               << ": full map send is taking too long ("
+                               << m_map_send_completion_timer
+                               << "s), restarting to avoid visible blocks being unloaded."
+                               << std::endl;
+               m_map_send_completion_timer = 0.0f;
+               m_nearest_unsent_d = 0;
+       }
+
        if (m_nothing_to_send_pause_timer >= 0)
                return;
 
@@ -176,12 +186,14 @@ void RemoteClient::GetNextBlocks (
        if (m_last_center != center) {
                m_nearest_unsent_d = 0;
                m_last_center = center;
+               m_map_send_completion_timer = 0.0f;
        }
        // reset the unsent distance if the view angle has changed more that 10% of the fov
        // (this matches isBlockInSight which allows for an extra 10%)
        if (camera_dir.dotProduct(m_last_camera_dir) < std::cos(camera_fov * 0.1f)) {
                m_nearest_unsent_d = 0;
                m_last_camera_dir = camera_dir;
+               m_map_send_completion_timer = 0.0f;
        }
        if (m_nearest_unsent_d > 0) {
                // make sure any blocks modified since the last time we sent blocks are resent
@@ -259,16 +271,6 @@ void RemoteClient::GetNextBlocks (
                        if (d <= BLOCK_SEND_DISABLE_LIMITS_MAX_D)
                                max_simul_dynamic = m_max_simul_sends;
 
-                       // Don't select too many blocks for sending
-                       if (num_blocks_selected >= max_simul_dynamic) {
-                               //queue_is_full = true;
-                               goto queue_full_break;
-                       }
-
-                       // Don't send blocks that are currently being transferred
-                       if (m_blocks_sending.find(p) != m_blocks_sending.end())
-                               continue;
-
                        /*
                                Do not go over max mapgen limit
                        */
@@ -304,6 +306,16 @@ void RemoteClient::GetNextBlocks (
                                block->resetUsageTimer();
                        }
 
+                       // Don't select too many blocks for sending
+                       if (num_blocks_selected >= max_simul_dynamic) {
+                               //queue_is_full = true;
+                               goto queue_full_break;
+                       }
+
+                       // Don't send blocks that are currently being transferred
+                       if (m_blocks_sending.find(p) != m_blocks_sending.end())
+                               continue;
+
                        /*
                                Don't send already sent blocks
                        */