Skip to content
Permalink
Browse files

Cavegen/Mgv5/Mgv7: Add optional giant caverns

Add to MapgenBasic for use by multiple mapgens.
Add to mgv5 and mgv7, enabled by default.

Similar to mgvalleys caverns but half the scale.
Parameters for upper y limit, distance caverns taper to full size, and
noise threshold (full cavern size).
As with mgvalleys caverns are generated first and classic caves are
disabled in any mapchunk containing a cavern, to avoid excessive
spreading volumes of liquids.
This also avoids floating blobs of liquid where a large classic cave
has overgenerated out into a neighbouring previously-generated mapchunk.
  • Loading branch information
paramat committed Apr 3, 2017
1 parent 86b1542 commit 859141a0ce38fbd606d95ae7a2f0999acf2fbe84
Showing with 303 additions and 54 deletions.
  1. +23 −0 builtin/settingtypes.txt
  2. +30 −0 minetest.conf.example
  3. +95 −0 src/cavegen.cpp
  4. +30 −0 src/cavegen.h
  5. +12 −0 src/mapgen.cpp
  6. +5 −0 src/mapgen.h
  7. +47 −39 src/mapgen_v5.cpp
  8. +9 −1 src/mapgen_v5.h
  9. +43 −10 src/mapgen_v7.cpp
  10. +9 −4 src/mapgen_v7.h
@@ -940,12 +940,25 @@ mg_biome_np_humidity_blend (Mapgen biome humidity blend noise parameters) noise_
# Controls width of tunnels, a smaller value creates wider tunnels.
mgv5_cave_width (Mapgen v5 cave width) float 0.125

# Y-level of cavern upper limit.
mgv5_cavern_limit (Mapgen v5 cavern limit) int -256

# Y-distance over which caverns expand to full size.
mgv5_cavern_taper (Mapgen v5 cavern taper) int 256

# Defines full size of caverns, smaller values create larger caverns.
mgv5_cavern_threshold (Mapgen v5 cavern threshold) float 0.7

mgv5_np_filler_depth (Mapgen v5 filler depth noise parameters) noise_params 0, 1, (150, 150, 150), 261, 4, 0.7, 2.0
mgv5_np_factor (Mapgen v5 factor noise parameters) noise_params 0, 1, (250, 250, 250), 920381, 3, 0.45, 2.0
mgv5_np_height (Mapgen v5 height noise parameters) noise_params 0, 10, (250, 250, 250), 84174, 4, 0.5, 2.0
mgv5_np_cave1 (Mapgen v5 cave1 noise parameters) noise_params 0, 12, (50, 50, 50), 52534, 4, 0.5, 2.0
mgv5_np_cave2 (Mapgen v5 cave2 noise parameters) noise_params 0, 12, (50, 50, 50), 10325, 4, 0.5, 2.0
mgv5_np_cavern (Mapgen v5 cavern noise parameters) noise_params 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0
# TODO
# Noise parameters in group format, unsupported by advanced settings
# menu but settable in minetest.conf.
# See documentation of noise parameter formats in minetest.conf.example.
#mgv5_np_ground = {
# offset = 0
# scale = 40
@@ -1007,6 +1020,15 @@ mgv7_floatland_level (Mapgen v7 floatland level) int 1280
# Y-level to which floatland shadows extend.
mgv7_shadow_limit (Mapgen v7 shadow limit) int 1024

# Y-level of cavern upper limit.
mgv7_cavern_limit (Mapgen v7 cavern limit) int -256

# Y-distance over which caverns expand to full size.
mgv7_cavern_taper (Mapgen v7 cavern taper) int 256

# Defines full size of caverns, smaller values create larger caverns.
mgv7_cavern_threshold (Mapgen v7 cavern threshold) float 0.7

