Drop less performant Server::setBlockNotSent for ClientInterface::markBlockposAsNotSent
authorLoic Blot <loic.blot@unix-experience.fr>
Thu, 8 Mar 2018 21:58:43 +0000 (22:58 +0100)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Fri, 9 Mar 2018 22:27:26 +0000 (23:27 +0100)
src/clientiface.cpp
src/clientiface.h
src/server.cpp
src/server.h

index a3c44fb9e17468532e545dd5e3792b76f4925ae9..3a6caf8004ece7754b8ea09364fbc9c232e80e4e 100644 (file)
@@ -648,6 +648,15 @@ std::vector<session_t> ClientInterface::getClientIDs(ClientState min_state)
        return reply;
 }
 
+void ClientInterface::markBlockposAsNotSent(const v3s16 &pos)
+{
+       MutexAutoLock clientslock(m_clients_mutex);
+       for (const auto &client : m_clients) {
+               if (client.second->getState() >= CS_Active)
+                       client.second->SetBlockNotSent(pos);
+       }
+}
+
 /**
  * Verify if user limit was reached.
  * User limit count all clients from HelloSent state (MT protocol user) to Active state
index a7cbc01071d56aac0244e5a21488698d2db3ca37..291ccd4016f096c6d61c93355774a299ffbac756 100644 (file)
@@ -431,6 +431,9 @@ public:
        /* get list of active client id's */
        std::vector<session_t> getClientIDs(ClientState min_state=CS_Active);
 
+       /* mark block as not sent to active client sessions */
+       void markBlockposAsNotSent(const v3s16 &pos);
+
        /* verify is server user limit was reached */
        bool isUserLimitReached();
 
index 9e1db6c61f16fbf8ee1edd8ffad24bf24a717e48..36d8b49f9c4c65f48783521c8ddb29e67bd5a66e 100644 (file)
@@ -558,8 +558,7 @@ void Server::AsyncRunStep(bool initial_step)
                /*
                        Set the modified blocks unsent for all the clients
                */
-               if(!modified_blocks.empty())
-               {
+               if (!modified_blocks.empty()) {
                        SetBlocksNotSent(modified_blocks);
                }
        }
@@ -857,13 +856,13 @@ void Server::AsyncRunStep(bool initial_step)
                        case MEET_BLOCK_NODE_METADATA_CHANGED:
                                infostream << "Server: MEET_BLOCK_NODE_METADATA_CHANGED" << std::endl;
                                                prof.add("MEET_BLOCK_NODE_METADATA_CHANGED", 1);
-                                               setBlockNotSent(event->p);
+                                               m_clients.markBlockposAsNotSent(event->p);
                                break;
                        case MEET_OTHER:
                                infostream << "Server: MEET_OTHER" << std::endl;
                                prof.add("MEET_OTHER", 1);
                                for (const v3s16 &modified_block : event->modified_blocks) {
-                                       setBlockNotSent(modified_block);
+                                       m_clients.markBlockposAsNotSent(modified_block);
                                }
                                break;
                        default:
@@ -1262,7 +1261,7 @@ void Server::setInventoryModified(const InventoryLocation &loc, bool playerSend)
                if (block)
                        block->raiseModified(MOD_STATE_WRITE_NEEDED);
 
-               setBlockNotSent(blockpos);
+               m_clients.markBlockposAsNotSent(blockpos);
        }
                break;
        case InventoryLocation::DETACHED:
@@ -2147,22 +2146,9 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
        }
 }
 
-void Server::setBlockNotSent(v3s16 p)
-{
-       std::vector<session_t> clients = m_clients.getClientIDs();
-       m_clients.lock();
-       for (const session_t i : clients) {
-               RemoteClient *client = m_clients.lockedGetClientNoEx(i);
-               client->SetBlockNotSent(p);
-       }
-       m_clients.unlock();
-}
-
 void Server::SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver,
                u16 net_proto_version)
 {
-       v3s16 p = block->getPos();
-
        /*
                Create a packet with the block in the right format
        */
@@ -2174,7 +2160,7 @@ void Server::SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver,
 
        NetworkPacket pkt(TOCLIENT_BLOCKDATA, 2 + 2 + 2 + 2 + s.size(), peer_id);
 
-       pkt << p;
+       pkt << block->getPos();
        pkt.putRawString(s.c_str(), s.size());
        Send(&pkt);
 }
index 8d5cd6da4c1112598177974e59fb5d9d0cbffd3e..bf11f1cca3e8c02bccb47d4b9804620fec6d21d4 100644 (file)
@@ -401,7 +401,6 @@ private:
        void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
                        std::vector<u16> *far_players=NULL, float far_d_nodes=100,
                        bool remove_metadata=true);
-       void setBlockNotSent(v3s16 p);
 
        // Environment and Connection must be locked when called
        void SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver, u16 net_proto_version);