//// amount of elements to skip for the next index
//// for noise/height/biome maps (not vmanip)
this->ystride = csize.X;
- this->zstride = csize.X * (csize.Y + 2);
+ // 1-down overgeneration
+ this->zstride_1d = csize.X * (csize.Y + 1);
this->biomemap = new u8[csize.X * csize.Z];
this->heightmap = new s16[csize.X * csize.Z];
noise_filler_depth = new Noise(&sp->np_filler_depth, seed, csize.X, csize.Z);
//// 3D 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);
+ // 1-down overgeneraion
+ noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y + 1, csize.Z);
+ noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y + 1, csize.Z);
//// Biome noise
noise_heat = new Noise(¶ms->np_biome_heat, seed, csize.X, csize.Z);
/////////////////////////////////////////////////////////////////
-int MapgenFlat::getGroundLevelAtPoint(v2s16 p)
+int MapgenFlat::getSpawnLevelAtPoint(v2s16 p)
{
+ s16 level_at_point = ground_level;
float n_terrain = NoisePerlin2D(&noise_terrain->np, p.X, p.Y, seed);
+
if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) {
- s16 depress = (lake_threshold - n_terrain) * lake_steepness;
- return ground_level - depress;
+ level_at_point = ground_level -
+ (lake_threshold - n_terrain) * lake_steepness;
} else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) {
- s16 rise = (n_terrain - hill_threshold) * hill_steepness;
- return ground_level + rise;
- } else {
- return ground_level;
+ level_at_point = ground_level +
+ (n_terrain - hill_threshold) * hill_steepness;
}
+
+ if (ground_level < water_level) // Ocean world, allow spawn in water
+ return MYMAX(level_at_point, water_level);
+ else if (level_at_point > water_level)
+ return level_at_point; // Spawn on land
+ else
+ return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
}
void MapgenFlat::calculateNoise()
{
//TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
- int x = node_min.X;
- int y = node_min.Y - 1;
- int z = node_min.Z;
+ s16 x = node_min.X;
+ s16 z = node_min.Z;
if ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS))
noise_terrain->perlinMap2D(x, z);
- noise_filler_depth->perlinMap2D(x, z);
-
- if (flags & MG_CAVES) {
- noise_cave1->perlinMap3D(x, y, z);
- noise_cave2->perlinMap3D(x, y, z);
- }
+ // Cave noises are calculated in generateCaves()
+ // only if solid terrain is present in mapchunk
+ noise_filler_depth->perlinMap2D(x, z);
noise_heat->perlinMap2D(x, z);
noise_humidity->perlinMap2D(x, z);
noise_heat_blend->perlinMap2D(x, z);
void MapgenFlat::generateCaves(s16 max_stone_y)
{
- if (max_stone_y >= node_min.Y) {
- u32 index = 0;
+ if (max_stone_y < node_min.Y)
+ return;
- 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;
-
- vm->m_data[vi] = MapNode(CONTENT_AIR);
- }
+ noise_cave1->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
+ noise_cave2->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
+
+ v3s16 em = vm->m_area.getExtent();
+ u32 index2d = 0;
+
+ for (s16 z = node_min.Z; z <= node_max.Z; z++)
+ for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
+ bool column_is_open = false; // Is column open to overground
+ bool is_tunnel = false; // Is tunnel or tunnel floor
+ u32 vi = vm->m_area.index(x, node_max.Y, z);
+ u32 index3d = (z - node_min.Z) * zstride_1d + csize.Y * ystride +
+ (x - node_min.X);
+ // Biome of column
+ Biome *biome = (Biome *)bmgr->getRaw(biomemap[index2d]);
+
+ // 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.
+ // This 'roof' is removed when the mapchunk above is generated.
+ for (s16 y = node_max.Y; 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) {
+ column_is_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);
+ is_tunnel = true;
+ } else if (is_tunnel && column_is_open &&
+ (c == biome->c_filler || c == biome->c_stone)) {
+ // Tunnel entrance floor
+ vm->m_data[vi] = MapNode(biome->c_top);
+ column_is_open = false;
+ is_tunnel = false;
+ } else {
+ column_is_open = false;
+ is_tunnel = false;
}
}
}