Make MapEditEvent more complete

SetBlocksNotSent is no longer used.
This commit is contained in:
Jude Melton-Houghton 2022-10-08 10:25:22 -04:00
parent 62ee02b8ba
commit 7701e70dc9
7 changed files with 26 additions and 31 deletions

@ -722,8 +722,15 @@ void *EmergeThread::run()
if (block) if (block)
modified_blocks[pos] = block; modified_blocks[pos] = block;
if (!modified_blocks.empty()) if (!modified_blocks.empty()) {
m_server->SetBlocksNotSent(modified_blocks); MapEditEvent event;
event.type = MEET_OTHER;
for (const auto &pair : modified_blocks) {
event.modified_blocks.insert(pair.first);
}
MutexAutoLock envlock(m_server->m_env_mutex);
m_map->dispatchEvent(event);
}
modified_blocks.clear(); modified_blocks.clear();
} }
} catch (VersionMismatchException &e) { } catch (VersionMismatchException &e) {

@ -79,21 +79,21 @@ struct MapEditEvent
MapEditEvent() = default; MapEditEvent() = default;
// Sets the event's position and marks the block as modified.
void setPositionModified(v3s16 pos)
{
p = pos;
modified_blocks.insert(getNodeBlockPos(pos));
}
VoxelArea getArea() const VoxelArea getArea() const
{ {
switch(type){ switch(type){
case MEET_ADDNODE: case MEET_ADDNODE:
return VoxelArea(p);
case MEET_REMOVENODE: case MEET_REMOVENODE:
return VoxelArea(p);
case MEET_SWAPNODE: case MEET_SWAPNODE:
return VoxelArea(p);
case MEET_BLOCK_NODE_METADATA_CHANGED: case MEET_BLOCK_NODE_METADATA_CHANGED:
{ return VoxelArea(p);
v3s16 np1 = p*MAP_BLOCKSIZE;
v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1);
return VoxelArea(np1, np2);
}
case MEET_OTHER: case MEET_OTHER:
{ {
VoxelArea a; VoxelArea a;

@ -175,7 +175,7 @@ bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gam
// Inform other things that the meta data has changed // Inform other things that the meta data has changed
MapEditEvent event; MapEditEvent event;
event.type = MEET_BLOCK_NODE_METADATA_CHANGED; event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
event.p = p; event.setPositionModified(p);
map->dispatchEvent(event); map->dispatchEvent(event);
} catch (InvalidPositionException &e) { } catch (InvalidPositionException &e) {
infostream << "RollbackAction::applyRevert(): " infostream << "RollbackAction::applyRevert(): "

@ -66,7 +66,7 @@ void NodeMetaRef::reportMetadataChange(const std::string *name)
MapEditEvent event; MapEditEvent event;
event.type = MEET_BLOCK_NODE_METADATA_CHANGED; event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
event.p = m_p; event.setPositionModified(m_p);
event.is_private_change = name && meta && meta->isPrivate(*name); event.is_private_change = name && meta && meta->isPrivate(*name);
m_env->getMap().dispatchEvent(event); m_env->getMap().dispatchEvent(event);
} }

@ -696,11 +696,13 @@ void Server::AsyncRunStep(bool initial_step)
std::map<v3s16, MapBlock*> modified_blocks; std::map<v3s16, MapBlock*> modified_blocks;
m_env->getServerMap().transformLiquids(modified_blocks, m_env); m_env->getServerMap().transformLiquids(modified_blocks, m_env);
/*
Set the modified blocks unsent for all the clients
*/
if (!modified_blocks.empty()) { if (!modified_blocks.empty()) {
SetBlocksNotSent(modified_blocks); MapEditEvent event;
event.type = MEET_OTHER;
for (const auto &pair : modified_blocks) {
event.modified_blocks.insert(pair.first);
}
m_env->getMap().dispatchEvent(event);
} }
} }
m_clients.step(dtime); m_clients.step(dtime);
@ -1253,17 +1255,6 @@ void Server::onMapEditEvent(const MapEditEvent &event)
m_unsent_map_edit_queue.push(new MapEditEvent(event)); m_unsent_map_edit_queue.push(new MapEditEvent(event));
} }
void Server::SetBlocksNotSent(std::map<v3s16, MapBlock *>& block)
{
std::vector<session_t> clients = m_clients.getClientIDs();
ClientInterface::AutoLock clientlock(m_clients);
// Set the modified blocks unsent for all the clients
for (const session_t client_id : clients) {
if (RemoteClient *client = m_clients.lockedGetClientNoEx(client_id))
client->SetBlocksNotSent(block);
}
}
void Server::peerAdded(con::Peer *peer) void Server::peerAdded(con::Peer *peer)
{ {
verbosestream<<"Server::peerAdded(): peer->id=" verbosestream<<"Server::peerAdded(): peer->id="

@ -439,9 +439,6 @@ private:
void SendNodeDef(session_t peer_id, const NodeDefManager *nodedef, void SendNodeDef(session_t peer_id, const NodeDefManager *nodedef,
u16 protocol_version); u16 protocol_version);
/* mark blocks not sent for all clients */
void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block);
virtual void SendChatMessage(session_t peer_id, const ChatMessage &message); virtual void SendChatMessage(session_t peer_id, const ChatMessage &message);
void SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed); void SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed);

@ -95,7 +95,7 @@ void ServerInventoryManager::setInventoryModified(const InventoryLocation &loc)
case InventoryLocation::NODEMETA: { case InventoryLocation::NODEMETA: {
MapEditEvent event; MapEditEvent event;
event.type = MEET_BLOCK_NODE_METADATA_CHANGED; event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
event.p = loc.p; event.setPositionModified(loc.p);
m_env->getMap().dispatchEvent(event); m_env->getMap().dispatchEvent(event);
} break; } break;
case InventoryLocation::DETACHED: { case InventoryLocation::DETACHED: {