]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapblock.cpp
make formspec textarea wordwrap
[dragonfireclient.git] / src / mapblock.cpp
index c7c820d42e7cfc6fa80ab0e00767f7c8c53857b3..95e54fb33ce849ced6f6452ee50da21e376c3d5b 100644 (file)
@@ -1,6 +1,6 @@
 /*
-Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -21,8 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include <sstream>
 #include "map.h"
-// For g_settings
-#include "main.h"
 #include "light.h"
 #include "nodedef.h"
 #include "nodemetadata.h"
@@ -31,10 +29,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nameidmapping.h"
 #include "content_mapnode.h" // For legacy name-id mapping
 #include "content_nodemeta.h" // For legacy deserialization
+#include "serialization.h"
 #ifndef SERVER
 #include "mapblock_mesh.h"
 #endif
 #include "util/string.h"
+#include "util/serialize.h"
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
 
@@ -56,14 +56,14 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
                m_generated(false),
                m_timestamp(BLOCK_TIMESTAMP_UNDEFINED),
                m_disk_timestamp(BLOCK_TIMESTAMP_UNDEFINED),
-               m_usage_timer(0)
+               m_usage_timer(0),
+               m_refcount(0)
 {
        data = NULL;
        if(dummy == false)
                reallocate();
        
 #ifndef SERVER
-       //mesh_mutex.Init();
        mesh = NULL;
 #endif
 }
@@ -166,7 +166,7 @@ MapNode MapBlock::getNodeParentNoEx(v3s16 p)
        if black_air_left!=NULL, it is set to true if non-sunlighted
        air is left in block.
 */
-bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
+bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
                bool remove_light, bool *black_air_left)
 {
        INodeDefManager *nodemgr = m_gamedef->ndef();
@@ -285,7 +285,7 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
                                
                                if(diminish_light(current_light) != 0)
                                {
-                                       light_sources.insert(pos_relative + pos, true);
+                                       light_sources.insert(pos_relative + pos);
                                }
 
                                if(current_light == 0 && stopped_to_solid_object)
@@ -612,8 +612,10 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk)
        */
        if(disk)
        {
-               // Node timers
-               m_node_timers.serialize(os);
+               if(version <= 24){
+                       // Node timers
+                       m_node_timers.serialize(os, version);
+               }
 
                // Static objects
                m_static_objects.serialize(os);
@@ -623,6 +625,26 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk)
 
                // Write block-specific node definition id mapping
                nimap.serialize(os);
+               
+               if(version >= 25){
+                       // Node timers
+                       m_node_timers.serialize(os, version);
+               }
+       }
+}
+
+void MapBlock::serializeNetworkSpecific(std::ostream &os, u16 net_proto_version)
+{
+       if(data == NULL)
+       {
+               throw SerializationError("ERROR: Not writing dummy block.");
+       }
+
+       if(net_proto_version >= 21){
+               int version = 1;
+               writeU8(os, version);
+               writeF1000(os, 0); // deprecated heat
+               writeF1000(os, 0); // deprecated humidity
        }
 }
 
@@ -696,10 +718,10 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk)
                        // Read unused zero
                        readU8(is);
                }
-               else if(version >= 24){
+               if(version == 24){
                        TRACESTREAM(<<"MapBlock::deSerialize "<<PP(getPos())
-                                       <<": Node timers"<<std::endl);
-                       m_node_timers.deSerialize(is);
+                                       <<": Node timers (ver==24)"<<std::endl);
+                       m_node_timers.deSerialize(is, version);
                }
 
                // Static objects
@@ -719,12 +741,36 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk)
                NameIdMapping nimap;
                nimap.deSerialize(is);
                correctBlockNodeIds(&nimap, data, m_gamedef);
+
+               if(version >= 25){
+                       TRACESTREAM(<<"MapBlock::deSerialize "<<PP(getPos())
+                                       <<": Node timers (ver>=25)"<<std::endl);
+                       m_node_timers.deSerialize(is, version);
+               }
        }
                
        TRACESTREAM(<<"MapBlock::deSerialize "<<PP(getPos())
                        <<": Done."<<std::endl);
 }
 
+void MapBlock::deSerializeNetworkSpecific(std::istream &is)
+{
+       try {
+               int version = readU8(is);
+               //if(version != 1)
+               //      throw SerializationError("unsupported MapBlock version");
+               if(version >= 1) {
+                       readF1000(is); // deprecated heat
+                       readF1000(is); // deprecated humidity
+               }
+       }
+       catch(SerializationError &e)
+       {
+               errorstream<<"WARNING: MapBlock::deSerializeNetworkSpecific(): Ignoring an error"
+                               <<": "<<e.what()<<std::endl;
+       }
+}
+
 /*
        Legacy serialization
 */