From: Perttu Ahola Date: Mon, 21 Nov 2011 11:29:16 +0000 (+0200) Subject: Add reason parameter to setModified and print it out to verbosestream when saving... X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=1b765b974003219fe395a5b97afaf6cfa9f0d7ed;p=zefram%2Fminetest%2Fminetest_engine.git Add reason parameter to setModified and print it out to verbosestream when saving block --- diff --git a/src/environment.cpp b/src/environment.cpp index 2c5c2d2b..5206ecc5 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -583,7 +583,8 @@ void spawnRandomObjects(MapBlock *block) // Add one block->m_static_objects.insert(0, s_obj); delete obj; - block->setChangedFlag(); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "spawnRandomObjects"); } } } @@ -620,7 +621,8 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime) event.p = block->getPos(); m_map->dispatchEvent(&event); - block->setChangedFlag(); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "node metadata modified in activateBlock"); } // TODO: Do something @@ -671,7 +673,8 @@ void ServerEnvironment::clearAllObjects() MapBlock *block = m_map->getBlockNoCreateNoEx(obj->m_static_block); if(block){ block->m_static_objects.remove(id); - block->raiseModified(MOD_STATE_WRITE_NEEDED); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "clearAllObjects"); obj->m_static_exists = false; } } @@ -722,7 +725,8 @@ void ServerEnvironment::clearAllObjects() if(num_stored != 0 || num_active != 0){ block->m_static_objects.m_stored.clear(); block->m_static_objects.m_active.clear(); - block->raiseModified(MOD_STATE_WRITE_NEEDED); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "clearAllObjects"); num_objs_cleared += num_stored + num_active; num_blocks_cleared++; } @@ -930,7 +934,8 @@ void ServerEnvironment::step(float dtime) event.p = p; m_map->dispatchEvent(&event); - block->setChangedFlag(); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "node metadata modified in step"); } } } @@ -1338,7 +1343,8 @@ bool ServerEnvironment::addActiveObjectAsStatic(ServerActiveObject *obj) if(block) { block->m_static_objects.insert(0, s_obj); - block->raiseModified(MOD_STATE_WRITE_AT_UNLOAD); + block->raiseModified(MOD_STATE_WRITE_AT_UNLOAD, + "addActiveObjectAsStatic"); succeeded = true; } else{ @@ -1503,7 +1509,8 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, object->m_static_block = blockpos; if(set_changed) - block->raiseModified(MOD_STATE_WRITE_NEEDED); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "addActiveObjectRaw"); } else{ errorstream<<"ServerEnvironment::addActiveObjectRaw(): " @@ -1557,7 +1564,8 @@ void ServerEnvironment::removeRemovedObjects() if(block) { block->m_static_objects.remove(id); - block->raiseModified(MOD_STATE_WRITE_NEEDED); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "removeRemovedObjects"); obj->m_static_exists = false; } } @@ -1638,7 +1646,9 @@ void ServerEnvironment::activateObjects(MapBlock *block) <<"; removing all of them."<m_static_objects.m_stored.clear(); - block->raiseModified(MOD_STATE_WRITE_NEEDED); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "stored list cleared in activateObjects due to " + "large amount of objects"); return; } // A list for objects that couldn't be converted to static for some @@ -1688,7 +1698,7 @@ void ServerEnvironment::activateObjects(MapBlock *block) The objects have just been activated and moved from the stored static list to the active static list. As such, the block is essentially the same. - Thus, do not call block->setChangedFlag(). + Thus, do not call block->raiseModified(MOD_STATE_WRITE_NEEDED). Otherwise there would be a huge amount of unnecessary I/O. */ } @@ -1788,7 +1798,9 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) obj->m_static_exists = false; // Only mark block as modified if data changed considerably if(shall_be_written) - block->raiseModified(MOD_STATE_WRITE_NEEDED); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "deactivateFarObjects: Static data " + "changed considerably"); } } @@ -1813,7 +1825,9 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) // Only mark block as modified if data changed considerably if(shall_be_written) - block->raiseModified(MOD_STATE_WRITE_NEEDED); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "deactivateFarObjects: Static data " + "changed considerably"); obj->m_static_exists = true; obj->m_static_block = block->getPos(); diff --git a/src/map.cpp b/src/map.cpp index 81befd08..1e7abc57 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1423,6 +1423,9 @@ void Map::timerUpdate(float dtime, float unload_timeout, if(block->getModified() != MOD_STATE_CLEAN && save_before_unloading) { + verbosestream<<"Saving block before unloading, " + <<"modified by: " + <getModifiedReason()<raiseModified(MOD_STATE_WRITE_NEEDED); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "finishBlockMake updateDayNightDiff"); } /* @@ -2849,6 +2853,9 @@ void ServerMap::save(bool only_changed) if(block->getModified() >= MOD_STATE_WRITE_NEEDED || only_changed == false) { + verbosestream<<"Saving block because of MOD_STATE_WRITE_NEEDED, " + <<"modified by: " + <getModifiedReason()< m_modified){ + m_modified = mod; + m_modified_reason = reason; + m_modified_reason_too_long = false; + } else if(mod == m_modified){ + if(!m_modified_reason_too_long){ + if(m_modified_reason.size() < 40) + m_modified_reason += ", " + reason; + else{ + m_modified_reason += "..."; + m_modified_reason_too_long = true; + } + } + } } u32 getModified() { return m_modified; } + std::string getModifiedReason() + { + return m_modified_reason; + } void resetModified() { m_modified = MOD_STATE_CLEAN; + m_modified_reason = "none"; + m_modified_reason_too_long = false; } // is_underground getter/setter @@ -209,7 +201,7 @@ public: void setIsUnderground(bool a_is_underground) { is_underground = a_is_underground; - raiseModified(MOD_STATE_WRITE_NEEDED); + raiseModified(MOD_STATE_WRITE_NEEDED, "setIsUnderground"); } #ifndef SERVER @@ -228,7 +220,7 @@ public: { if(expired != m_lighting_expired){ m_lighting_expired = expired; - raiseModified(MOD_STATE_WRITE_NEEDED); + raiseModified(MOD_STATE_WRITE_NEEDED, "setLightingExpired"); } } bool getLightingExpired() @@ -243,7 +235,7 @@ public: void setGenerated(bool b) { if(b != m_generated){ - raiseModified(MOD_STATE_WRITE_NEEDED); + raiseModified(MOD_STATE_WRITE_NEEDED, "setGenerated"); m_generated = b; } } @@ -324,7 +316,7 @@ public: if(y < 0 || y >= MAP_BLOCKSIZE) throw InvalidPositionException(); if(z < 0 || z >= MAP_BLOCKSIZE) throw InvalidPositionException(); data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x] = n; - raiseModified(MOD_STATE_WRITE_NEEDED); + raiseModified(MOD_STATE_WRITE_NEEDED, "setNode"); } void setNode(v3s16 p, MapNode & n) @@ -353,7 +345,7 @@ public: if(data == NULL) throw InvalidPositionException(); data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x] = n; - raiseModified(MOD_STATE_WRITE_NEEDED); + raiseModified(MOD_STATE_WRITE_NEEDED, "setNodeNoCheck"); } void setNodeNoCheck(v3s16 p, MapNode & n) @@ -507,7 +499,7 @@ public: void setTimestamp(u32 time) { m_timestamp = time; - raiseModified(MOD_STATE_WRITE_AT_UNLOAD); + raiseModified(MOD_STATE_WRITE_AT_UNLOAD, "setTimestamp"); } void setTimestampNoChangedFlag(u32 time) { @@ -608,6 +600,8 @@ private: - On the client, this is used for nothing. */ u32 m_modified; + std::string m_modified_reason; + bool m_modified_reason_too_long; /* When propagating sunlight and the above block doesn't exist, diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 999c757d..4688a87c 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -1478,7 +1478,7 @@ void add_random_objects(MapBlock *block) last_node_walkable = false; } } - block->setChangedFlag(); + block->raiseModified(MOD_STATE_WRITE_NEEDED, "mapgen::add_random_objects"); #endif } diff --git a/src/server.cpp b/src/server.cpp index ad80851d..207f35dc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3087,16 +3087,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos); if(block) { - block->setChangedFlag(); + block->raiseModified(MOD_STATE_WRITE_NEEDED, + "sign node text"); } - for(core::map::Iterator - i = m_clients.getIterator(); - i.atEnd()==false; i++) - { - RemoteClient *client = i.getNode()->getValue(); - client->SetBlockNotSent(blockpos); - } + setBlockNotSent(blockpos); } else if(command == TOSERVER_INVENTORY_ACTION) { diff --git a/src/test.cpp b/src/test.cpp index 2a25ed65..f778f2d9 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -393,9 +393,9 @@ struct TestMapBlock MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/ // Changed flag should be initially set - assert(b.getChangedFlag() == true); - b.resetChangedFlag(); - assert(b.getChangedFlag() == false); + assert(b.getModified() == MOD_STATE_WRITE_NEEDED); + b.resetModified(); + assert(b.getModified() == MOD_STATE_CLEAN); // All nodes should have been set to // .d=CONTENT_IGNORE and .getLight() = 0