X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmap.cpp;h=03a842e7425bb3ae9e4f3014ad79eb9f7f0d25ce;hb=54917e306256d4d39b95335986fce93b8c56a6e3;hp=f1fbc7a1c1c8dbf1c5287dd5b96709877057f574;hpb=ec4f58741bedc098048234aac32662e08479fba2;p=minetest.git diff --git a/src/map.cpp b/src/map.cpp index f1fbc7a1c..03a842e74 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -21,23 +21,22 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapsector.h" #include "mapblock.h" #include "main.h" -#ifndef SERVER -#include "client.h" -#endif #include "filesys.h" #include "utility.h" #include "voxel.h" #include "porting.h" #include "mapgen.h" #include "nodemetadata.h" -#ifndef SERVER -#include -#endif #include "settings.h" #include "log.h" #include "profiler.h" #include "nodedef.h" #include "gamedef.h" +#ifndef SERVER +#include "client.h" +#include "mapblock_mesh.h" +#include +#endif #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" @@ -214,7 +213,7 @@ void Map::setNode(v3s16 p, MapNode & n) <<" while trying to replace \"" <ndef()->get(block->getNodeNoCheck(relpos)).name <<"\" at "<setNodeNoCheck(relpos, n); @@ -915,7 +914,7 @@ void Map::updateLighting(core::map & a_blocks, /* */ void Map::addNodeAndUpdate(v3s16 p, MapNode n, - core::map &modified_blocks, std::string &player_name) + core::map &modified_blocks) { INodeDefManager *nodemgr = m_gamedef->ndef(); @@ -1007,8 +1006,12 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n, std::string metadata_name = nodemgr->get(n).metadata_name; if(metadata_name != ""){ NodeMetadata *meta = NodeMetadata::create(metadata_name, m_gamedef); - meta->setOwner(player_name); - setNodeMetadata(p, meta); + if(!meta){ + errorstream<<"Failed to create node metadata \"" + < modified_blocks; - std::string st = std::string(""); - addNodeAndUpdate(p, n, modified_blocks, st); + addNodeAndUpdate(p, n, modified_blocks); // Copy modified_blocks to event for(core::map::Iterator @@ -1678,7 +1680,9 @@ void Map::transformLiquids(core::map & modified_blocks) 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: @@ -1911,7 +1915,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef): m_database_read(NULL), m_database_write(NULL) { - infostream<<__FUNCTION_NAME<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++; @@ -2881,8 +2870,7 @@ void ServerMap::save(bool only_changed) block_count_all++; - if(block->getModified() >= MOD_STATE_WRITE_NEEDED - || only_changed == false) + if(block->getModified() >= save_level) { // Lazy beginSave() if(!save_started){ @@ -2909,7 +2897,7 @@ void ServerMap::save(bool only_changed) /* Only print if something happened or saved whole map */ - if(only_changed == false || sector_meta_count != 0 + if(save_level == MOD_STATE_CLEAN || sector_meta_count != 0 || block_count != 0) { infostream<<"ServerMap: Written: " @@ -2973,9 +2961,9 @@ void ServerMap::saveMapMeta() { DSTACK(__FUNCTION_NAME); - infostream<<"ServerMap::saveMapMeta(): " + /*infostream<<"ServerMap::saveMapMeta(): " <<"seed="<avg("CM: blocks drawn", blocks_drawn); + g_profiler->avg("CM: animated meshes", mesh_animate_count); + g_profiler->avg("CM: animated meshes (far)", mesh_animate_count_far); } g_profiler->avg(prefix+"vertices drawn", vertex_count); @@ -4067,205 +4031,6 @@ void ClientMap::renderPostFx() } } -bool ClientMap::setTempMod(v3s16 p, NodeMod mod, - core::map *affected_blocks) -{ - bool changed = false; - /* - Add it to all blocks touching it - */ - v3s16 dirs[7] = { - v3s16(0,0,0), // this - v3s16(0,0,1), // back - v3s16(0,1,0), // top - v3s16(1,0,0), // right - v3s16(0,0,-1), // front - v3s16(0,-1,0), // bottom - v3s16(-1,0,0), // left - }; - for(u16 i=0; i<7; i++) - { - v3s16 p2 = p + dirs[i]; - // Block position of neighbor (or requested) node - v3s16 blockpos = getNodeBlockPos(p2); - MapBlock * blockref = getBlockNoCreateNoEx(blockpos); - if(blockref == NULL) - continue; - // Relative position of requested node - v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; - if(blockref->setTempMod(relpos, mod)) - { - changed = true; - } - } - if(changed && affected_blocks!=NULL) - { - for(u16 i=0; i<7; i++) - { - v3s16 p2 = p + dirs[i]; - // Block position of neighbor (or requested) node - v3s16 blockpos = getNodeBlockPos(p2); - MapBlock * blockref = getBlockNoCreateNoEx(blockpos); - if(blockref == NULL) - continue; - affected_blocks->insert(blockpos, blockref); - } - } - return changed; -} - -bool ClientMap::clearTempMod(v3s16 p, - core::map *affected_blocks) -{ - bool changed = false; - v3s16 dirs[7] = { - v3s16(0,0,0), // this - v3s16(0,0,1), // back - v3s16(0,1,0), // top - v3s16(1,0,0), // right - v3s16(0,0,-1), // front - v3s16(0,-1,0), // bottom - v3s16(-1,0,0), // left - }; - for(u16 i=0; i<7; i++) - { - v3s16 p2 = p + dirs[i]; - // Block position of neighbor (or requested) node - v3s16 blockpos = getNodeBlockPos(p2); - MapBlock * blockref = getBlockNoCreateNoEx(blockpos); - if(blockref == NULL) - continue; - // Relative position of requested node - v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; - if(blockref->clearTempMod(relpos)) - { - changed = true; - } - } - if(changed && affected_blocks!=NULL) - { - for(u16 i=0; i<7; i++) - { - v3s16 p2 = p + dirs[i]; - // Block position of neighbor (or requested) node - v3s16 blockpos = getNodeBlockPos(p2); - MapBlock * blockref = getBlockNoCreateNoEx(blockpos); - if(blockref == NULL) - continue; - affected_blocks->insert(blockpos, blockref); - } - } - return changed; -} - -void ClientMap::expireMeshes(bool only_daynight_diffed) -{ - TimeTaker timer("expireMeshes()"); - - core::map::Iterator si; - si = m_sectors.getIterator(); - for(; si.atEnd() == false; si++) - { - MapSector *sector = si.getNode()->getValue(); - - core::list< MapBlock * > sectorblocks; - sector->getBlocks(sectorblocks); - - core::list< MapBlock * >::Iterator i; - for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++) - { - MapBlock *block = *i; - - if(only_daynight_diffed && dayNightDiffed(block->getPos()) == false) - { - continue; - } - - { - JMutexAutoLock lock(block->mesh_mutex); - if(block->mesh != NULL) - { - /*block->mesh->drop(); - block->mesh = NULL;*/ - block->setMeshExpired(true); - } - } - } - } -} - -void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio) -{ - assert(mapType() == MAPTYPE_CLIENT); - - try{ - v3s16 p = blockpos + v3s16(0,0,0); - MapBlock *b = getBlockNoCreate(p); - b->updateMesh(daynight_ratio); - //b->setMeshExpired(true); - } - catch(InvalidPositionException &e){} - // Leading edge - try{ - v3s16 p = blockpos + v3s16(-1,0,0); - MapBlock *b = getBlockNoCreate(p); - b->updateMesh(daynight_ratio); - //b->setMeshExpired(true); - } - catch(InvalidPositionException &e){} - try{ - v3s16 p = blockpos + v3s16(0,-1,0); - MapBlock *b = getBlockNoCreate(p); - b->updateMesh(daynight_ratio); - //b->setMeshExpired(true); - } - catch(InvalidPositionException &e){} - try{ - v3s16 p = blockpos + v3s16(0,0,-1); - MapBlock *b = getBlockNoCreate(p); - b->updateMesh(daynight_ratio); - //b->setMeshExpired(true); - } - catch(InvalidPositionException &e){} -} - -#if 0 -/* - Update mesh of block in which the node is, and if the node is at the - leading edge, update the appropriate leading blocks too. -*/ -void ClientMap::updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio) -{ - v3s16 dirs[4] = { - v3s16(0,0,0), - v3s16(-1,0,0), - v3s16(0,-1,0), - v3s16(0,0,-1), - }; - v3s16 blockposes[4]; - for(u32 i=0; i<4; i++) - { - v3s16 np = nodepos + dirs[i]; - blockposes[i] = getNodeBlockPos(np); - // Don't update mesh of block if it has been done already - bool already_updated = false; - for(u32 j=0; jupdateMesh(daynight_ratio); - } -} -#endif - void ClientMap::PrintInfo(std::ostream &out) { out<<"ClientMap: ";