Reduce some instances of useless data shuffling

This commit is contained in:
sfan5 2024-01-23 21:32:36 +01:00
parent 362e4505e8
commit 731b84d725
3 changed files with 11 additions and 24 deletions

@ -480,12 +480,11 @@ void RemoteClient::SetBlockNotSent(v3s16 p)
m_blocks_modified.insert(p); m_blocks_modified.insert(p);
} }
void RemoteClient::SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks) void RemoteClient::SetBlocksNotSent(const std::vector<v3s16> &blocks)
{ {
m_nothing_to_send_pause_timer = 0; m_nothing_to_send_pause_timer = 0;
for (auto &block : blocks) { for (v3s16 p : blocks) {
v3s16 p = block.first;
// remove the block from sending and sent sets, // remove the block from sending and sent sets,
// and mark as modified if found // and mark as modified if found
if (m_blocks_sending.erase(p) + m_blocks_sent.erase(p) > 0) if (m_blocks_sending.erase(p) + m_blocks_sent.erase(p) > 0)
@ -707,12 +706,12 @@ std::vector<session_t> ClientInterface::getClientIDs(ClientState min_state)
return reply; return reply;
} }
void ClientInterface::markBlockposAsNotSent(const v3s16 &pos) void ClientInterface::markBlocksNotSent(const std::vector<v3s16> &positions)
{ {
RecursiveMutexAutoLock clientslock(m_clients_mutex); RecursiveMutexAutoLock clientslock(m_clients_mutex);
for (const auto &client : m_clients) { for (const auto &client : m_clients) {
if (client.second->getState() >= CS_Active) if (client.second->getState() >= CS_Active)
client.second->SetBlockNotSent(pos); client.second->SetBlocksNotSent(positions);
} }
} }

@ -267,7 +267,7 @@ public:
void SentBlock(v3s16 p); void SentBlock(v3s16 p);
void SetBlockNotSent(v3s16 p); void SetBlockNotSent(v3s16 p);
void SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks); void SetBlocksNotSent(const std::vector<v3s16> &blocks);
/** /**
* tell client about this block being modified right now. * tell client about this block being modified right now.
@ -473,8 +473,8 @@ public:
/* get list of active client id's */ /* get list of active client id's */
std::vector<session_t> getClientIDs(ClientState min_state=CS_Active); std::vector<session_t> getClientIDs(ClientState min_state=CS_Active);
/* mark block as not sent to active client sessions */ /* mark blocks as not sent on all active clients */
void markBlockposAsNotSent(const v3s16 &pos); void markBlocksNotSent(const std::vector<v3s16> &positions);
/* verify is server user limit was reached */ /* verify is server user limit was reached */
bool isUserLimitReached(); bool isUserLimitReached();

@ -950,9 +950,7 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
} }
case MEET_OTHER: case MEET_OTHER:
prof.add("MEET_OTHER", 1); prof.add("MEET_OTHER", 1);
for (const v3s16 &modified_block : event->modified_blocks) { m_clients.markBlocksNotSent(event->modified_blocks);
m_clients.markBlockposAsNotSent(modified_block);
}
break; break;
default: default:
prof.add("unknown", 1); prof.add("unknown", 1);
@ -964,19 +962,9 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
/* /*
Set blocks not sent to far players Set blocks not sent to far players
*/ */
if (!far_players.empty()) {
// Convert list format to that wanted by SetBlocksNotSent
std::map<v3s16, MapBlock*> modified_blocks2;
for (const v3s16 &modified_block : event->modified_blocks) {
modified_blocks2[modified_block] =
m_env->getMap().getBlockNoCreateNoEx(modified_block);
}
// Set blocks not sent
for (const u16 far_player : far_players) { for (const u16 far_player : far_players) {
if (RemoteClient *client = getClient(far_player)) if (RemoteClient *client = getClient(far_player))
client->SetBlocksNotSent(modified_blocks2); client->SetBlocksNotSent(event->modified_blocks);
}
} }
delete event; delete event;