Optimize usage of TOSERVER_GOTBLOCKS packet
authorsfan5 <sfan5@live.de>
Wed, 7 Aug 2019 08:31:12 +0000 (10:31 +0200)
committersfan5 <sfan5@live.de>
Wed, 7 Aug 2019 09:32:16 +0000 (11:32 +0200)
src/client/client.cpp
src/client/client.h

index 78e077fc3954b15a4708c3bc092f3834c37e4fb3..4dc05dc09c064bec4853e278afca6ef342975086 100644 (file)
@@ -475,6 +475,7 @@ void Client::step(float dtime)
        */
        {
                int num_processed_meshes = 0;
+               std::vector<v3s16> blocks_to_ack;
                while (!m_mesh_update_thread.m_queue_out.empty())
                {
                        num_processed_meshes++;
@@ -513,14 +514,18 @@ void Client::step(float dtime)
                                m_minimap->addBlock(r.p, minimap_mapblock);
 
                        if (r.ack_block_to_server) {
-                               /*
-                                       Acknowledge block
-                                       [0] u8 count
-                                       [1] v3s16 pos_0
-                               */
-                               sendGotBlocks(r.p);
+                               if (blocks_to_ack.size() == 255) {
+                                       sendGotBlocks(blocks_to_ack);
+                                       blocks_to_ack.clear();
+                               }
+
+                               blocks_to_ack.emplace_back(r.p);
                        }
                }
+               if (blocks_to_ack.size() > 0) {
+                               // Acknowledge block(s)
+                               sendGotBlocks(blocks_to_ack);
+               }
 
                if (num_processed_meshes > 0)
                        g_profiler->graphAdd("num_processed_meshes", num_processed_meshes);
@@ -1069,10 +1074,13 @@ void Client::sendDeletedBlocks(std::vector<v3s16> &blocks)
        Send(&pkt);
 }
 
-void Client::sendGotBlocks(v3s16 block)
+void Client::sendGotBlocks(const std::vector<v3s16> &blocks)
 {
-       NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6);
-       pkt << (u8) 1 << block;
+       NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6 * blocks.size());
+       pkt << (u8) blocks.size();
+       for (const v3s16 &block : blocks)
+               pkt << block;
+
        Send(&pkt);
 }
 
index 312b8c87fac066983463c6c30ea41cfcf3848ad7..527ae652415551045e74c9b1a334ed985d6b6aa1 100644 (file)
@@ -465,7 +465,7 @@ private:
        void promptConfirmRegistration(AuthMechanism chosen_auth_mechanism);
        void startAuth(AuthMechanism chosen_auth_mechanism);
        void sendDeletedBlocks(std::vector<v3s16> &blocks);
-       void sendGotBlocks(v3s16 block);
+       void sendGotBlocks(const std::vector<v3s16> &blocks);
        void sendRemovedSounds(std::vector<s32> &soundList);
 
        // Helper function