/*
Minetest
-Copyright (C) 2015-2017 paramat
-Copyright (C) 2015-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2015-2019 paramat
+Copyright (C) 2015-2016 kwolekr, Ryan Kwolek
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
#include "mapgen.h"
+#include <cmath>
#include "voxel.h"
#include "noise.h"
#include "mapblock.h"
FlagDesc flagdesc_mapgen_fractal[] = {
- {NULL, 0}
+ {"terrain", MGFRACTAL_TERRAIN},
+ {NULL, 0}
};
///////////////////////////////////////////////////////////////////////////////////////
-MapgenFractal::MapgenFractal(int mapgenid, MapgenFractalParams *params, EmergeManager *emerge)
- : MapgenBasic(mapgenid, params, emerge)
+MapgenFractal::MapgenFractal(MapgenFractalParams *params, EmergeManager *emerge)
+ : MapgenBasic(MAPGEN_FRACTAL, params, emerge)
{
spflags = params->spflags;
cave_width = params->cave_width;
large_cave_depth = params->large_cave_depth;
lava_depth = params->lava_depth;
+ dungeon_ymin = params->dungeon_ymin;
+ dungeon_ymax = params->dungeon_ymax;
fractal = params->fractal;
iterations = params->iterations;
scale = params->scale;
julia_z = params->julia_z;
julia_w = params->julia_w;
- //// 2D terrain noise
- noise_seabed = new Noise(¶ms->np_seabed, seed, csize.X, csize.Z);
+ //// 2D noise
+ if (spflags & MGFRACTAL_TERRAIN)
+ noise_seabed = new Noise(¶ms->np_seabed, seed, csize.X, csize.Z);
+
noise_filler_depth = new Noise(¶ms->np_filler_depth, seed, csize.X, csize.Z);
- MapgenBasic::np_cave1 = params->np_cave1;
- MapgenBasic::np_cave2 = params->np_cave2;
+ //// 3D noise
+ MapgenBasic::np_dungeons = params->np_dungeons;
+ // Overgeneration to node_min.Y - 1
+ MapgenBasic::np_cave1 = params->np_cave1;
+ MapgenBasic::np_cave2 = params->np_cave2;
formula = fractal / 2 + fractal % 2;
julia = fractal % 2 == 0;
MapgenFractal::~MapgenFractal()
{
- delete noise_seabed;
+ if (noise_seabed)
+ delete noise_seabed;
+
delete noise_filler_depth;
}
np_seabed (-14, 9, v3f(600, 600, 600), 41900, 5, 0.6, 2.0),
np_filler_depth (0, 1.2, v3f(150, 150, 150), 261, 3, 0.7, 2.0),
np_cave1 (0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0),
- np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0)
+ np_cave2 (0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0),
+ np_dungeons (0.9, 0.5, v3f(500, 500, 500), 0, 2, 0.8, 2.0)
{
}
settings->getFloatNoEx("mgfractal_cave_width", cave_width);
settings->getS16NoEx("mgfractal_large_cave_depth", large_cave_depth);
settings->getS16NoEx("mgfractal_lava_depth", lava_depth);
+ settings->getS16NoEx("mgfractal_dungeon_ymin", dungeon_ymin);
+ settings->getS16NoEx("mgfractal_dungeon_ymax", dungeon_ymax);
settings->getU16NoEx("mgfractal_fractal", fractal);
settings->getU16NoEx("mgfractal_iterations", iterations);
settings->getV3FNoEx("mgfractal_scale", scale);
settings->getNoiseParams("mgfractal_np_filler_depth", np_filler_depth);
settings->getNoiseParams("mgfractal_np_cave1", np_cave1);
settings->getNoiseParams("mgfractal_np_cave2", np_cave2);
+ settings->getNoiseParams("mgfractal_np_dungeons", np_dungeons);
}
settings->setFloat("mgfractal_cave_width", cave_width);
settings->setS16("mgfractal_large_cave_depth", large_cave_depth);
settings->setS16("mgfractal_lava_depth", lava_depth);
+ settings->setS16("mgfractal_dungeon_ymin", dungeon_ymin);
+ settings->setS16("mgfractal_dungeon_ymax", dungeon_ymax);
settings->setU16("mgfractal_fractal", fractal);
settings->setU16("mgfractal_iterations", iterations);
settings->setV3F("mgfractal_scale", scale);
settings->setNoiseParams("mgfractal_np_filler_depth", np_filler_depth);
settings->setNoiseParams("mgfractal_np_cave1", np_cave1);
settings->setNoiseParams("mgfractal_np_cave2", np_cave2);
+ settings->setNoiseParams("mgfractal_np_dungeons", np_dungeons);
}
int MapgenFractal::getSpawnLevelAtPoint(v2s16 p)
{
- bool solid_below = false; // Dry solid node is present below to spawn on
- u8 air_count = 0; // Consecutive air nodes above the dry solid node
- s16 seabed_level = NoisePerlin2D(&noise_seabed->np, p.X, p.Y, seed);
- // Seabed can rise above water_level or might be raised to create dry land
- s16 search_start = MYMAX(seabed_level, water_level + 1);
- if (seabed_level > water_level)
- solid_below = true;
-
- for (s16 y = search_start; y <= search_start + 128; y++) {
- if (getFractalAtPoint(p.X, y, p.Y)) { // Fractal node
+ bool solid_below = false; // Fractal node is present below to spawn on
+ u8 air_count = 0; // Consecutive air nodes above a fractal node
+ s16 search_start = 0; // No terrain search start
+
+ // If terrain present, don't start search below terrain or water level
+ if (noise_seabed) {
+ s16 seabed_level = NoisePerlin2D(&noise_seabed->np, p.X, p.Y, seed);
+ search_start = MYMAX(search_start, MYMAX(seabed_level, water_level));
+ }
+
+ for (s16 y = search_start; y <= search_start + 4096; y++) {
+ if (getFractalAtPoint(p.X, y, p.Y)) {
+ // Fractal node
solid_below = true;
air_count = 0;
- } else if (solid_below) { // Air above solid node
+ } else if (solid_below) {
+ // Air above fractal node
air_count++;
- // 3 to account for snowblock dust
+ // 3 and -2 to account for biome dust nodes
if (air_count == 3)
return y - 2;
}
data->blockpos_requested.Y <= data->blockpos_max.Y &&
data->blockpos_requested.Z <= data->blockpos_max.Z);
+ //TimeTaker t("makeChunk");
+
this->generating = true;
- this->vm = data->vmanip;
+ this->vm = data->vmanip;
this->ndef = data->nodedef;
- //TimeTaker t("makeChunk");
v3s16 blockpos_min = data->blockpos_min;
v3s16 blockpos_max = data->blockpos_max;
blockseed = getBlockSeed2(full_node_min, seed);
- // Generate base terrain, mountains, and ridges with initial heightmaps
+ // Generate fractal and optional terrain
s16 stone_surface_max_y = generateTerrain();
// Create heightmap
updateHeightmap(node_min, node_max);
// Init biome generator, place biome-specific nodes, and build biomemap
- biomegen->calcBiomeNoise(node_min);
+ if (flags & MG_BIOMES) {
+ biomegen->calcBiomeNoise(node_min);
+ generateBiomes();
+ }
- MgStoneType mgstone_type;
- content_t biome_stone;
- generateBiomes(&mgstone_type, &biome_stone);
+ // Generate tunnels and randomwalk caves
+ if (flags & MG_CAVES) {
+ generateCavesNoiseIntersection(stone_surface_max_y);
+ generateCavesRandomWalk(stone_surface_max_y, large_cave_depth);
+ }
- if (flags & MG_CAVES)
- generateCaves(stone_surface_max_y, large_cave_depth);
+ // Generate the registered ores
+ m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
- if (flags & MG_DUNGEONS)
- generateDungeons(stone_surface_max_y, mgstone_type, biome_stone);
+ // Generate dungeons
+ if ((flags & MG_DUNGEONS) && full_node_min.Y >= dungeon_ymin &&
+ full_node_max.Y <= dungeon_ymax)
+ generateDungeons(stone_surface_max_y);
// Generate the registered decorations
if (flags & MG_DECORATIONS)
m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
- // Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
-
// Sprinkle some dust on top after everything else was generated
- dustTopNodes();
-
- //printf("makeChunk: %dms\n", t.stop());
+ if (flags & MG_BIOMES)
+ dustTopNodes();
- updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
+ // Update liquids
+ if (spflags & MGFRACTAL_TERRAIN)
+ updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
+ // Calculate lighting
if (flags & MG_LIGHT)
calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
full_node_min, full_node_max);
- //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
- // node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
-
this->generating = false;
+
+ //printf("makeChunk: %lums\n", t.stop());
}
break;
case 6: // 3D "Christmas Tree"
// Altering the formula here is necessary to avoid division by zero
- if (fabs(oz) < 0.000000001f) {
+ if (std::fabs(oz) < 0.000000001f) {
nx = ox * ox - oy * oy - oz * oz + cx;
ny = 2.0f * oy * ox + cy;
nz = 4.0f * oz * ox + cz;
} else {
- float a = (2.0f * ox) / (sqrt(oy * oy + oz * oz));
+ float a = (2.0f * ox) / (std::sqrt(oy * oy + oz * oz));
nx = ox * ox - oy * oy - oz * oz + cx;
ny = a * (oy * oy - oz * oz) + cy;
nz = a * 2.0f * oy * oz + cz;
}
break;
case 7: // 3D "Mandelbulb"
- if (fabs(oy) < 0.000000001f) {
+ if (std::fabs(oy) < 0.000000001f) {
nx = ox * ox - oz * oz + cx;
ny = cy;
- nz = -2.0f * oz * sqrt(ox * ox) + cz;
+ nz = -2.0f * oz * std::sqrt(ox * ox) + cz;
} else {
float a = 1.0f - (oz * oz) / (ox * ox + oy * oy);
nx = (ox * ox - oy * oy) * a + cx;
ny = 2.0f * ox * oy * a + cy;
- nz = -2.0f * oz * sqrt(ox * ox + oy * oy) + cz;
+ nz = -2.0f * oz * std::sqrt(ox * ox + oy * oy) + cz;
}
break;
case 8: // 3D "Cosine Mandelbulb"
- if (fabs(oy) < 0.000000001f) {
+ if (std::fabs(oy) < 0.000000001f) {
nx = 2.0f * ox * oz + cx;
ny = 4.0f * oy * oz + cy;
nz = oz * oz - ox * ox - oy * oy + cz;
} else {
- float a = (2.0f * oz) / sqrt(ox * ox + oy * oy);
+ float a = (2.0f * oz) / std::sqrt(ox * ox + oy * oy);
nx = (ox * ox - oy * oy) * a + cx;
ny = 2.0f * ox * oy * a + cy;
nz = oz * oz - ox * ox - oy * oy + cz;
}
break;
case 9: // 4D "Mandelbulb"
- float rxy = sqrt(ox * ox + oy * oy);
- float rxyz = sqrt(ox * ox + oy * oy + oz * oz);
- if (fabs(ow) < 0.000000001f && fabs(oz) < 0.000000001f) {
+ float rxy = std::sqrt(ox * ox + oy * oy);
+ float rxyz = std::sqrt(ox * ox + oy * oy + oz * oz);
+ if (std::fabs(ow) < 0.000000001f && std::fabs(oz) < 0.000000001f) {
nx = (ox * ox - oy * oy) + cx;
ny = 2.0f * ox * oy + cy;
nz = -2.0f * rxy * oz + cz;
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
u32 index2d = 0;
- noise_seabed->perlinMap2D(node_min.X, node_min.Z);
+ if (noise_seabed)
+ noise_seabed->perlinMap2D(node_min.X, node_min.Z);
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++, index2d++) {
- if (vm->m_data[vi].getContent() == CONTENT_IGNORE) {
- s16 seabed_height = noise_seabed->result[index2d];
-
- if (y <= seabed_height || getFractalAtPoint(x, y, z)) {
- vm->m_data[vi] = n_stone;
- if (y > stone_surface_max_y)
- stone_surface_max_y = y;
- } else if (y <= water_level) {
- vm->m_data[vi] = n_water;
- } else {
- vm->m_data[vi] = n_air;
- }
+ if (vm->m_data[vi].getContent() != CONTENT_IGNORE)
+ continue;
+
+ s16 seabed_height = -MAX_MAP_GENERATION_LIMIT;
+ if (noise_seabed)
+ seabed_height = noise_seabed->result[index2d];
+
+ if (((spflags & MGFRACTAL_TERRAIN) && y <= seabed_height) ||
+ getFractalAtPoint(x, y, z)) {
+ vm->m_data[vi] = n_stone;
+ if (y > stone_surface_max_y)
+ stone_surface_max_y = y;
+ } else if ((spflags & MGFRACTAL_TERRAIN) && y <= water_level) {
+ vm->m_data[vi] = n_water;
+ } else {
+ vm->m_data[vi] = n_air;
}
}
index2d -= ystride;