From 393345e6f78a21b4f7284f942ddb81066fbd2077 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sat, 15 Aug 2015 14:03:36 -0400 Subject: [PATCH] SEnv: Remove static_exists from ActiveObjects in deleted blocks --- src/environment.cpp | 28 +++++++++++++++++++++++++++- src/environment.h | 5 +++++ src/script/lua_api/l_env.cpp | 6 ++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index 5bed11476..bd09e36b4 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1424,6 +1424,33 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius, } } +void ServerEnvironment::setStaticForObjectsInBlock( + v3s16 blockpos, bool static_exists, v3s16 static_block) +{ + MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos); + if (!block) + return; + + for (std::map::iterator + so_it = block->m_static_objects.m_active.begin(); + so_it != block->m_static_objects.m_active.end(); ++so_it) { + // Get the ServerActiveObject counterpart to this StaticObject + std::map::iterator ao_it; + ao_it = m_active_objects.find(so_it->first); + if (ao_it == m_active_objects.end()) { + // If this ever happens, there must be some kind of nasty bug. + errorstream << "ServerEnvironment::setStaticForObjectsInBlock(): " + "Object from MapBlock::m_static_objects::m_active not found " + "in m_active_objects"; + continue; + } + + ServerActiveObject *sao = ao_it->second; + sao->m_static_exists = static_exists; + sao->m_static_block = static_block; + } +} + ActiveObjectMessage ServerEnvironment::getActiveObjectMessage() { if(m_active_object_messages.empty()) @@ -1960,7 +1987,6 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) } } - #ifndef SERVER #include "clientsimpleobject.h" diff --git a/src/environment.h b/src/environment.h index 2bc128f40..3ab3f37a9 100644 --- a/src/environment.h +++ b/src/environment.h @@ -327,6 +327,11 @@ public: std::set* getForceloadedBlocks() { return &m_active_blocks.m_forceloaded_list; }; + // Sets the static object status all the active objects in the specified block + // This is only really needed for deleting blocks from the map + void setStaticForObjectsInBlock(v3s16 blockpos, + bool static_exists, v3s16 static_block=v3s16(0,0,0)); + private: /* diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 9d1936769..5bb2bbba8 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -773,10 +773,12 @@ int ModApiEnvMod::l_delete_area(lua_State *L) for (s16 y = bpmin.Y; y <= bpmax.Y; y++) for (s16 x = bpmin.X; x <= bpmax.X; x++) { v3s16 bp(x, y, z); - if (map.deleteBlock(bp)) + if (map.deleteBlock(bp)) { + env->setStaticForObjectsInBlock(bp, false); event.modified_blocks.insert(bp); - else + } else { success = false; + } } map.dispatchEvent(&event);