From: Perttu Ahola Date: Tue, 12 Nov 2013 17:54:32 +0000 (+0200) Subject: Revert patch 58f036ad1 that causes object duplication (which tried to fix objects... X-Git-Tag: 0.4.8~31 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=21789ccc5f2e372fe462e54944fef3a31c790110;p=oweals%2Fminetest.git Revert patch 58f036ad1 that causes object duplication (which tried to fix objects getting hidden from client) and fix the original problem correctly. This fixes the second distinct object duplication bug. --- diff --git a/src/environment.cpp b/src/environment.cpp index 8a52a143d..f019591df 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1417,8 +1417,8 @@ void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius, ServerActiveObject *object = i->second; if(object == NULL) continue; - // Discard if removed - if(object->m_removed) + // Discard if removed or deactivating + if(object->m_removed || object->m_pending_deactivation) continue; if(object->unlimitedTransferDistance() == false){ // Discard if too far @@ -1468,7 +1468,7 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius, continue; } - if(object->m_removed) + if(object->m_removed || object->m_pending_deactivation) { removed_objects.insert(id); continue; @@ -1556,9 +1556,8 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, StaticObject s_obj(object->getType(), objectpos, staticdata); // Add to the block where the object is located in v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); - MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos); - if(block) - { + MapBlock *block = m_map->emergeBlock(blockpos); + if(block){ block->m_static_objects.m_active[object->getId()] = s_obj; object->m_static_exists = true; object->m_static_block = blockpos; @@ -1566,11 +1565,10 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, if(set_changed) block->raiseModified(MOD_STATE_WRITE_NEEDED, "addActiveObjectRaw"); - } - else{ + } else { v3s16 p = floatToInt(objectpos, BS); errorstream<<"ServerEnvironment::addActiveObjectRaw(): " - <<"could not find block for storing id="<getId() + <<"could not emerge block for storing id="<getId() <<" statically (pos="<m_static_objects.remove(id); block->raiseModified(MOD_STATE_WRITE_NEEDED, - "removeRemovedObjects"); + "removeRemovedObjects/remove"); obj->m_static_exists = false; } else { - infostream << "failed to emerge block from which " - "an object to be removed was loaded from. id="< new_stored; - // Loop through stored static objects for(std::list::iterator i = block->m_static_objects.m_stored.begin(); i != block->m_static_objects.m_stored.end(); ++i) @@ -1750,6 +1768,19 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) StaticObject &s_obj = *i; block->m_static_objects.m_stored.push_back(s_obj); } + + // Turn the active counterparts of activated objects not pending for + // deactivation + for(std::map::iterator + i = block->m_static_objects.m_active.begin(); + i != block->m_static_objects.m_active.end(); ++i) + { + u16 id = i->first; + ServerActiveObject *object = getActiveObject(id); + assert(object); + object->m_pending_deactivation = false; + } + /* Note: Block hasn't really been modified here. The objects have just been activated and moved from the stored @@ -1910,6 +1941,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) block = m_map->emergeBlock(blockpos); } catch(InvalidPositionException &e){ // Handled via NULL pointer + // NOTE: emergeBlock's failure is usually determined by it + // actually returning NULL } if(block) @@ -1923,17 +1956,21 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) <<" Forcing delete."<m_static_block, but happens rarely for some unknown + // reason. Unsuccessful attempts have been made to find + // said reason. if(id && block->m_static_objects.m_active.find(id) != block->m_static_objects.m_active.end()){ infostream<<"ServerEnv: WARNING: Performing hack #83274" <m_static_objects.remove(id); } - //store static data - block->m_static_objects.insert(0, s_obj); + // Store static data + u16 store_id = pending_delete ? id : 0; + block->m_static_objects.insert(store_id, s_obj); // Only mark block as modified if data changed considerably if(shall_be_written)