Mgv7/flat/fractal: Place biome top node on tunnel entrance floor
authorparamat <mat.gregory@virginmedia.com>
Mon, 11 Jan 2016 05:46:41 +0000 (05:46 +0000)
committerparamat <mat.gregory@virginmedia.com>
Thu, 14 Jan 2016 04:43:50 +0000 (04:43 +0000)
src/mapgen_flat.cpp
src/mapgen_fractal.cpp
src/mapgen_v7.cpp

index c961d755a45a7ddae17cb3048f7672bb0af79282..b7f01320fec4e635343ab2aca6eb26321dde867b 100644 (file)
@@ -551,20 +551,39 @@ void MapgenFlat::dustTopNodes()
 void MapgenFlat::generateCaves(s16 max_stone_y)
 {
        if (max_stone_y >= node_min.Y) {
-               u32 index = 0;
+               v3s16 em = vm->m_area.getExtent();
+               u32 index2d = 0;
+               u32 index3d;
 
                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 vi = vm->m_area.index(node_min.X, y, z);
-                       for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index++) {
-                               float d1 = contour(noise_cave1->result[index]);
-                               float d2 = contour(noise_cave2->result[index]);
-                               if (d1 * d2 > 0.3f) {
-                                       content_t c = vm->m_data[vi].getContent();
-                                       if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
-                                               continue;
-
+               for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
+                       bool open = false;  // Is column open to overground
+                       u32 vi = vm->m_area.index(x, node_max.Y + 1, z);
+                       index3d = (z - node_min.Z) * zstride + (csize.Y + 1) * ystride +
+                               (x - node_min.X);
+                       // Biome of column
+                       Biome *biome = (Biome *)bmgr->getRaw(biomemap[index2d]);
+
+                       for (s16 y = node_max.Y + 1; y >= node_min.Y - 1;
+                                       y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) {
+                               content_t c = vm->m_data[vi].getContent();
+                               if (c == CONTENT_AIR || c == biome->c_water_top ||
+                                               c == biome->c_water) {
+                                       open = true;
+                                       continue;
+                               }
+                               // Ground
+                               float d1 = contour(noise_cave1->result[index3d]);
+                               float d2 = contour(noise_cave2->result[index3d]);
+                               if (d1 * d2 > 0.3f && ndef->get(c).is_ground_content) {
+                                       // In tunnel and ground content, excavate
                                        vm->m_data[vi] = MapNode(CONTENT_AIR);
+                               } else if (open && (c == biome->c_filler || c == biome->c_stone)) {
+                                       // Tunnel entrance floor
+                                       vm->m_data[vi] = MapNode(biome->c_top);
+                                       open = false;
+                               } else {
+                                       open = false;
                                }
                        }
                }
index 6c03c4ca95d59d0d507388c99c423d28ec7966f2..5c0d283ecf7745fee11fcc2cfb3a1ddb3bf936b4 100644 (file)
@@ -674,20 +674,39 @@ void MapgenFractal::dustTopNodes()
 void MapgenFractal::generateCaves(s16 max_stone_y)
 {
        if (max_stone_y >= node_min.Y) {
-               u32 index = 0;
+               v3s16 em = vm->m_area.getExtent();
+               u32 index2d = 0;
+               u32 index3d;
 
                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 vi = vm->m_area.index(node_min.X, y, z);
-                       for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index++) {
-                               float d1 = contour(noise_cave1->result[index]);
-                               float d2 = contour(noise_cave2->result[index]);
-                               if (d1 * d2 > 0.3f) {
-                                       content_t c = vm->m_data[vi].getContent();
-                                       if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
-                                               continue;
-
+               for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
+                       bool open = false;  // Is column open to overground
+                       u32 vi = vm->m_area.index(x, node_max.Y + 1, z);
+                       index3d = (z - node_min.Z) * zstride + (csize.Y + 1) * ystride +
+                               (x - node_min.X);
+                       // Biome of column
+                       Biome *biome = (Biome *)bmgr->getRaw(biomemap[index2d]);
+
+                       for (s16 y = node_max.Y + 1; y >= node_min.Y - 1;
+                                       y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) {
+                               content_t c = vm->m_data[vi].getContent();
+                               if (c == CONTENT_AIR || c == biome->c_water_top ||
+                                               c == biome->c_water) {
+                                       open = true;
+                                       continue;
+                               }
+                               // Ground
+                               float d1 = contour(noise_cave1->result[index3d]);
+                               float d2 = contour(noise_cave2->result[index3d]);
+                               if (d1 * d2 > 0.3f && ndef->get(c).is_ground_content) {
+                                       // In tunnel and ground content, excavate
                                        vm->m_data[vi] = MapNode(CONTENT_AIR);
+                               } else if (open && (c == biome->c_filler || c == biome->c_stone)) {
+                                       // Tunnel entrance floor
+                                       vm->m_data[vi] = MapNode(biome->c_top);
+                                       open = false;
+                               } else {
+                                       open = false;
                                }
                        }
                }
index 50559f9a59122e3804a42785fbf2ff684fa83747..1e4815486d9e2edec41d0e57dc753d80f85f6f00 100644 (file)
@@ -863,20 +863,39 @@ void MapgenV7::addTopNodes()
 void MapgenV7::generateCaves(s16 max_stone_y)
 {
        if (max_stone_y >= node_min.Y) {
-               u32 index   = 0;
+               v3s16 em = vm->m_area.getExtent();
+               u32 index2d = 0;
+               u32 index3d;
 
                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++) {
-                               float d1 = contour(noise_cave1->result[index]);
-                               float d2 = contour(noise_cave2->result[index]);
-                               if (d1 * d2 > 0.3f) {
-                                       content_t c = vm->m_data[i].getContent();
-                                       if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
-                                               continue;
-
-                                       vm->m_data[i] = MapNode(CONTENT_AIR);
+               for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
+                       bool open = false;  // Is column open to overground
+                       u32 vi = vm->m_area.index(x, node_max.Y + 1, z);
+                       index3d = (z - node_min.Z) * zstride + (csize.Y + 1) * ystride +
+                               (x - node_min.X);
+                       // Biome of column
+                       Biome *biome = (Biome *)bmgr->getRaw(biomemap[index2d]);
+
+                       for (s16 y = node_max.Y + 1; y >= node_min.Y - 1;
+                                       y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) {
+                               content_t c = vm->m_data[vi].getContent();
+                               if (c == CONTENT_AIR || c == biome->c_water_top ||
+                                               c == biome->c_water) {
+                                       open = true;
+                                       continue;
+                               }
+                               // Ground
+                               float d1 = contour(noise_cave1->result[index3d]);
+                               float d2 = contour(noise_cave2->result[index3d]);
+                               if (d1 * d2 > 0.3f && ndef->get(c).is_ground_content) {
+                                       // In tunnel and ground content, excavate
+                                       vm->m_data[vi] = MapNode(CONTENT_AIR);
+                               } else if (open && (c == biome->c_filler || c == biome->c_stone)) {
+                                       // Tunnel entrance floor
+                                       vm->m_data[vi] = MapNode(biome->c_top);
+                                       open = false;
+                               } else {
+                                       open = false;
                                }
                        }
                }