Tune caves
[oweals/minetest.git] / src / map.cpp
index d6b33ed66dc6e9c73fb0e701e59e99d1142c4c65..835aca4fbdebfbf946b1858424f136a132c58d3d 100644 (file)
@@ -690,6 +690,8 @@ void Map::updateLighting(enum LightBank bank,
        core::map<v3s16, bool> light_sources;
 
        core::map<v3s16, u8> unlight_from;
+
+       int num_bottom_invalid = 0;
        
        {
        //TimeTaker t("first stuff");
@@ -727,10 +729,16 @@ void Map::updateLighting(enum LightBank bank,
                                        n.setLight(bank, 0, nodemgr);
                                        block->setNode(p, n);
 
+                                       // If node sources light, add to list
+                                       u8 source = nodemgr->get(n).light_source;
+                                       if(source != 0)
+                                               light_sources[p + posnodes] = true;
+
                                        // Collect borders for unlighting
-                                       if(x==0 || x == MAP_BLOCKSIZE-1
+                                       if((x==0 || x == MAP_BLOCKSIZE-1
                                        || y==0 || y == MAP_BLOCKSIZE-1
                                        || z==0 || z == MAP_BLOCKSIZE-1)
+                                       && oldlight != 0)
                                        {
                                                v3s16 p_map = p + posnodes;
                                                unlight_from.insert(p_map, oldlight);
@@ -752,6 +760,9 @@ void Map::updateLighting(enum LightBank bank,
                        {
                                bool bottom_valid = block->propagateSunlight(light_sources);
 
+                               if(!bottom_valid)
+                                       num_bottom_invalid++;
+
                                // If bottom is valid, we're done.
                                if(bottom_valid)
                                        break;
@@ -786,7 +797,7 @@ void Map::updateLighting(enum LightBank bank,
        }
 
        }
-       
+
        /*
                Enable this to disable proper lighting for speeding up map
                generation for testing or whatever
@@ -806,38 +817,43 @@ void Map::updateLighting(enum LightBank bank,
        }
 #endif
 
-#if 0
+#if 1
        {
-               TimeTaker timer("unspreadLight");
+               //TimeTaker timer("unspreadLight");
                unspreadLight(bank, unlight_from, light_sources, modified_blocks);
        }
 
-       if(debug)
+       /*if(debug)
        {
                u32 diff = modified_blocks.size() - count_was;
                count_was = modified_blocks.size();
                infostream<<"unspreadLight modified "<<diff<<std::endl;
-       }
+       }*/
 
        {
-               TimeTaker timer("spreadLight");
+               //TimeTaker timer("spreadLight");
                spreadLight(bank, light_sources, modified_blocks);
        }
 
-       if(debug)
+       /*if(debug)
        {
                u32 diff = modified_blocks.size() - count_was;
                count_was = modified_blocks.size();
                infostream<<"spreadLight modified "<<diff<<std::endl;
-       }
+       }*/
 #endif
 
+#if 0
        {
                //MapVoxelManipulator vmanip(this);
-
+               
                // Make a manual voxel manipulator and load all the blocks
                // that touch the requested blocks
                ManualMapVoxelManipulator vmanip(this);
+
+               {
+               //TimeTaker timer("initialEmerge");
+
                core::map<v3s16, MapBlock*>::Iterator i;
                i = blocks_to_update.getIterator();
                for(; i.atEnd() == false; i++)
@@ -871,6 +887,7 @@ void Map::updateLighting(enum LightBank bank,
                        // Lighting of block will be updated completely
                        block->setLightingExpired(false);
                }
+               }
 
                {
                        //TimeTaker timer("unSpreadLight");
@@ -887,6 +904,7 @@ void Map::updateLighting(enum LightBank bank,
                /*infostream<<"emerge_time="<<emerge_time<<std::endl;
                emerge_time = 0;*/
        }
+#endif
 
        //m_dout<<"Done ("<<getTimestamp()<<")"<<std::endl;
 }
@@ -2056,14 +2074,24 @@ void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
                                <<"("<<blockpos.X<<","<<blockpos.Y<<","<<blockpos.Z<<")"
                                <<std::endl;
        
-       s16 chunksize = 3;
-       v3s16 blockpos_div = getContainerPos(blockpos, chunksize);
+       //s16 chunksize = 3;
+       //v3s16 chunk_offset(-1,-1,-1);
+       //s16 chunksize = 4;
+       //v3s16 chunk_offset(-1,-1,-1);
+       s16 chunksize = 5;
+       v3s16 chunk_offset(-2,-2,-2);
+       v3s16 blockpos_div = getContainerPos(blockpos - chunk_offset, chunksize);
        v3s16 blockpos_min = blockpos_div * chunksize;
        v3s16 blockpos_max = blockpos_div * chunksize + v3s16(1,1,1)*(chunksize-1);
-       
+       blockpos_min += chunk_offset;
+       blockpos_max += chunk_offset;
+
+       //v3s16 extra_borders(1,1,1);
+       v3s16 extra_borders(1,1,1);
+
        // Do nothing if not inside limits (+-1 because of neighbors)
-       if(blockpos_over_limit(blockpos_min - v3s16(1,1,1)) ||
-               blockpos_over_limit(blockpos_max + v3s16(1,1,1)))
+       if(blockpos_over_limit(blockpos_min - extra_borders) ||
+               blockpos_over_limit(blockpos_max + extra_borders))
        {
                data->no_op = true;
                return;
@@ -2082,15 +2110,18 @@ void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
        {
                //TimeTaker timer("initBlockMake() create area");
                
-               for(s16 x=blockpos_min.X-1; x<=blockpos_max.X+1; x++)
-               for(s16 z=blockpos_min.Z-1; z<=blockpos_max.Z+1; z++)
+               for(s16 x=blockpos_min.X-extra_borders.X;
+                               x<=blockpos_max.X+extra_borders.X; x++)
+               for(s16 z=blockpos_min.Z-extra_borders.Z;
+                               z<=blockpos_max.Z+extra_borders.Z; z++)
                {
                        v2s16 sectorpos(x, z);
                        // Sector metadata is loaded from disk if not already loaded.
                        ServerMapSector *sector = createSector(sectorpos);
                        assert(sector);
 
-                       for(s16 y=blockpos_min.Y-1; y<=blockpos_max.Y+1; y++)
+                       for(s16 y=blockpos_min.Y-extra_borders.Y;
+                                       y<=blockpos_max.Y+extra_borders.Y; y++)
                        {
                                v3s16 p(x,y,z);
                                //MapBlock *block = createBlock(p);
@@ -2126,8 +2157,8 @@ void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
        */
        
        // The area that contains this block and it's neighbors
-       v3s16 bigarea_blocks_min = blockpos_min - v3s16(1,1,1);
-       v3s16 bigarea_blocks_max = blockpos_max + v3s16(1,1,1);
+       v3s16 bigarea_blocks_min = blockpos_min - extra_borders;
+       v3s16 bigarea_blocks_max = blockpos_max + extra_borders;
        
        data->vmanip = new ManualMapVoxelManipulator(this);
        //data->vmanip->setMap(this);
@@ -2151,6 +2182,8 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
                        <<blockpos_requested.Y<<","
                        <<blockpos_requested.Z<<")"<<std::endl;*/
 
+       v3s16 extra_borders(1,1,1);
+
        if(data->no_op)
        {
                //infostream<<"finishBlockMake(): no-op"<<std::endl;
@@ -2163,9 +2196,12 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
        data->vmanip.print(infostream);*/
 
        // Make sure affected blocks are loaded
-       for(s16 x=blockpos_min.X-1; x<=blockpos_max.X+1; x++)
-       for(s16 z=blockpos_min.Z-1; z<=blockpos_max.Z+1; z++)
-       for(s16 y=blockpos_min.Y-1; y<=blockpos_max.Y+1; y++)
+       for(s16 x=blockpos_min.X-extra_borders.X;
+                       x<=blockpos_max.X+extra_borders.X; x++)
+       for(s16 z=blockpos_min.Z-extra_borders.Z;
+                       z<=blockpos_max.Z+extra_borders.Z; z++)
+       for(s16 y=blockpos_min.Y-extra_borders.Y;
+                       y<=blockpos_max.Y+extra_borders.Y; y++)
        {
                v3s16 p(x, y, z);
                // Load from disk if not already in memory
@@ -2203,14 +2239,18 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
                Update lighting
        */
        {
+#if 0
                TimeTaker t("finishBlockMake lighting update");
 
                core::map<v3s16, MapBlock*> lighting_update_blocks;
                
                // Center blocks
-               for(s16 x=blockpos_min.X; x<=blockpos_max.X; x++)
-               for(s16 z=blockpos_min.Z; z<=blockpos_max.Z; z++)
-               for(s16 y=blockpos_min.Y; y<=blockpos_max.Y; y++)
+               for(s16 x=blockpos_min.X-extra_borders.X;
+                               x<=blockpos_max.X+extra_borders.X; x++)
+               for(s16 z=blockpos_min.Z-extra_borders.Z;
+                               z<=blockpos_max.Z+extra_borders.Z; z++)
+               for(s16 y=blockpos_min.Y-extra_borders.Y;
+                               y<=blockpos_max.Y+extra_borders.Y; y++)
                {
                        v3s16 p(x, y, z);
                        MapBlock *block = getBlockNoCreateNoEx(p);
@@ -2219,39 +2259,30 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
                }
 
                updateLighting(lighting_update_blocks, changed_blocks);
+#endif
                
                /*
                        Set lighting to non-expired state in all of them.
                        This is cheating, but it is not fast enough if all of them
                        would actually be updated.
                */
-               for(s16 x=blockpos_min.X-1; x<=blockpos_max.X+1; x++)
-               for(s16 z=blockpos_min.Z-1; z<=blockpos_max.Z+1; z++)
-               for(s16 y=blockpos_min.Y-1; y<=blockpos_max.Y+1; y++)
+               for(s16 x=blockpos_min.X-extra_borders.X;
+                               x<=blockpos_max.X+extra_borders.X; x++)
+               for(s16 z=blockpos_min.Z-extra_borders.Z;
+                               z<=blockpos_max.Z+extra_borders.Z; z++)
+               for(s16 y=blockpos_min.Y-extra_borders.Y;
+                               y<=blockpos_max.Y+extra_borders.Y; y++)
                {
                        v3s16 p(x, y, z);
                        getBlockNoCreateNoEx(p)->setLightingExpired(false);
                }
 
+#if 0
                if(enable_mapgen_debug_info == false)
                        t.stop(true); // Hide output
+#endif
        }
 
-       // Center blocks
-       for(s16 x=blockpos_min.X; x<=blockpos_max.X; x++)
-       for(s16 z=blockpos_min.Z; z<=blockpos_max.Z; z++)
-       for(s16 y=blockpos_min.Y; y<=blockpos_max.Y; y++)
-       {
-               v3s16 p(x, y, z);
-               MapBlock *block = getBlockNoCreateNoEx(p);
-               assert(block);
-
-               /*
-                       Add random objects to block
-               */
-               mapgen::add_random_objects(block);
-       }
-       
        /*
                Go through changed blocks
        */