X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fmap.cpp;h=8bdc2ad4c97f341e8bffd3faa737cfccdcad97de;hb=cd563473fa298db3b910009f26ba263bacd84be9;hp=13f2a0e984d0ab13e951fa07255de4b8b2738ab2;hpb=251b015210f55f028fdde8035928c7cf893fce75;p=oweals%2Fminetest.git diff --git a/src/map.cpp b/src/map.cpp index 13f2a0e98..8bdc2ad4c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -208,6 +208,15 @@ void Map::setNode(v3s16 p, MapNode & n) v3s16 blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreate(blockpos); v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; + // Never allow placing CONTENT_IGNORE, it fucks up stuff + if(n.getContent() == CONTENT_IGNORE){ + errorstream<<"Map::setNode(): Not allowing to place CONTENT_IGNORE" + <<" while trying to replace \"" + <ndef()->get(block->getNodeNoCheck(relpos)).name + <<"\" at "<setNodeNoCheck(relpos, n); } @@ -851,15 +860,15 @@ void Map::updateLighting(enum LightBank bank, for(s16 y=-1; y<=1; y++) for(s16 x=-1; x<=1; x++) { - v3s16 p(x,y,z); - MapBlock *block = getBlockNoCreateNoEx(p); + v3s16 p2 = p + v3s16(x,y,z); + MapBlock *block = getBlockNoCreateNoEx(p2); if(block == NULL) continue; if(block->isDummy()) continue; if(block->getLightingExpired()) continue; - vmanip.initialEmerge(p, p); + vmanip.initialEmerge(p2, p2); }*/ // Lighting of block will be updated completely @@ -994,13 +1003,17 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n, /* Add intial metadata */ - - NodeMetadata *meta_proto = nodemgr->get(n).initial_metadata; - if(meta_proto) - { - NodeMetadata *meta = meta_proto->clone(m_gamedef); - meta->setOwner(player_name); - setNodeMetadata(p, meta); + + std::string metadata_name = nodemgr->get(n).metadata_name; + if(metadata_name != ""){ + NodeMetadata *meta = NodeMetadata::create(metadata_name, m_gamedef); + if(!meta){ + errorstream<<"Failed to create node metadata \"" + <setOwner(player_name); + setNodeMetadata(p, meta); + } } /* @@ -1397,6 +1410,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, core::list sector_deletion_queue; u32 deleted_blocks_count = 0; u32 saved_blocks_count = 0; + u32 block_count_all = 0; core::map::Iterator si; @@ -1442,6 +1456,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, else { all_blocks_deleted = false; + block_count_all++; } } @@ -1462,6 +1477,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, <<" blocks from memory"; if(save_before_unloading) infostream<<", of which "< & modified_blocks) switch (liquid_type) { case LIQUID_SOURCE: liquid_level = LIQUID_LEVEL_SOURCE; - liquid_kind = nodemgr->get(n0).liquid_alternative_flowing; + liquid_kind = nodemgr->getId(nodemgr->get(n0).liquid_alternative_flowing); break; case LIQUID_FLOWING: liquid_level = (n0.param2 & LIQUID_LEVEL_MASK); @@ -1663,18 +1679,20 @@ void Map::transformLiquids(core::map & modified_blocks) case LIQUID_SOURCE: // if this node is not (yet) of a liquid type, choose the first liquid type we encounter if (liquid_kind == CONTENT_AIR) - liquid_kind = nodemgr->get(nb.n.getContent()).liquid_alternative_flowing; - if (nodemgr->get(nb.n.getContent()).liquid_alternative_flowing !=liquid_kind) { + liquid_kind = nodemgr->getId(nodemgr->get(nb.n).liquid_alternative_flowing); + if (nodemgr->getId(nodemgr->get(nb.n).liquid_alternative_flowing) != liquid_kind) { neutrals[num_neutrals++] = nb; } else { - sources[num_sources++] = nb; + // Do not count bottom source, it will screw things up + if(dirs[i].Y != -1) + sources[num_sources++] = nb; } break; case LIQUID_FLOWING: // if this node is not (yet) of a liquid type, choose the first liquid type we encounter if (liquid_kind == CONTENT_AIR) - liquid_kind = nodemgr->get(nb.n.getContent()).liquid_alternative_flowing; - if (nodemgr->get(nb.n.getContent()).liquid_alternative_flowing != liquid_kind) { + liquid_kind = nodemgr->getId(nodemgr->get(nb.n).liquid_alternative_flowing); + if (nodemgr->getId(nodemgr->get(nb.n).liquid_alternative_flowing) != liquid_kind) { neutrals[num_neutrals++] = nb; } else { flows[num_flows++] = nb; @@ -1695,7 +1713,7 @@ void Map::transformLiquids(core::map & modified_blocks) // liquid_kind will be set to either the flowing alternative of the node (if it's a liquid) // or the flowing alternative of the first of the surrounding sources (if it's air), so // it's perfectly safe to use liquid_kind here to determine the new node content. - new_node_content = nodemgr->get(liquid_kind).liquid_alternative_source; + new_node_content = nodemgr->getId(nodemgr->get(liquid_kind).liquid_alternative_source); } else if (num_sources == 1 && sources[0].t != NEIGHBOR_LOWER) { // liquid_kind is set properly, see above new_node_content = liquid_kind; @@ -2000,7 +2018,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef): emergeSector(v2s16(0,0)); // Initially write whole map - save(false); + save(MOD_STATE_CLEAN); } ServerMap::~ServerMap() @@ -2012,7 +2030,7 @@ ServerMap::~ServerMap() if(m_map_saving_enabled) { // Save only changed parts - save(true); + save(MOD_STATE_WRITE_AT_UNLOAD); infostream<<"Server: saved map to "<vmanip.print(infostream);*/ - + + // Make sure affected blocks are loaded + for(s16 x=-1; x<=1; x++) + for(s16 z=-1; z<=1; z++) + for(s16 y=-1; y<=1; y++) + { + v3s16 p(blockpos.X+x, blockpos.Y+y, blockpos.Z+z); + // Load from disk if not already in memory + emergeBlock(p, false); + } + /* Blit generated stuff to map NOTE: blitBackAll adds nearly everything to changed_blocks @@ -2303,7 +2331,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data, Save changed parts of map NOTE: Will be saved later. */ - //save(true); + //save(MOD_STATE_WRITE_AT_UNLOAD); /*infostream<<"finishBlockMake() done for ("<::Iterator i = m_sectors.getIterator(); for(; i.atEnd() == false; i++) { ServerMapSector *sector = (ServerMapSector*)i.getNode()->getValue(); assert(sector->getId() == MAPSECTOR_SERVER); - if(sector->differs_from_disk || only_changed == false) + if(sector->differs_from_disk || save_level == MOD_STATE_CLEAN) { saveSectorMeta(sector); sector_meta_count++; @@ -2852,17 +2882,22 @@ void ServerMap::save(bool only_changed) sector->getBlocks(blocks); core::list::Iterator j; - //sqlite3_exec(m_database, "BEGIN;", NULL, NULL, NULL); for(j=blocks.begin(); j!=blocks.end(); j++) { MapBlock *block = *j; block_count_all++; - if(block->getModified() >= MOD_STATE_WRITE_NEEDED - || only_changed == false) + if(block->getModified() >= save_level) { + // Lazy beginSave() + if(!save_started){ + beginSave(); + save_started = true; + } + modprofiler.add(block->getModifiedReason(), 1); + saveBlock(block); block_count++; @@ -2872,15 +2907,15 @@ void ServerMap::save(bool only_changed) <getPos().Z<<")" <