Skip to content

Commit

Permalink
Reduce some instances of useless data shuffling
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Jan 23, 2024
1 parent 362e450 commit 731b84d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
9 changes: 4 additions & 5 deletions src/clientiface.cpp
Expand Up @@ -480,12 +480,11 @@ void RemoteClient::SetBlockNotSent(v3s16 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;

for (auto &block : blocks) {
v3s16 p = block.first;
for (v3s16 p : blocks) {
// remove the block from sending and sent sets,
// and mark as modified if found
if (m_blocks_sending.erase(p) + m_blocks_sent.erase(p) > 0)
Expand Down Expand Up @@ -707,12 +706,12 @@ std::vector<session_t> ClientInterface::getClientIDs(ClientState min_state)
return reply;
}

void ClientInterface::markBlockposAsNotSent(const v3s16 &pos)
void ClientInterface::markBlocksNotSent(const std::vector<v3s16> &positions)
{
RecursiveMutexAutoLock clientslock(m_clients_mutex);
for (const auto &client : m_clients) {
if (client.second->getState() >= CS_Active)
client.second->SetBlockNotSent(pos);
client.second->SetBlocksNotSent(positions);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/clientiface.h
Expand Up @@ -267,7 +267,7 @@ class RemoteClient
void SentBlock(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.
Expand Down Expand Up @@ -473,8 +473,8 @@ class ClientInterface {
/* 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);
/* mark blocks as not sent on all active clients */
void markBlocksNotSent(const std::vector<v3s16> &positions);

/* verify is server user limit was reached */
bool isUserLimitReached();
Expand Down
20 changes: 4 additions & 16 deletions src/server.cpp
Expand Up @@ -950,9 +950,7 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
}
case MEET_OTHER:
prof.add("MEET_OTHER", 1);
for (const v3s16 &modified_block : event->modified_blocks) {
m_clients.markBlockposAsNotSent(modified_block);
}
m_clients.markBlocksNotSent(event->modified_blocks);
break;
default:
prof.add("unknown", 1);
Expand All @@ -964,19 +962,9 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
/*
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) {
if (RemoteClient *client = getClient(far_player))
client->SetBlocksNotSent(modified_blocks2);
}
for (const u16 far_player : far_players) {
if (RemoteClient *client = getClient(far_player))
client->SetBlocksNotSent(event->modified_blocks);
}

delete event;
Expand Down

0 comments on commit 731b84d

Please sign in to comment.