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