mgv7_np_terrain_base (Mapgen v7 terrain base noise parameters) noise_params 4, 70, (600, 600, 600), 82341, 5, 0.6, 2.0
mgv7_np_terrain_alt (Mapgen v7 terrain altitude noise parameters) noise_params 4, 25, (600, 600, 600), 5934, 5, 0.6, 2.0
mgv7_np_terrain_persist (Mapgen v7 terrain persistation noise parameters) noise_params 0.6, 0.1, (2000, 2000, 2000), 539, 3, 0.6, 2.0
@@ -1018,6 +1040,7 @@ mgv7_np_floatland_base (Mapgen v7 floatland base terrain noise parameters) noise
mgv7_np_float_base_height (Mapgen v7 floatland base terrain height noise parameters) noise_params 48, 24, (300, 300, 300), 907, 4, 0.7, 2.0
mgv7_np_mountain (Mapgen v7 mountain noise parameters) noise_params -0.6, 1, (250, 350, 250), 5333, 5, 0.63, 2.0
mgv7_np_ridge (Mapgen v7 river channel wall noise parameters) noise_params 0, 1, (100, 100, 100), 6467, 4, 0.75, 2.0
mgv7_np_cavern (Mapgen v7 cavern noise parameters) noise_params 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0
mgv7_np_cave1 (Mapgen v7 cave1 noise parameters) noise_params 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0
mgv7_np_cave2 (Mapgen v7 cave2 noise parameters) noise_params 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0

@@ -1174,6 +1174,18 @@ server_side_occlusion_culling = true
# type: float
# mgv5_cave_width = 0.125

# Y-level of cavern upper limit.
# type: int
# mgv5_cavern_limit = -256

# Y-distance over which caverns expand to full size.
# type: int
# mgv5_cavern_taper = 256

# Defines full size of caverns, smaller values create larger caverns.
# type: float
# mgv5_cavern_threshold = 0.7

# type: noise_params
# mgv5_np_filler_depth = 0, 1, (150, 150, 150), 261, 4, 0.7, 2.0

@@ -1189,6 +1201,9 @@ server_side_occlusion_culling = true
# type: noise_params
# mgv5_np_cave2 = 0, 12, (50, 50, 50), 10325, 4, 0.5, 2.0

# type: noise_params
# mgv5_np_cavern = 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0

# Noise parameters in group format, unsupported by advanced settings
# menu but settable in minetest.conf.
# See documentation of noise parameter formats above.
@@ -1284,6 +1299,18 @@ server_side_occlusion_culling = true
# type: int
# mgv7_shadow_limit = 1024

# Y-level of cavern upper limit.
# type: int
# mgv7_cavern_limit = -256

# Y-distance over which caverns expand to full size.
# type: int
# mgv7_cavern_taper = 256

# Defines full size of caverns, smaller values create larger caverns.
# type: float
# mgv7_cavern_threshold = 0.7

# type: noise_params
# mgv7_np_terrain_base = 4, 70, (600, 600, 600), 82341, 5, 0.6, 2.0

@@ -1317,6 +1344,9 @@ server_side_occlusion_culling = true
# type: noise_params
# mgv7_np_ridge = 0, 1, (100, 100, 100), 6467, 4, 0.75, 2.0

# type: noise_params
# mgv7_np_cavern = 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0

# type: noise_params
# mgv7_np_cave1 = 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0

@@ -150,6 +150,101 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
}


////
//// CavernsNoise
////

CavernsNoise::CavernsNoise(
INodeDefManager *nodedef, v3s16 chunksize, NoiseParams *np_cavern,
s32 seed, float cavern_limit, float cavern_taper, float cavern_threshold)
{
assert(nodedef);

m_ndef = nodedef;

m_csize = chunksize;
m_cavern_limit = cavern_limit;
m_cavern_taper = cavern_taper;
m_cavern_threshold = cavern_threshold;

m_ystride = m_csize.X;
m_zstride_1d = m_csize.X * (m_csize.Y + 1);

// Noise is created using 1-down overgeneration
// A Nx-by-1-by-Nz-sized plane is at the bottom of the desired for
// re-carving the solid overtop placed for blocking sunlight
noise_cavern = new Noise(np_cavern, seed, m_csize.X, m_csize.Y + 1, m_csize.Z);

c_water_source = m_ndef->getId("mapgen_water_source");
if (c_water_source == CONTENT_IGNORE)
c_water_source = CONTENT_AIR;

c_lava_source = m_ndef->getId("mapgen_lava_source");
if (c_lava_source == CONTENT_IGNORE)
c_lava_source = CONTENT_AIR;
}


CavernsNoise::~CavernsNoise()
{
delete noise_cavern;
}


