]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapgen_v5.cpp
src/network/connection.h: Fix race condition
[minetest.git] / src / mapgen_v5.cpp
index 92febf43b2f4e2ff8c24278a8e1bdcb5e4d9fd5e..f23dad4ecb635e2d58dca0c118f657998f3ae404 100644 (file)
@@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "content_sao.h"
 #include "nodedef.h"
 #include "voxelalgorithms.h"
-#include "profiler.h"
 #include "settings.h" // For g_settings
 #include "emerge.h"
 #include "dungeongen.h"
@@ -58,6 +57,8 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)
 
        this->biomemap  = new u8[csize.X * csize.Z];
        this->heightmap = new s16[csize.X * csize.Z];
+       this->heatmap   = NULL;
+       this->humidmap  = NULL;
 
        MapgenV5Params *sp = (MapgenV5Params *)params->sparams;
        this->spflags      = sp->spflags;
@@ -68,13 +69,15 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)
        noise_height       = new Noise(&sp->np_height,       seed, csize.X, csize.Z);
 
        // 3D terrain noise
-       noise_cave1        = new Noise(&sp->np_cave1,   seed, csize.X, csize.Y + 2, csize.Z);
-       noise_cave2        = new Noise(&sp->np_cave2,   seed, csize.X, csize.Y + 2, csize.Z);
-       noise_ground       = new Noise(&sp->np_ground,  seed, csize.X, csize.Y + 2, csize.Z);
+       noise_cave1  = new Noise(&sp->np_cave1,  seed, csize.X, csize.Y + 2, csize.Z);
+       noise_cave2  = new Noise(&sp->np_cave2,  seed, csize.X, csize.Y + 2, csize.Z);
+       noise_ground = new Noise(&sp->np_ground, seed, csize.X, csize.Y + 2, csize.Z);
 
        // Biome noise
-       noise_heat         = new Noise(&params->np_biome_heat,     seed, csize.X, csize.Z);
-       noise_humidity     = new Noise(&params->np_biome_humidity, seed, csize.X, csize.Z);
+       noise_heat           = new Noise(&params->np_biome_heat,           seed, csize.X, csize.Z);
+       noise_humidity       = new Noise(&params->np_biome_humidity,       seed, csize.X, csize.Z);
+       noise_heat_blend     = new Noise(&params->np_biome_heat_blend,     seed, csize.X, csize.Z);
+       noise_humidity_blend = new Noise(&params->np_biome_humidity_blend, seed, csize.X, csize.Z);
 
        //// Resolve nodes to be used
        INodeDefManager *ndef = emerge->ndef;
@@ -116,6 +119,8 @@ MapgenV5::~MapgenV5()
 
        delete noise_heat;
        delete noise_humidity;
+       delete noise_heat_blend;
+       delete noise_humidity_blend;
 
        delete[] heightmap;
        delete[] biomemap;
@@ -330,7 +335,16 @@ void MapgenV5::calculateNoise()
        noise_filler_depth->perlinMap2D(x, z);
        noise_heat->perlinMap2D(x, z);
        noise_humidity->perlinMap2D(x, z);
+       noise_heat_blend->perlinMap2D(x, z);
+       noise_humidity_blend->perlinMap2D(x, z);
 
+       for (s32 i = 0; i < csize.X * csize.Z; i++) {
+               noise_heat->result[i] += noise_heat_blend->result[i];
+               noise_humidity->result[i] += noise_humidity_blend->result[i];
+       }
+
+       heatmap = noise_heat->result;
+       humidmap = noise_humidity->result;
        //printf("calculateNoise: %dus\n", t.stop());
 }
 
@@ -491,30 +505,24 @@ MgStoneType MapgenV5::generateBiomes(float *heat_map, float *humidity_map)
 
 void MapgenV5::generateCaves(int max_stone_y)
 {
-       u32 index = 0;
-       u32 index2d = 0;
+       if (max_stone_y >= node_min.Y) {
+               u32 index = 0;
 
-       for (s16 z=node_min.Z; z<=node_max.Z; z++) {
-               for (s16 y=node_min.Y - 1; y<=node_max.Y + 1; y++) {
+               for (s16 z = node_min.Z; z <= node_max.Z; z++)
+               for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
                        u32 i = vm->m_area.index(node_min.X, y, z);
-                       for (s16 x=node_min.X; x<=node_max.X; x++, i++, index++, index2d++) {
+                       for (s16 x = node_min.X; x <= node_max.X; x++, i++, index++) {
                                float d1 = contour(noise_cave1->result[index]);
                                float d2 = contour(noise_cave2->result[index]);
                                if (d1*d2 > 0.125) {
-                                       Biome *biome = (Biome *)bmgr->getRaw(biomemap[index2d]);
                                        content_t c = vm->m_data[i].getContent();
-                                       if (!ndef->get(c).is_ground_content || c == CONTENT_AIR ||
-                                                       (y <= water_level &&
-                                                       c != biome->c_stone &&
-                                                       c != c_stone))
+                                       if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
                                                continue;
 
                                        vm->m_data[i] = MapNode(CONTENT_AIR);
                                }
                        }
-                       index2d -= ystride;
                }
-               index2d += ystride;
        }
 
        if (node_max.Y > LARGE_CAVE_DEPTH)