X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmap.cpp;h=ba4130ca29e860a9b6196cc66a1be5ecdb990988;hb=9b907dd65a2c045d10605894fdaea504200e2be7;hp=eb55d3a57ec0fff4c63769d961c70a27f3dc5cc5;hpb=061d4b420206c67fb346d75fb6bcaf4aa8147ca8;p=minetest.git diff --git a/src/map.cpp b/src/map.cpp index eb55d3a57..ba4130ca2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -28,6 +28,15 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "porting.h" #include "mapgen.h" #include "nodemetadata.h" +#include "content_mapnode.h" +#ifndef SERVER +#include +#endif +#include "settings.h" +#include "log.h" +#include "profiler.h" + +#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" /* SQLite format specification: @@ -341,7 +350,7 @@ void Map::unspreadLight(enum LightBank bank, */ /*if(light_sources.find(n2pos)) { - std::cout<<"Removed from light_sources"<getKey(); //v3s16 pos = *j; - //dstream<<"pos=("<get("")) { core::map::Iterator i; i = blocks_to_update.getIterator(); @@ -794,7 +803,7 @@ void Map::updateLighting(enum LightBank bank, { u32 diff = modified_blocks.size() - count_was; count_was = modified_blocks.size(); - dstream<<"unspreadLight modified "< & modified_blocks) u32 initial_size = m_transforming_liquid.size(); /*if(initial_size != 0) - dstream<<"transformLiquids(): initial_size="<get("fixed_map_seed").empty()) { m_seed = (((u64)(myrand()%0xffff)<<0) + ((u64)(myrand()%0xffff)<<16) @@ -1905,7 +1924,7 @@ ServerMap::ServerMap(std::string savedir): } else { - m_seed = g_settings.getU64("fixed_map_seed"); + m_seed = g_settings->getU64("fixed_map_seed"); } /* @@ -1930,7 +1949,7 @@ ServerMap::ServerMap(std::string savedir): // If directory is empty, it is safe to save into it. if(fs::GetDirListing(m_savedir).size() == 0) { - dstream<getBool("enable_mapgen_debug_info"); if(enable_mapgen_debug_info) - dstream<<"initBlockMake(): ("< &changed_blocks) { v3s16 blockpos = data->blockpos; - /*dstream<<"finishBlockMake(): ("<no_op) { - //dstream<<"finishBlockMake(): no-op"<getBool("enable_mapgen_debug_info"); - /*dstream<<"Resulting vmanip:"<vmanip.print(dstream);*/ + /*infostream<<"Resulting vmanip:"<vmanip.print(infostream);*/ /* Blit generated stuff to map @@ -2154,7 +2173,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data, } if(enable_mapgen_debug_info) - dstream<<"finishBlockMake: changed_blocks.size()=" + infostream<<"finishBlockMake: changed_blocks.size()=" <getBool("enable_mapgen_debug_info"); TimeTaker timer("generateBlock"); @@ -2407,7 +2426,7 @@ MapBlock * ServerMap::generateBlock( */ if(blockpos_over_limit(p)) { - dstream<<__FUNCTION_NAME<<": Block position over limit"<getNode(p); if(n.getContent() == CONTENT_IGNORE) { - dstream<<"CONTENT_IGNORE at " + infostream<<"CONTENT_IGNORE at " <<"("< MAP_GENERATION_LIMIT / MAP_BLOCKSIZE - || p.Y < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE - || p.Y > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE - || p.Z < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE - || p.Z > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE) - throw InvalidPositionException("emergeBlock(): pos. over limit"); - - v2s16 p2d(p.X, p.Z); - s16 block_y = p.Y; - /* - This will create or load a sector if not found in memory. - If block exists on disk, it will be loaded. - */ - ServerMapSector *sector; - try{ - sector = createSector(p2d); - //sector = emergeSector(p2d, changed_blocks); - } - catch(InvalidPositionException &e) - { - dstream<<"emergeBlock: createSector() failed: " - <getBlockNoCreateNoEx(block_y); - - // If not found, try loading from disk - if(block == NULL) - { - block = loadBlock(p); - } - - // Handle result - if(block == NULL) - { - does_not_exist = true; - } - else if(block->isDummy() == true) - { - does_not_exist = true; - } - else if(block->getLightingExpired()) - { - lighting_expired = true; - } - else - { - // Valid block - //dstream<<"emergeBlock(): Returning already valid block"<insertBlock(block); - } - // Done. - return block; - } - - //dstream<<"Not found on disk, generating."< making one"< light_sources; - bool black_air_left = false; - bool bottom_invalid = - block->propagateSunlight(light_sources, true, - &black_air_left); - - // If sunlight didn't reach everywhere and part of block is - // above ground, lighting has to be properly updated - //if(black_air_left && some_part_underground) - if(black_air_left) - { - lighting_invalidated_blocks[block->getPos()] = block; - } - - if(bottom_invalid) - { - lighting_invalidated_blocks[block->getPos()] = block; - } - } -#endif - - return block; -} -#endif - s16 ServerMap::findGroundLevel(v2s16 p2d) { #if 0 @@ -2806,7 +2679,7 @@ void ServerMap::createDatabase() { if(e == SQLITE_ABORT) throw FileNotGoodException("Could not create database structure"); else - dstream<<"Server: Database structure was created"; + infostream<<"Server: Database structure was created"; } void ServerMap::verifyDatabase() { @@ -2814,7 +2687,7 @@ void ServerMap::verifyDatabase() { return; { - std::string dbp = m_savedir + "/map.sqlite"; + std::string dbp = m_savedir + DIR_DELIM + "map.sqlite"; bool needs_create = false; int d; @@ -2829,7 +2702,7 @@ void ServerMap::verifyDatabase() { d = sqlite3_open_v2(dbp.c_str(), &m_database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); if(d != SQLITE_OK) { - dstream<<"WARNING: Database failed to open: "<getPos().X<<"," <getPos().Y<<"," <getPos().Z<<")" @@ -3012,7 +2891,7 @@ void ServerMap::save(bool only_changed) if(only_changed == false || sector_meta_count != 0 || block_count != 0) { - dstream<= 0) + return i % mod; + return mod - ((-i) % mod); +} + +v3s16 ServerMap::getIntegerAsBlock(sqlite3_int64 i) +{ + s32 x = unsignedToSigned(pythonmodulo(i, 4096), 2048); + i = (i - x) / 4096; + s32 y = unsignedToSigned(pythonmodulo(i, 4096), 2048); + i = (i - y) / 4096; + s32 z = unsignedToSigned(pythonmodulo(i, 4096), 2048); + return v3s16(x,y,z); +} + +void ServerMap::listAllLoadableBlocks(core::list &dst) +{ + if(loadFromFolders()){ + errorstream<<"Map::listAllLoadableBlocks(): Result will be missing " + <<"all blocks that are stored in flat files"<isDummy()) { /*v3s16 p = block->getPos(); - dstream<<"ServerMap::saveBlock(): WARNING: Not writing dummy block " + infostream<<"ServerMap::saveBlock(): WARNING: Not writing dummy block " <<"("<::Iterator si; @@ -3764,7 +3700,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) int time2 = time(0); if(time2 > time1 + 4) { - dstream<<"ClientMap::renderMap(): " + infostream<<"ClientMap::renderMap(): " "Rendering takes ages, returning." < range) continue;*/ + + blocks_in_range++; #if 1 /* @@ -3840,8 +3778,10 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) // Mesh has not been expired and there is no mesh: // block has no content - if(block->mesh == NULL && mesh_expired == false) + if(block->mesh == NULL && mesh_expired == false){ + blocks_in_range_without_mesh++; continue; + } } f32 faraway = BS*50; @@ -3879,9 +3819,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) JMutexAutoLock lock(block->mesh_mutex); scene::SMesh *mesh = block->mesh; - - if(mesh == NULL) + + if(mesh == NULL){ + blocks_in_range_without_mesh++; continue; + } blocks_would_have_drawn++; if(blocks_drawn >= m_control.wanted_max_blocks @@ -3893,7 +3835,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) sector_blocks_drawn++; u32 c = mesh->getMeshBufferCount(); - + bool stuff_actually_drawn = false; for(u32 i=0; igetMeshBuffer(i); @@ -3904,16 +3846,25 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) // Render transparent on transparent pass and likewise. if(transparent == is_transparent_pass) { + if(buf->getVertexCount() == 0) + errorstream<<"Block ["<setMaterial(buf->getMaterial()); driver->drawMeshBuffer(buf); vertex_count += buf->getVertexCount(); + meshbuffer_count++; + stuff_actually_drawn = true; } } + if(stuff_actually_drawn) + blocks_had_pass_meshbuf++; + else + blocks_without_stuff++; } } // foreach sectorblocks @@ -3923,10 +3874,34 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) } } + std::string prefix = "CM: "; + + // Log only on solid pass because values are the same + if(pass == scene::ESNRP_SOLID){ + g_profiler->avg(prefix+"blocks in range", blocks_in_range); + if(blocks_in_range != 0) + g_profiler->avg(prefix+"blocks in range without mesh (frac)", + (float)blocks_in_range_without_mesh/blocks_in_range); + g_profiler->avg(prefix+"blocks drawn", blocks_drawn); + } + + if(pass == scene::ESNRP_SOLID) + prefix = "CM: solid: "; + else + prefix = "CM: transparent: "; + + g_profiler->avg(prefix+"vertices drawn", vertex_count); + if(blocks_had_pass_meshbuf != 0) + g_profiler->avg(prefix+"meshbuffers per block", + (float)meshbuffer_count / (float)blocks_had_pass_meshbuf); + if(blocks_drawn != 0) + g_profiler->avg(prefix+"empty blocks (frac)", + (float)blocks_without_stuff / blocks_drawn); + m_control.blocks_drawn = blocks_drawn; m_control.blocks_would_have_drawn = blocks_would_have_drawn; - /*dstream<<"renderMap(): is_transparent_pass="<getBool("free_move") == false) { post_effect_color = video::SColor(255, 0, 0, 0); } @@ -4176,7 +4151,7 @@ MapVoxelManipulator::MapVoxelManipulator(Map *map) MapVoxelManipulator::~MapVoxelManipulator() { - /*dstream<<"MapVoxelManipulator: blocks: "<getBlockNoCreate(p); if(block->isDummy()) @@ -4240,7 +4215,7 @@ void MapVoxelManipulator::emerge(VoxelArea a, s32 caller_id) m_loaded_blocks.insert(p, !block_data_inexistent); } - //dstream<<"emerge done"<getBlockNoCreateNoEx(p); if(block == NULL) { - dstream<<"WARNING: "<<__FUNCTION_NAME + infostream<<"WARNING: "<<__FUNCTION_NAME <<": got NULL block " <<"("<