From 6036f865cba44fd26374a3a649370f51d5d4ff6c Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 8 Mar 2018 22:58:43 +0100 Subject: [PATCH] Drop less performant Server::setBlockNotSent for ClientInterface::markBlockposAsNotSent --- src/clientiface.cpp | 9 +++++++++ src/clientiface.h | 3 +++ src/server.cpp | 24 +++++------------------- src/server.h | 1 - 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/clientiface.cpp b/src/clientiface.cpp index a3c44fb9e..3a6caf800 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -648,6 +648,15 @@ std::vector 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 diff --git a/src/clientiface.h b/src/clientiface.h index a7cbc0107..291ccd401 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -431,6 +431,9 @@ public: /* get list of active client id's */ std::vector 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(); diff --git a/src/server.cpp b/src/server.cpp index 9e1db6c61..36d8b49f9 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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 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); } diff --git a/src/server.h b/src/server.h index 8d5cd6da4..bf11f1cca 100644 --- a/src/server.h +++ b/src/server.h @@ -401,7 +401,6 @@ private: void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0, std::vector *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);