X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fmapblock.cpp;h=e9c8fadff64a2c84794b8dcadc59da144172b851;hb=69bd803a3221bf02672431390e672b0510695254;hp=efe628a4e6fc3349c04a28b071489bdfdd280dd5;hpb=d0ea6f9920d30f46d1f5d44e8823a8d932f9f29d;p=oweals%2Fminetest.git diff --git a/src/mapblock.cpp b/src/mapblock.cpp index efe628a4e..e9c8fadff 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock_mesh.h" #endif #include "util/string.h" +#include "util/serialize.h" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" @@ -56,7 +57,8 @@ 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) @@ -552,12 +554,12 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) throw SerializationError("ERROR: Not writing dummy block."); } - if(version <= 21) - { - serialize_pre22(os, version, disk); - return; - } - + // Can't do this anymore; we have 16-bit dynamically allocated node IDs + // in memory; conversion just won't work in this direction. + if(version < 24) + throw SerializationError("MapBlock::serialize: serialization to " + "version < 24 not possible"); + // First byte u8 flags = 0; if(is_underground) @@ -582,8 +584,7 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) tmp_nodes[i] = data[i]; getBlockNodeIdMapping(&nimap, tmp_nodes, m_gamedef->ndef()); - u8 content_width = 1; - /*u8 content_width = (nimap.size() <= 255) ? 1 : 2;*/ + u8 content_width = 2; u8 params_width = 2; writeU8(os, content_width); writeU8(os, params_width); @@ -593,8 +594,7 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) } else { - u8 content_width = 1; - /*u8 content_width = 2;*/ + u8 content_width = 2; u8 params_width = 2; writeU8(os, content_width); writeU8(os, params_width); @@ -606,10 +606,7 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) Node metadata */ std::ostringstream oss(std::ios_base::binary); - if(version >= 23) - m_node_metadata.serialize(oss); - else - content_nodemeta_serialize_legacy(oss, &m_node_metadata); + m_node_metadata.serialize(oss); compressZlib(oss.str(), os); /* @@ -617,13 +614,10 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) */ if(disk) { - // Version 23 doesn't actually contain node timers - // (this field should have not been added) - if(version == 23) - writeU8(os, 0); - // Node timers (uncomment when node timers are taken into use) - /*if(version >= 24) - m_node_timers.serialize(os);*/ + if(version <= 24){ + // Node timers + m_node_timers.serialize(os, version); + } // Static objects m_static_objects.serialize(os); @@ -633,10 +627,14 @@ 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::deSerialize(std::istream &is, u8 version, bool disk) { if(!ser_ver_supported(version)) @@ -666,7 +664,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk) u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; u8 content_width = readU8(is); u8 params_width = readU8(is); - if(content_width != 1) + if(content_width != 1 && content_width != 2) throw SerializationError("MapBlock::deSerialize(): invalid content_width"); if(params_width != 2) throw SerializationError("MapBlock::deSerialize(): invalid params_width"); @@ -703,15 +701,15 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk) if(disk) { // Node timers - if(version == 23) + if(version == 23){ // Read unused zero readU8(is); - // Uncomment when node timers are taken into use - /*else if(version >= 24){ + } + if(version == 24){ TRACESTREAM(<<"MapBlock::deSerialize "<= 25){ + TRACESTREAM(<<"MapBlock::deSerialize "<=25)"< unknown_contents; - for(u32 i=0; iget(id); - const std::string &name = f.name; - if(name == "") - unknown_contents.insert(id); - else - nimap->set(id, name); - } - for(std::set::const_iterator - i = unknown_contents.begin(); - i != unknown_contents.end(); i++){ - errorstream<<"getBlockNodeIdMapping_pre22(): IGNORING ERROR: " - <<"Name for node id "<<(*i)<<" not known"<ndef(); - for(u32 i=0; iget(tmp_data[i].getContent()); - // Mineral - if(nodedef->getId("default:stone_with_coal") == tmp_data[i].getContent()) - { - tmp_data[i].setContent(nodedef->getId("default:stone")); - tmp_data[i].setParam1(1); // MINERAL_COAL - } - else if(nodedef->getId("default:stone_with_iron") == tmp_data[i].getContent()) - { - tmp_data[i].setContent(nodedef->getId("default:stone")); - tmp_data[i].setParam1(2); // MINERAL_IRON - } - // facedir_simple - if(f.legacy_facedir_simple) - { - tmp_data[i].setParam1(tmp_data[i].getParam2()); - tmp_data[i].setParam2(0); - } - // wall_mounted - if(f.legacy_wallmounted) - { - u8 wallmounted_new_to_old[8] = {0x04, 0x08, 0x01, 0x02, 0x10, 0x20, 0, 0}; - u8 dir_new_format = tmp_data[i].getParam2() & 7; // lowest 3 bits - u8 dir_old_format = wallmounted_new_to_old[dir_new_format]; - tmp_data[i].setParam2(dir_old_format); - } - } - - // Serialize nodes - u32 ser_length = MapNode::serializedLength(version); - SharedBuffer databuf_nodelist(nodecount * ser_length); - for(u32 i=0; i materialdata(nodecount); - for(u32 i=0; i lightdata(nodecount); - for(u32 i=0; i= 10) - { - // Get and compress param2 - SharedBuffer param2data(nodecount); - for(u32 i=0; i= 18) - { - if(m_generated == false) - flags |= 0x08; - } - writeU8(os, flags); - - /* - Get data - */ - - // Create buffer with different parameters sorted - SharedBuffer databuf(nodecount*3); - for(u32 i=0; i= 14) - { - if(version <= 15) - { - try{ - std::ostringstream oss(std::ios_base::binary); - content_nodemeta_serialize_legacy(oss, &m_node_metadata); - os<= 9) - { - // count=0 - writeU16(os, 0); - } - - // Versions up from 15 have static objects. - if(version >= 15) - { - m_static_objects.serialize(os); - } - - // Timestamp - if(version >= 17) - { - writeU32(os, getTimestamp()); - } - - // Scan and write node definition id mapping - if(version >= 21) - { - NameIdMapping nimap; - getBlockNodeIdMapping_pre22(&nimap, data, m_gamedef->ndef()); - nimap.serialize(os); - } - } -} - void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk) { u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE;