Add reason parameter to setModified and print it out to verbosestream when saving...
authorPerttu Ahola <celeron55@gmail.com>
Mon, 21 Nov 2011 11:29:16 +0000 (13:29 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 29 Nov 2011 17:13:49 +0000 (19:13 +0200)
src/environment.cpp
src/map.cpp
src/mapblock.cpp
src/mapblock.h
src/mapgen.cpp
src/server.cpp
src/test.cpp

index 2c5c2d2b8a572f56f7f1de8b2e36ec749d7043f8..5206ecc5d7197c4e1985039e7a81a5c7d3abdda0 100644 (file)
@@ -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();
index 81befd0811fca12b3124b49bbaf0205aedf6976c..1e7abc57fc7f9d23bb1e5c4aadb896792f0c7318 100644 (file)
@@ -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++;
 
index 76b8a5e799be3a8912c47d8806df81a1ddc77f60..bc678db1533c49da99beacd6eb1948d68b06f787 100644 (file)
@@ -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),
index 0866fc396fa19b217ce804db4faa2c9a9b683adc..5b27d01c3327397c4f6bf52517dec94f926eb50f 100644 (file)
@@ -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,
index 999c757d0be681fb181bc37cb2de4897843c6bcf..4688a87c48a0af80ac6431b2cd4eb3ca050d0b78 100644 (file)
@@ -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
 }
 
index ad80851dd496d69a3a01f21dc99e31c298d2f4de..207f35dcb8300678e554839c45fb8fe9b26af07c 100644 (file)
@@ -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)
        {
index 2a25ed65648da31bd5007e5a5be94634e8f8b68c..f778f2d9149431122d91838daec2187e13c09999 100644 (file)
@@ -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