From bb2ee54d3b841ebdb6c6a0b6573b64216ae0baae Mon Sep 17 00:00:00 2001 From: paramat Date: Sun, 13 Mar 2016 07:56:27 +0000 Subject: [PATCH] Mapgen: Fix light in tunnels at mapchunk borders Don't excavate the overgenerated stone at node_max.Y + 1, this creates a 'roof' over the tunnel, preventing light in tunnels at mapchunk borders when generating mapchunks upwards. --- src/mapgen_flat.cpp | 6 ++++++ src/mapgen_fractal.cpp | 6 ++++++ src/mapgen_v5.cpp | 6 ++++++ src/mapgen_v7.cpp | 6 ++++++ src/mapgen_valleys.cpp | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/src/mapgen_flat.cpp b/src/mapgen_flat.cpp index 0d071411..d654a772 100644 --- a/src/mapgen_flat.cpp +++ b/src/mapgen_flat.cpp @@ -573,6 +573,12 @@ void MapgenFlat::generateCaves(s16 max_stone_y) for (s16 y = node_max.Y + 1; y >= node_min.Y - 1; y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) { + // Don't excavate the overgenerated stone at node_max.Y + 1, + // this creates a 'roof' over the tunnel, preventing light in + // tunnels at mapchunk borders when generating mapchunks upwards. + if (y > node_max.Y) + continue; + content_t c = vm->m_data[vi].getContent(); if (c == CONTENT_AIR || c == biome->c_water_top || c == biome->c_water) { diff --git a/src/mapgen_fractal.cpp b/src/mapgen_fractal.cpp index 8a5c1e2b..cdea9c09 100644 --- a/src/mapgen_fractal.cpp +++ b/src/mapgen_fractal.cpp @@ -701,6 +701,12 @@ void MapgenFractal::generateCaves(s16 max_stone_y) for (s16 y = node_max.Y + 1; y >= node_min.Y - 1; y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) { + // Don't excavate the overgenerated stone at node_max.Y + 1, + // this creates a 'roof' over the tunnel, preventing light in + // tunnels at mapchunk borders when generating mapchunks upwards. + if (y > node_max.Y) + continue; + content_t c = vm->m_data[vi].getContent(); if (c == CONTENT_AIR || c == biome->c_water_top || c == biome->c_water) { diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index 0bb3715a..e9b1b58b 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -519,6 +519,12 @@ void MapgenV5::generateCaves(int max_stone_y) 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++) { + // Don't excavate the overgenerated stone at node_max.Y + 1, + // this creates a 'roof' over the tunnel, preventing light in + // tunnels at mapchunk borders when generating mapchunks upwards. + if (y > node_max.Y) + continue; + float d1 = contour(noise_cave1->result[index]); float d2 = contour(noise_cave2->result[index]); if (d1 * d2 > 0.125f) { diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index 029f56a4..24867623 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -883,6 +883,12 @@ void MapgenV7::generateCaves(s16 max_stone_y) for (s16 y = node_max.Y + 1; y >= node_min.Y - 1; y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) { + // Don't excavate the overgenerated stone at node_max.Y + 1, + // this creates a 'roof' over the tunnel, preventing light in + // tunnels at mapchunk borders when generating mapchunks upwards. + if (y > node_max.Y) + continue; + content_t c = vm->m_data[vi].getContent(); if (c == CONTENT_AIR || c == biome->c_water_top || c == biome->c_water) { diff --git a/src/mapgen_valleys.cpp b/src/mapgen_valleys.cpp index d6fcde5f..34a316ab 100644 --- a/src/mapgen_valleys.cpp +++ b/src/mapgen_valleys.cpp @@ -931,6 +931,12 @@ void MapgenValleys::generateCaves(s16 max_stone_y) for (s16 y = node_max.Y + 1; y >= node_min.Y - 1; y--, index_3d -= ystride, vm->m_area.add_y(em, index_data, -1)) { + // Don't excavate the overgenerated stone at node_max.Y + 1, + // this creates a 'roof' over the tunnel, preventing light in + // tunnels at mapchunk borders when generating mapchunks upwards. + if (y > node_max.Y) + continue; + float terrain = noise_terrain_height->result[index_2d]; // Saves some time.