From: Paramat Date: Sun, 29 Apr 2018 06:20:46 +0000 (+0100) Subject: Mapgen caves: Re-order generation to fix cavern bug X-Git-Tag: 5.0.0~427 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=54606e103d5b2d2bace6d57c45e48804c5dec487;p=oweals%2Fminetest.git Mapgen caves: Re-order generation to fix cavern bug Previously, caverns confused tunnel generation causing biome top and filler nodes to appear in caverns. Split 'generateCaves()' into 2 functions to separate tunnel and large randomwalk cave generation. In each mapgen re-order cave generation to generate tunnels before caverns. --- diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 9aaead79d..eb562e769 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -824,21 +824,26 @@ void MapgenBasic::dustTopNodes() } -void MapgenBasic::generateCaves(s16 max_stone_y, s16 large_cave_depth) +void MapgenBasic::generateCavesNoiseIntersection(s16 max_stone_y) { - if (max_stone_y < node_min.Y) + if (node_min.Y > max_stone_y) return; CavesNoiseIntersection caves_noise(ndef, m_bmgr, csize, &np_cave1, &np_cave2, seed, cave_width); caves_noise.generateCaves(vm, node_min, node_max, biomemap); +} + - if (node_max.Y > large_cave_depth) +void MapgenBasic::generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_depth) +{ + if (node_min.Y > max_stone_y || node_max.Y > large_cave_depth) return; PseudoRandom ps(blockseed + 21343); u32 bruises_count = ps.range(0, 2); + for (u32 i = 0; i < bruises_count; i++) { CavesRandomWalk cave(ndef, &gennotify, seed, water_level, c_water_source, c_lava_source, lava_depth, biomegen); @@ -849,7 +854,7 @@ void MapgenBasic::generateCaves(s16 max_stone_y, s16 large_cave_depth) } -bool MapgenBasic::generateCaverns(s16 max_stone_y) +bool MapgenBasic::generateCavernsNoise(s16 max_stone_y) { if (node_min.Y > max_stone_y || node_min.Y > cavern_limit) return false; diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h index 51d23cd28..abac79016 100644 --- a/src/mapgen/mapgen.h +++ b/src/mapgen/mapgen.h @@ -238,11 +238,12 @@ public: MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge); virtual ~MapgenBasic(); - virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth); - virtual bool generateCaverns(s16 max_stone_y); - virtual void generateDungeons(s16 max_stone_y); virtual void generateBiomes(); virtual void dustTopNodes(); + virtual void generateCavesNoiseIntersection(s16 max_stone_y); + virtual void generateCavesRandomWalk(s16 max_stone_y, s16 large_cave_depth); + virtual bool generateCavernsNoise(s16 max_stone_y); + virtual void generateDungeons(s16 max_stone_y); protected: EmergeManager *m_emerge; diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp index 37c769693..4347f8479 100644 --- a/src/mapgen/mapgen_carpathian.cpp +++ b/src/mapgen/mapgen_carpathian.cpp @@ -250,20 +250,25 @@ void MapgenCarpathian::makeChunk(BlockMakeData *data) biomegen->calcBiomeNoise(node_min); generateBiomes(); - // Generate caverns, tunnels and classic caves + // Generate tunnels, caverns and large randomwalk caves if (flags & MG_CAVES) { - bool has_cavern = false; + // Generate tunnels first as caverns confuse them + generateCavesNoiseIntersection(stone_surface_max_y); + // Generate caverns + bool near_cavern = false; if (spflags & MGCARPATHIAN_CAVERNS) - has_cavern = generateCaverns(stone_surface_max_y); - // Generate tunnels and classic caves - if (has_cavern) - // Disable classic caves in this mapchunk by setting + near_cavern = generateCavernsNoise(stone_surface_max_y); + + // Generate large randomwalk caves + if (near_cavern) + // Disable large randomwalk caves in this mapchunk by setting // 'large cave depth' to world base. Avoids excessive liquid in // large caverns and floating blobs of overgenerated liquid. - generateCaves(stone_surface_max_y, -MAX_MAP_GENERATION_LIMIT); + generateCavesRandomWalk(stone_surface_max_y, + -MAX_MAP_GENERATION_LIMIT); else - generateCaves(stone_surface_max_y, large_cave_depth); + generateCavesRandomWalk(stone_surface_max_y, large_cave_depth); } // Generate dungeons diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index 60b30137b..dbe0bd5bb 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -198,8 +198,12 @@ void MapgenFlat::makeChunk(BlockMakeData *data) biomegen->calcBiomeNoise(node_min); generateBiomes(); - if (flags & MG_CAVES) - generateCaves(stone_surface_max_y, large_cave_depth); + if (flags & MG_CAVES) { + // Generate tunnels + generateCavesNoiseIntersection(stone_surface_max_y); + // Generate large randomwalk caves + generateCavesRandomWalk(stone_surface_max_y, large_cave_depth); + } if ((flags & MG_DUNGEONS) && full_node_min.Y >= dungeon_ymin && full_node_max.Y <= dungeon_ymax) diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index 10397f7b8..a1d425cd0 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -209,8 +209,12 @@ void MapgenFractal::makeChunk(BlockMakeData *data) biomegen->calcBiomeNoise(node_min); generateBiomes(); - if (flags & MG_CAVES) - generateCaves(stone_surface_max_y, large_cave_depth); + if (flags & MG_CAVES) { + // Generate tunnels + generateCavesNoiseIntersection(stone_surface_max_y); + // Generate large randomwalk caves + generateCavesRandomWalk(stone_surface_max_y, large_cave_depth); + } if ((flags & MG_DUNGEONS) && full_node_min.Y >= dungeon_ymin && full_node_max.Y <= dungeon_ymax) diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp index aabc86c4d..fc0970363 100644 --- a/src/mapgen/mapgen_v5.cpp +++ b/src/mapgen/mapgen_v5.cpp @@ -209,20 +209,25 @@ void MapgenV5::makeChunk(BlockMakeData *data) biomegen->calcBiomeNoise(node_min); generateBiomes(); - // Generate caverns, tunnels and classic caves + // Generate tunnels, caverns and large randomwalk caves if (flags & MG_CAVES) { - bool near_cavern = false; + // Generate tunnels first as caverns confuse them + generateCavesNoiseIntersection(stone_surface_max_y); + // Generate caverns + bool near_cavern = false; if (spflags & MGV5_CAVERNS) - near_cavern = generateCaverns(stone_surface_max_y); - // Generate tunnels and classic caves + near_cavern = generateCavernsNoise(stone_surface_max_y); + + // Generate large randomwalk caves if (near_cavern) - // Disable classic caves in this mapchunk by setting + // Disable large randomwalk caves in this mapchunk by setting // 'large cave depth' to world base. Avoids excessive liquid in // large caverns and floating blobs of overgenerated liquid. - generateCaves(stone_surface_max_y, -MAX_MAP_GENERATION_LIMIT); + generateCavesRandomWalk(stone_surface_max_y, + -MAX_MAP_GENERATION_LIMIT); else - generateCaves(stone_surface_max_y, large_cave_depth); + generateCavesRandomWalk(stone_surface_max_y, large_cave_depth); } // Generate dungeons and desert temples diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index c83a5105d..23e8dbdd2 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -313,20 +313,25 @@ void MapgenV7::makeChunk(BlockMakeData *data) biomegen->calcBiomeNoise(node_min); generateBiomes(); - // Generate caverns, tunnels and classic caves + // Generate tunnels, caverns and large randomwalk caves if (flags & MG_CAVES) { - bool near_cavern = false; + // Generate tunnels first as caverns confuse them + generateCavesNoiseIntersection(stone_surface_max_y); + // Generate caverns + bool near_cavern = false; if (spflags & MGV7_CAVERNS) - near_cavern = generateCaverns(stone_surface_max_y); - // Generate tunnels and classic caves + near_cavern = generateCavernsNoise(stone_surface_max_y); + + // Generate large randomwalk caves if (near_cavern) - // Disable classic caves in this mapchunk by setting + // Disable large randomwalk caves in this mapchunk by setting // 'large cave depth' to world base. Avoids excessive liquid in // large caverns and floating blobs of overgenerated liquid. - generateCaves(stone_surface_max_y, -MAX_MAP_GENERATION_LIMIT); + generateCavesRandomWalk(stone_surface_max_y, + -MAX_MAP_GENERATION_LIMIT); else - generateCaves(stone_surface_max_y, large_cave_depth); + generateCavesRandomWalk(stone_surface_max_y, large_cave_depth); } // Generate dungeons diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index 72f478803..843acb690 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -233,18 +233,23 @@ void MapgenValleys::makeChunk(BlockMakeData *data) // Place biome-specific nodes and build biomemap generateBiomes(); - // Generate caverns, tunnels and classic caves + // Generate tunnels, caverns and large randomwalk caves if (flags & MG_CAVES) { + // Generate tunnels first as caverns confuse them + generateCavesNoiseIntersection(stone_surface_max_y); + // Generate caverns - bool near_cavern = generateCaverns(stone_surface_max_y); - // Generate tunnels and classic caves + bool near_cavern = generateCavernsNoise(stone_surface_max_y); + + // Generate large randomwalk caves if (near_cavern) - // Disable classic caves in this mapchunk by setting + // Disable large randomwalk caves in this mapchunk by setting // 'large cave depth' to world base. Avoids excessive liquid in // large caverns and floating blobs of overgenerated liquid. - generateCaves(stone_surface_max_y, -MAX_MAP_GENERATION_LIMIT); + generateCavesRandomWalk(stone_surface_max_y, + -MAX_MAP_GENERATION_LIMIT); else - generateCaves(stone_surface_max_y, large_cave_depth); + generateCavesRandomWalk(stone_surface_max_y, large_cave_depth); } // Dungeon creation