Skip to content

Commit 6036f86

Browse files
committed
Drop less performant Server::setBlockNotSent for ClientInterface::markBlockposAsNotSent
1 parent b592c52 commit 6036f86

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

src/clientiface.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,15 @@ std::vector<session_t> ClientInterface::getClientIDs(ClientState min_state)
648648
return reply;
649649
}
650650

651+
void ClientInterface::markBlockposAsNotSent(const v3s16 &pos)
652+
{
653+
MutexAutoLock clientslock(m_clients_mutex);
654+
for (const auto &client : m_clients) {
655+
if (client.second->getState() >= CS_Active)
656+
client.second->SetBlockNotSent(pos);
657+
}
658+
}
659+
651660
/**
652661
* Verify if user limit was reached.
653662
* User limit count all clients from HelloSent state (MT protocol user) to Active state

src/clientiface.h

+3
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ class ClientInterface {
431431
/* get list of active client id's */
432432
std::vector<session_t> getClientIDs(ClientState min_state=CS_Active);
433433

434+
/* mark block as not sent to active client sessions */
435+
void markBlockposAsNotSent(const v3s16 &pos);
436+
434437
/* verify is server user limit was reached */
435438
bool isUserLimitReached();
436439

src/server.cpp

+5-19
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,7 @@ void Server::AsyncRunStep(bool initial_step)
558558
/*
559559
Set the modified blocks unsent for all the clients
560560
*/
561-
if(!modified_blocks.empty())
562-
{
561+
if (!modified_blocks.empty()) {
563562
SetBlocksNotSent(modified_blocks);
564563
}
565564
}
@@ -857,13 +856,13 @@ void Server::AsyncRunStep(bool initial_step)
857856
case MEET_BLOCK_NODE_METADATA_CHANGED:
858857
infostream << "Server: MEET_BLOCK_NODE_METADATA_CHANGED" << std::endl;
859858
prof.add("MEET_BLOCK_NODE_METADATA_CHANGED", 1);
860-
setBlockNotSent(event->p);
859+
m_clients.markBlockposAsNotSent(event->p);
861860
break;
862861
case MEET_OTHER:
863862
infostream << "Server: MEET_OTHER" << std::endl;
864863
prof.add("MEET_OTHER", 1);
865864
for (const v3s16 &modified_block : event->modified_blocks) {
866-
setBlockNotSent(modified_block);
865+
m_clients.markBlockposAsNotSent(modified_block);
867866
}
868867
break;
869868
default:
@@ -1262,7 +1261,7 @@ void Server::setInventoryModified(const InventoryLocation &loc, bool playerSend)
12621261
if (block)
12631262
block->raiseModified(MOD_STATE_WRITE_NEEDED);
12641263

1265-
setBlockNotSent(blockpos);
1264+
m_clients.markBlockposAsNotSent(blockpos);
12661265
}
12671266
break;
12681267
case InventoryLocation::DETACHED:
@@ -2147,22 +2146,9 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
21472146
}
21482147
}
21492148

2150-
void Server::setBlockNotSent(v3s16 p)
2151-
{
2152-
std::vector<session_t> clients = m_clients.getClientIDs();
2153-
m_clients.lock();
2154-
for (const session_t i : clients) {
2155-
RemoteClient *client = m_clients.lockedGetClientNoEx(i);
2156-
client->SetBlockNotSent(p);
2157-
}
2158-
m_clients.unlock();
2159-
}
2160-
21612149
void Server::SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver,
21622150
u16 net_proto_version)
21632151
{
2164-
v3s16 p = block->getPos();
2165-
21662152
/*
21672153
Create a packet with the block in the right format
21682154
*/
@@ -2174,7 +2160,7 @@ void Server::SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver,
21742160

21752161
NetworkPacket pkt(TOCLIENT_BLOCKDATA, 2 + 2 + 2 + 2 + s.size(), peer_id);
21762162

2177-
pkt << p;
2163+
pkt << block->getPos();
21782164
pkt.putRawString(s.c_str(), s.size());
21792165
Send(&pkt);
21802166
}

src/server.h

-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ class Server : public con::PeerHandler, public MapEventReceiver,
401401
void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
402402
std::vector<u16> *far_players=NULL, float far_d_nodes=100,
403403
bool remove_metadata=true);
404-
void setBlockNotSent(v3s16 p);
405404

406405
// Environment and Connection must be locked when called
407406
void SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver, u16 net_proto_version);

0 commit comments

Comments
 (0)