bool CavernsNoise::generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax)
{
assert(vm);

// Calculate noise
noise_cavern->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);

// Cache cavern_amp values
float cavern_amp[m_csize.Y + 1];
u8 cavern_amp_index = 0; // Index zero at column top
for (s16 y = nmax.Y; y >= nmin.Y - 1; y--, cavern_amp_index++) {
cavern_amp[cavern_amp_index] =
MYMIN((m_cavern_limit - y) / (float)m_cavern_taper, 1.0f);
}

//// Place nodes
bool has_cavern = false;
v3s16 em = vm->m_area.getExtent();
u32 index2d = 0;

for (s16 z = nmin.Z; z <= nmax.Z; z++)
for (s16 x = nmin.X; x <= nmax.X; x++, index2d++) {
// Reset cave_amp index to column top
cavern_amp_index = 0;
// Initial voxelmanip index at column top
u32 vi = vm->m_area.index(x, nmax.Y, z);
// Initial 3D noise index at column top
u32 index3d = (z - nmin.Z) * m_zstride_1d + m_csize.Y * m_ystride +
(x - nmin.X);
// Don't excavate the overgenerated stone at node_max.Y + 1,
// this creates a 'roof' over the cavern, preventing light in
// caverns at mapchunk borders when generating mapchunks upwards.
// This 'roof' is excavated when the mapchunk above is generated.
for (s16 y = nmax.Y; y >= nmin.Y - 1; y--,
index3d -= m_ystride,
vm->m_area.add_y(em, vi, -1),
cavern_amp_index++) {
content_t c = vm->m_data[vi].getContent();
float nabs_cavern = fabs(noise_cavern->result[index3d]);
// Caverns generate first but still remove lava and water in case
// of overgenerated classic caves.
if (nabs_cavern * cavern_amp[cavern_amp_index] > m_cavern_threshold &&
(m_ndef->get(c).is_ground_content ||
c == c_lava_source || c == c_water_source)) {
vm->m_data[vi] = MapNode(CONTENT_AIR);
has_cavern = true;
}
}
}

return has_cavern;
}


////
//// CavesRandomWalk
////
@@ -62,6 +62,36 @@ class CavesNoiseIntersection {
Noise *noise_cave2;
};

/*
CavernsNoise is a cave digging algorithm
*/
class CavernsNoise {
public:
CavernsNoise(INodeDefManager *nodedef, v3s16 chunksize, NoiseParams *np_cavern,
s32 seed, float cavern_limit, float cavern_taper, float cavern_threshold);
~CavernsNoise();

bool generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax);

private:
INodeDefManager *m_ndef;

// configurable parameters
v3s16 m_csize;
float m_cavern_limit;
float m_cavern_taper;
float m_cavern_threshold;

// intermediate state variables
u16 m_ystride;
u16 m_zstride_1d;

Noise *noise_cavern;

content_t c_water_source;
content_t c_lava_source;
};

/*
CavesRandomWalk is an implementation of a cave-digging algorithm that
operates on the principle of a "random walk" to approximate the stochiastic
@@ -840,6 +840,18 @@ void MapgenBasic::generateCaves(s16 max_stone_y, s16 large_cave_depth)
}


bool MapgenBasic::generateCaverns(s16 max_stone_y)
{
if (node_min.Y > max_stone_y || node_min.Y > cavern_limit)
return false;

CavernsNoise caverns_noise(ndef, csize, &np_cavern,
seed, cavern_limit, cavern_taper, cavern_threshold);

return caverns_noise.generateCaverns(vm, node_min, node_max);
}


void MapgenBasic::generateDungeons(s16 max_stone_y, MgStoneType stone_type)
{
if (max_stone_y < node_min.Y)
@@ -243,6 +243,7 @@ class MapgenBasic : public Mapgen {
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, MgStoneType stone_type);
virtual MgStoneType generateBiomes();
virtual void dustTopNodes();
@@ -282,7 +283,11 @@ class MapgenBasic : public Mapgen {

NoiseParams np_cave1;
NoiseParams np_cave2;
NoiseParams np_cavern;
float cave_width;
float cavern_limit;
float cavern_taper;
float cavern_threshold;
};

#endif

0 comments on commit 859141a

Please sign in to comment.