From 5a6e6d5fd88679e38c348b26b176a43a5c074640 Mon Sep 17 00:00:00 2001 From: darkrose Date: Sat, 21 Mar 2015 05:49:30 +1000 Subject: [PATCH] just some tweaks to the last commit --- src/environment.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index c89628f..81ae8a2 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -861,6 +861,14 @@ void ServerEnvironment::step(float dtime) if (block == NULL) continue; + std::list new_list; + for (std::list::iterator oi = block->m_active_objects.begin(); oi != block->m_active_objects.end(); oi++) { + ServerActiveObject *obj = getActiveObject(*oi); + if (obj && obj->m_static_exists && obj->m_static_block == block->getPos()) + new_list.push_back(*oi); + } + block->m_active_objects.swap(new_list); + // Reset block usage timer if (circuitstep || metastep) block->resetUsageTimer(); @@ -3479,11 +3487,11 @@ void ServerEnvironment::removeRemovedObjects() for (std::map::iterator i = m_active_objects.begin(); i != m_active_objects.end(); ++i) { u16 id = i->first; ServerActiveObject* obj = i->second; - // This shouldn't happen but check it + // this shouldn't happen but check it if (obj == NULL) { infostream<<"NULL object found in ServerEnvironment" <<" while finding removed objects. id="<m_static_exists) { MapBlock *block = m_map->emergeBlock(obj->m_static_block, false); if (block) { - obj->m_static_exists = false; + bool keep = false; for (std::list::iterator oi = block->m_active_objects.begin(); oi != block->m_active_objects.end(); oi++) { if (*oi == id) { - obj->m_static_exists = true; + keep = true; break; } } + obj->m_static_exists = keep; } } if (!obj->m_static_exists) { @@ -3516,8 +3525,10 @@ void ServerEnvironment::removeRemovedObjects() } continue; } - if (obj->m_known_by_count > 0) + if (obj->m_known_by_count > 0) { + obj->m_pending_deactivation = true; continue; + } /* Delete static data from block if is marked as removed @@ -3590,8 +3601,7 @@ void ServerEnvironment::activateObjects(MapBlock *block) <<"activating objects of block "<getPos()) <<" ("<m_static_objects.m_objects.size() <<" objects)"<m_static_objects.m_objects.size() > 49); - if (large_amount) { + if (block->m_static_objects.m_objects.size() > 49) { errorstream<<"suspiciously large amount of objects detected: " <m_static_objects.m_objects.size()<<" in " <getPos()) @@ -3605,8 +3615,6 @@ void ServerEnvironment::activateObjects(MapBlock *block) // Activate stored objects std::list new_stored; for (std::list::iterator i = block->m_static_objects.m_objects.begin(); i != block->m_static_objects.m_objects.end(); i++) { - /*infostream<<"Server: Creating an active object from " - <<"static data"<