Skip to content

Commit d742cd1

Browse files
authored
Bring back low priority block events in a safe way. (#16945)
This reverts commit 6ac8346, and brings back low priority block events. (Revert "Revert part of 16013 - restore liquid updates to the client (#16663)") Close block changes are never considered "low priority"
1 parent 47e5f42 commit d742cd1

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

src/map.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ struct MapEditEvent
4646
MapNode n = CONTENT_AIR;
4747
std::vector<v3s16> modified_blocks; // Represents a set
4848
bool is_private_change = false;
49+
// Setting low_priority to true allows the server
50+
// to send this change to clients with some delay.
51+
bool low_priority = false;
4952

5053
MapEditEvent() = default;
5154

src/server.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
784784
if (!modified_blocks.empty()) {
785785
MapEditEvent event;
786786
event.type = MEET_OTHER;
787+
event.low_priority = true;
787788
event.setModifiedBlocks(modified_blocks);
788789
m_env->getMap().dispatchEvent(event);
789790
}
@@ -1041,7 +1042,7 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
10411042
}
10421043
case MEET_OTHER:
10431044
prof.add("MEET_OTHER", 1);
1044-
m_clients.markBlocksNotSent(event->modified_blocks);
1045+
m_clients.markBlocksNotSent(event->modified_blocks, event->low_priority);
10451046
break;
10461047
default:
10471048
prof.add("unknown", 1);
@@ -1057,7 +1058,7 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
10571058
*/
10581059
for (const u16 far_player : far_players) {
10591060
if (RemoteClient *client = getClient(far_player))
1060-
client->SetBlocksNotSent(event->modified_blocks);
1061+
client->SetBlocksNotSent(event->modified_blocks, event->low_priority);
10611062
}
10621063

10631064
delete event;

src/server/clientiface.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ void RemoteClient::SentBlock(v3s16 p)
430430
" already in m_blocks_sending"<<std::endl;
431431
}
432432

433-
void RemoteClient::SetBlockNotSent(v3s16 p)
433+
void RemoteClient::SetBlockNotSent(v3s16 p, bool low_priority)
434434
{
435435
m_nothing_to_send_pause_timer = 0;
436436

@@ -446,14 +446,19 @@ void RemoteClient::SetBlockNotSent(v3s16 p)
446446
// will reset m_nearest_unsent_d to 0 anyway (see getNextBlocks).
447447
p -= m_last_center;
448448
s16 this_d = std::max({std::abs(p.X), std::abs(p.Y), std::abs(p.Z)});
449-
m_nearest_unsent_d = std::min(m_nearest_unsent_d, this_d);
449+
450+
// If this is a low priority event (and not close), do not reset m_nearest_unsent_d.
451+
// Instead, the send loop will get to the block in the next full loop iteration.
452+
if (!low_priority || this_d < m_block_cull_optimize_distance) {
453+
m_nearest_unsent_d = std::min(m_nearest_unsent_d, this_d);
454+
}
450455
}
451456
}
452457

453-
void RemoteClient::SetBlocksNotSent(const std::vector<v3s16> &blocks)
458+
void RemoteClient::SetBlocksNotSent(const std::vector<v3s16> &blocks, bool low_priority)
454459
{
455460
for (v3s16 p : blocks) {
456-
SetBlockNotSent(p);
461+
SetBlockNotSent(p, low_priority);
457462
}
458463
}
459464

@@ -677,12 +682,12 @@ std::vector<session_t> ClientInterface::getClientIDs(ClientState min_state)
677682
return reply;
678683
}
679684

680-
void ClientInterface::markBlocksNotSent(const std::vector<v3s16> &positions)
685+
void ClientInterface::markBlocksNotSent(const std::vector<v3s16> &positions, bool low_priority)
681686
{
682687
RecursiveMutexAutoLock clientslock(m_clients_mutex);
683688
for (const auto &client : m_clients) {
684689
if (client.second->getState() >= CS_Active)
685-
client.second->SetBlocksNotSent(positions);
690+
client.second->SetBlocksNotSent(positions, low_priority);
686691
}
687692
}
688693

src/server/clientiface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ class RemoteClient
250250

251251
void SentBlock(v3s16 p);
252252

253-
void SetBlockNotSent(v3s16 p);
254-
void SetBlocksNotSent(const std::vector<v3s16> &blocks);
253+
void SetBlockNotSent(v3s16 p, bool low_priority = false);
254+
void SetBlocksNotSent(const std::vector<v3s16> &blocks, bool low_priority = false);
255255

256256
/**
257257
* tell client about this block being modified right now.
@@ -442,7 +442,7 @@ class ClientInterface {
442442
std::vector<session_t> getClientIDs(ClientState min_state=CS_Active);
443443

444444
/* mark blocks as not sent on all active clients */
445-
void markBlocksNotSent(const std::vector<v3s16> &positions);
445+
void markBlocksNotSent(const std::vector<v3s16> &positions, bool low_priority = false);
446446

447447
/* verify if server user limit was reached */
448448
bool isUserLimitReached();

src/servermap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ MapBlock *ServerMap::loadBlock(const std::string &blob, v3s16 p3d, bool save_aft
778778
if (!modified_blocks.empty()) {
779779
MapEditEvent event;
780780
event.type = MEET_OTHER;
781+
event.low_priority = true;
781782
event.setModifiedBlocks(modified_blocks);
782783
dispatchEvent(event);
783784
}

0 commit comments

Comments
 (0)