forked from Mirrorlandia_minetest/minetest
Store MapEditEvent
blocks in a vector (#13071)
This commit is contained in:
parent
5c248c2d7d
commit
d13b12b791
src
@ -725,9 +725,7 @@ void *EmergeThread::run()
|
||||
if (!modified_blocks.empty()) {
|
||||
MapEditEvent event;
|
||||
event.type = MEET_OTHER;
|
||||
for (const auto &pair : modified_blocks) {
|
||||
event.modified_blocks.insert(pair.first);
|
||||
}
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
MutexAutoLock envlock(m_server->m_env_mutex);
|
||||
m_map->dispatchEvent(event);
|
||||
}
|
||||
|
15
src/map.cpp
15
src/map.cpp
@ -262,10 +262,7 @@ bool Map::addNodeWithEvent(v3s16 p, MapNode n, bool remove_metadata)
|
||||
std::map<v3s16, MapBlock*> modified_blocks;
|
||||
addNodeAndUpdate(p, n, modified_blocks, remove_metadata);
|
||||
|
||||
// Copy modified_blocks to event
|
||||
for (auto &modified_block : modified_blocks) {
|
||||
event.modified_blocks.insert(modified_block.first);
|
||||
}
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
}
|
||||
catch(InvalidPositionException &e){
|
||||
succeeded = false;
|
||||
@ -287,10 +284,7 @@ bool Map::removeNodeWithEvent(v3s16 p)
|
||||
std::map<v3s16, MapBlock*> modified_blocks;
|
||||
removeNodeAndUpdate(p, modified_blocks);
|
||||
|
||||
// Copy modified_blocks to event
|
||||
for (auto &modified_block : modified_blocks) {
|
||||
event.modified_blocks.insert(modified_block.first);
|
||||
}
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
}
|
||||
catch(InvalidPositionException &e){
|
||||
succeeded = false;
|
||||
@ -1873,10 +1867,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
|
||||
//Modified lighting, send event
|
||||
MapEditEvent event;
|
||||
event.type = MEET_OTHER;
|
||||
std::map<v3s16, MapBlock *>::iterator it;
|
||||
for (it = modified_blocks.begin();
|
||||
it != modified_blocks.end(); ++it)
|
||||
event.modified_blocks.insert(it->first);
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
13
src/map.h
13
src/map.h
@ -74,7 +74,7 @@ struct MapEditEvent
|
||||
MapEditEventType type = MEET_OTHER;
|
||||
v3s16 p;
|
||||
MapNode n = CONTENT_AIR;
|
||||
std::set<v3s16> modified_blocks;
|
||||
std::vector<v3s16> modified_blocks; // Represents a set
|
||||
bool is_private_change = false;
|
||||
|
||||
MapEditEvent() = default;
|
||||
@ -82,8 +82,17 @@ struct MapEditEvent
|
||||
// Sets the event's position and marks the block as modified.
|
||||
void setPositionModified(v3s16 pos)
|
||||
{
|
||||
assert(modified_blocks.empty()); // only meant for initialization (once)
|
||||
p = pos;
|
||||
modified_blocks.insert(getNodeBlockPos(pos));
|
||||
modified_blocks.push_back(getNodeBlockPos(pos));
|
||||
}
|
||||
|
||||
void setModifiedBlocks(const std::map<v3s16, MapBlock *> blocks)
|
||||
{
|
||||
assert(modified_blocks.empty()); // only meant for initialization (once)
|
||||
modified_blocks.reserve(blocks.size());
|
||||
for (const auto &block : blocks)
|
||||
modified_blocks.push_back(block.first);
|
||||
}
|
||||
|
||||
VoxelArea getArea() const
|
||||
|
@ -273,8 +273,7 @@ void Schematic::placeOnMap(ServerMap *map, v3s16 p, u32 flags,
|
||||
//// Create & dispatch map modification events to observers
|
||||
MapEditEvent event;
|
||||
event.type = MEET_OTHER;
|
||||
for (it = modified_blocks.begin(); it != modified_blocks.end(); ++it)
|
||||
event.modified_blocks.insert(it->first);
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
|
||||
map->dispatchEvent(event);
|
||||
}
|
||||
|
@ -137,8 +137,7 @@ treegen::error spawn_ltree(ServerMap *map, v3s16 p0,
|
||||
// Send a MEET_OTHER event
|
||||
MapEditEvent event;
|
||||
event.type = MEET_OTHER;
|
||||
for (auto &modified_block : modified_blocks)
|
||||
event.modified_blocks.insert(modified_block.first);
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
map->dispatchEvent(event);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -1131,8 +1131,7 @@ int ModApiEnvMod::l_fix_light(lua_State *L)
|
||||
if (!modified_blocks.empty()) {
|
||||
MapEditEvent event;
|
||||
event.type = MEET_OTHER;
|
||||
for (auto &modified_block : modified_blocks)
|
||||
event.modified_blocks.insert(modified_block.first);
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
|
||||
map.dispatchEvent(event);
|
||||
}
|
||||
@ -1238,7 +1237,7 @@ int ModApiEnvMod::l_delete_area(lua_State *L)
|
||||
v3s16 bp(x, y, z);
|
||||
if (map.deleteBlock(bp)) {
|
||||
env->setStaticForActiveObjectsInBlock(bp, false);
|
||||
event.modified_blocks.insert(bp);
|
||||
event.modified_blocks.push_back(bp);
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
|
@ -128,8 +128,7 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
|
||||
|
||||
MapEditEvent event;
|
||||
event.type = MEET_OTHER;
|
||||
for (const auto &it : modified_blocks)
|
||||
event.modified_blocks.insert(it.first);
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
map->dispatchEvent(event);
|
||||
|
||||
return 0;
|
||||
|
@ -699,9 +699,7 @@ void Server::AsyncRunStep(bool initial_step)
|
||||
if (!modified_blocks.empty()) {
|
||||
MapEditEvent event;
|
||||
event.type = MEET_OTHER;
|
||||
for (const auto &pair : modified_blocks) {
|
||||
event.modified_blocks.insert(pair.first);
|
||||
}
|
||||
event.setModifiedBlocks(modified_blocks);
|
||||
m_env->getMap().dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user