diff options
-rw-r--r-- | src/environment.cpp | 38 | ||||
-rw-r--r-- | src/map.cpp | 9 | ||||
-rw-r--r-- | src/mapblock.cpp | 2 | ||||
-rw-r--r-- | src/mapblock.h | 68 | ||||
-rw-r--r-- | src/mapgen.cpp | 2 | ||||
-rw-r--r-- | src/server.cpp | 11 | ||||
-rw-r--r-- | src/test.cpp | 6 |
7 files changed, 74 insertions, 62 deletions
diff --git a/src/environment.cpp b/src/environment.cpp index 2c5c2d2b8..5206ecc5d 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."<<std::endl; // Clear stored list block->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 81befd081..1e7abc57f 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: " + <<block->getModifiedReason()<<std::endl; saveBlock(block); saved_blocks_count++; } @@ -2281,7 +2284,8 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data, /* Set block as modified */ - block->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: " + <<block->getModifiedReason()<<std::endl; saveBlock(block); block_count++; diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 76b8a5e79..bc678db15 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -41,6 +41,8 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy): m_pos(pos), m_gamedef(gamedef), m_modified(MOD_STATE_WRITE_NEEDED), + m_modified_reason("initial"), + m_modified_reason_too_long(false), is_underground(false), m_lighting_expired(true), m_day_night_differs(false), diff --git a/src/mapblock.h b/src/mapblock.h index 0866fc396..5b27d01c3 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -143,7 +143,7 @@ public: //data[i] = MapNode(); data[i] = MapNode(CONTENT_IGNORE); } - raiseModified(MOD_STATE_WRITE_NEEDED); + raiseModified(MOD_STATE_WRITE_NEEDED, "reallocate"); } /* @@ -160,45 +160,37 @@ public: reallocate(); } - /* - This is called internally or externally after the block is - modified, so that the block is saved and possibly not deleted from - memory. - */ - // DEPRECATED, use *Modified() - void setChangedFlag() - { - //dstream<<"Deprecated setChangedFlag() called"<<std::endl; - raiseModified(MOD_STATE_WRITE_NEEDED); - } - // DEPRECATED, use *Modified() - void resetChangedFlag() - { - //dstream<<"Deprecated resetChangedFlag() called"<<std::endl; - resetModified(); - } - // DEPRECATED, use *Modified() - bool getChangedFlag() - { - //dstream<<"Deprecated getChangedFlag() called"<<std::endl; - if(getModified() == MOD_STATE_CLEAN) - return false; - else - return true; - } - // m_modified methods - void raiseModified(u32 mod) - { - m_modified = MYMAX(m_modified, mod); + void raiseModified(u32 mod, const std::string &reason="unknown") + { + if(mod > 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 999c757d0..4688a87c4 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 ad80851dd..207f35dcb 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<u16, RemoteClient*>::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 2a25ed656..f778f2d91 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 |