SEnv: Remove static_exists from ActiveObjects in deleted blocks
authorkwolekr <kwolekr@minetest.net>
Sat, 15 Aug 2015 18:03:36 +0000 (14:03 -0400)
committerkwolekr <kwolekr@minetest.net>
Sun, 16 Aug 2015 19:55:07 +0000 (15:55 -0400)
src/environment.cpp
src/environment.h
src/script/lua_api/l_env.cpp

index 5bed1147630b2b5c5b3a46c4a061e80378ef5ce0..dbbfc6f1ff9d9bef1746d8c7edd78954c93a78bc 100644 (file)
@@ -1424,6 +1424,33 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
        }
 }
 
+void ServerEnvironment::setStaticForActiveObjectsInBlock(
+       v3s16 blockpos, bool static_exists, v3s16 static_block)
+{
+       MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
+       if (!block)
+               return;
+
+       for (std::map<u16, StaticObject>::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<u16, ServerActiveObject *>::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"
index 2bc128f40b71eb997be0120c6b5f8ff403b00aa2..c7069431678983ed4294580e6c8d8e5e23bf5525 100644 (file)
@@ -327,6 +327,11 @@ public:
 
        std::set<v3s16>* 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 setStaticForActiveObjectsInBlock(v3s16 blockpos,
+               bool static_exists, v3s16 static_block=v3s16(0,0,0));
+
 private:
 
        /*
index 9d1936769192d03c8f03dbcc59297d7541ed94ad..28afdd07147de0ca482bd3eba8a1f78b9e203907 100644 (file)
@@ -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->setStaticForActiveObjectsInBlock(bp, false);
                        event.modified_blocks.insert(bp);
-               else
+               } else {
                        success = false;
+               }
        }
 
        map.dispatchEvent(&event);