X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmapblock.cpp;h=ca80c39d71cae6d55d9f2a49cccbdccdc2ebeb18;hb=7220ca906dfc804bd508336f5bed252bcec62ae0;hp=a6e9b3951f9d8103bbc53176d2f99d39b547e3d0;hpb=6d0ea26c2d62c3774ff384cf1bfc2a3372b49a3b;p=dragonfireclient.git diff --git a/src/mapblock.cpp b/src/mapblock.cpp index a6e9b3951..ca80c39d7 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -21,8 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "map.h" -// For g_settings -#include "main.h" #include "light.h" #include "nodedef.h" #include "nodemetadata.h" @@ -31,6 +29,7 @@ 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 @@ -63,9 +62,8 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy): data = NULL; if(dummy == false) reallocate(); - + #ifndef SERVER - //mesh_mutex.Init(); mesh = NULL; #endif } @@ -75,7 +73,7 @@ MapBlock::~MapBlock() #ifndef SERVER { //JMutexAutoLock lock(mesh_mutex); - + if(mesh) { delete mesh; @@ -99,60 +97,25 @@ bool MapBlock::isValidPositionParent(v3s16 p) } } -MapNode MapBlock::getNodeParent(v3s16 p) +MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position) { - if(isValidPosition(p) == false) - { - return m_parent->getNode(getPosRelative() + p); - } - else - { - if(data == NULL) - throw InvalidPositionException(); - return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X]; - } -} + if (isValidPosition(p) == false) + return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position); -void MapBlock::setNodeParent(v3s16 p, MapNode & n) -{ - if(isValidPosition(p) == false) - { - m_parent->setNode(getPosRelative() + p, n); - } - else - { - if(data == NULL) - throw InvalidPositionException(); - data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X] = n; - } -} - -MapNode MapBlock::getNodeParentNoEx(v3s16 p) -{ - if(isValidPosition(p) == false) - { - try{ - return m_parent->getNode(getPosRelative() + p); - } - catch(InvalidPositionException &e) - { - return MapNode(CONTENT_IGNORE); - } - } - else - { - if(data == NULL) - { - return MapNode(CONTENT_IGNORE); - } - return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X]; + if (data == NULL) { + if (is_valid_position) + *is_valid_position = false; + return MapNode(CONTENT_IGNORE); } + if (is_valid_position) + *is_valid_position = true; + return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X]; } /* Propagates sunlight down through the block. Doesn't modify nodes that are not affected by sunlight. - + Returns false if sunlight at bottom block is invalid. Returns true if sunlight at bottom block is valid. Returns true if bottom block doesn't exist. @@ -168,26 +131,31 @@ 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 & light_sources, +bool MapBlock::propagateSunlight(std::set & light_sources, bool remove_light, bool *black_air_left) { INodeDefManager *nodemgr = m_gamedef->ndef(); // Whether the sunlight at the top of the bottom block is valid bool block_below_is_valid = true; - + v3s16 pos_relative = getPosRelative(); - + for(s16 x=0; x & light_sources, no_sunlight = true; } } - catch(InvalidPositionException &e) + else { - no_top_block = true; - + //no_top_block = true; + // NOTE: This makes over-ground roofed places sunlighted // Assume sunlight, unless is_underground==true if(is_underground) @@ -210,7 +178,7 @@ bool MapBlock::propagateSunlight(core::map & light_sources, } else { - MapNode n = getNode(v3s16(x, MAP_BLOCKSIZE-1, z)); + MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z)); if(m_gamedef->ndef()->get(n).sunlight_propagates == false) { no_sunlight = true; @@ -243,19 +211,19 @@ bool MapBlock::propagateSunlight(core::map & light_sources, <<", is_underground="<ndef(); + // Running this function un-expires m_day_night_differs m_day_night_differs_expired = false; - if(data == NULL) - { + if (data == NULL) { m_day_night_differs = false; return; } - bool differs = false; + bool differs; /* Check if any lighting value differs */ - for(u32 i=0; i mapping; + memset(getBlockNodeIdMapping_mapping, 0xFF, USHRT_MAX * sizeof(content_t)); + std::set unknown_contents; content_t id_counter = 0; for(u32 i=0; i::iterator j = mapping.find(global_id); - if(j != mapping.end()) - { - id = j->second; + if (getBlockNodeIdMapping_mapping[global_id] != 0xFFFF) { + id = getBlockNodeIdMapping_mapping[global_id]; } else { // We have to assign a new mapping id = id_counter++; - mapping.insert(std::make_pair(global_id, id)); + getBlockNodeIdMapping_mapping[global_id] = id; const ContentFeatures &f = nodedef->get(global_id); const std::string &name = f.name; @@ -548,18 +515,14 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) { if(!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapBlock format not supported"); - + if(data == NULL) { throw SerializationError("ERROR: Not writing dummy block."); } - - // 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"); - + + FATAL_ERROR_IF(version < SER_FMT_CLIENT_VER_LOWEST, "Serialize version error"); + // First byte u8 flags = 0; if(is_underground) @@ -571,7 +534,7 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) if(m_generated == false) flags |= 0x08; writeU8(os, flags); - + /* Bulk node data */ @@ -601,7 +564,7 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) MapNode::serializeBulk(os, version, data, nodecount, content_width, params_width, true); } - + /* Node metadata */ @@ -627,7 +590,7 @@ 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); @@ -635,11 +598,26 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk) } } +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 + } +} + void MapBlock::deSerialize(std::istream &is, u8 version, bool disk) { if(!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapBlock format not supported"); - + TRACESTREAM(<<"MapBlock::deSerialize "<= 1) { + readF1000(is); // deprecated heat + readF1000(is); // deprecated humidity + } + } + catch(SerializationError &e) + { + errorstream<<"WARNING: MapBlock::deSerializeNetworkSpecific(): Ignoring an error" + <<": "<= 10) { // Uncompress and set param2 data @@ -847,7 +843,7 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk) databuf_nodelist[i*ser_length + 1] = s[i+nodecount]; databuf_nodelist[i*ser_length + 2] = s[i+nodecount*2]; } - + /* NodeMetadata */ @@ -984,12 +980,12 @@ std::string analyze_block(MapBlock *block) return "NULL"; std::ostringstream desc; - + v3s16 p = block->getPos(); char spos[20]; snprintf(spos, 20, "(%2d,%2d,%2d), ", p.X, p.Y, p.Z); desc<getModified()) { case MOD_STATE_CLEAN: @@ -1035,7 +1031,7 @@ std::string analyze_block(MapBlock *block) for(s16 x0=0; x0getNode(p); + MapNode n = block->getNodeNoEx(p); content_t c = n.getContent(); if(c == CONTENT_IGNORE) some_ignore = true; @@ -1046,21 +1042,21 @@ std::string analyze_block(MapBlock *block) else full_air = false; } - + desc<<"content {"; - + std::ostringstream ss; - + if(full_ignore) ss<<"IGNORE (full), "; else if(some_ignore) ss<<"IGNORE, "; - + if(full_air) ss<<"AIR (full), "; else if(some_air) ss<<"AIR, "; - + if(ss.str().size()>=2) desc<