Mgfractal: Make non-fractal terrain optional (#8702)

Enabled by default.
Only allow spawn on fractal, not on seabed terrain.
Various codestyle and comment improvements.
This commit is contained in:
Paramat 2019-07-25 19:58:35 +01:00 committed by GitHub
parent ecd20de64d
commit 245a31d6b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 46 deletions

@ -1732,6 +1732,11 @@ mgflat_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 500), 0,
[*Mapgen Fractal] [*Mapgen Fractal]
# Map generation attributes specific to Mapgen flat.
# 'terrain' enables the generation of non-fractal terrain:
# ocean, islands and underground.
mgfractal_spflags (Mapgen Fractal specific flags) flags terrain terrain,noterrain
# Controls width of tunnels, a smaller value creates wider tunnels. # Controls width of tunnels, a smaller value creates wider tunnels.
mgfractal_cave_width (Cave width) float 0.09 mgfractal_cave_width (Cave width) float 0.09

@ -1,7 +1,7 @@
/* /*
Minetest Minetest
Copyright (C) 2015-2018 paramat Copyright (C) 2015-2019 paramat
Copyright (C) 2015-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net> Copyright (C) 2015-2016 kwolekr, Ryan Kwolek
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU Lesser General Public License as published by
@ -41,7 +41,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
FlagDesc flagdesc_mapgen_fractal[] = { FlagDesc flagdesc_mapgen_fractal[] = {
{NULL, 0} {"terrain", MGFRACTAL_TERRAIN},
{NULL, 0}
}; };
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
@ -66,13 +67,17 @@ MapgenFractal::MapgenFractal(MapgenFractalParams *params, EmergeManager *emerge)
julia_z = params->julia_z; julia_z = params->julia_z;
julia_w = params->julia_w; julia_w = params->julia_w;
//// 2D terrain noise //// 2D noise
noise_seabed = new Noise(&params->np_seabed, seed, csize.X, csize.Z); if (spflags & MGFRACTAL_TERRAIN)
noise_seabed = new Noise(&params->np_seabed, seed, csize.X, csize.Z);
noise_filler_depth = new Noise(&params->np_filler_depth, seed, csize.X, csize.Z); noise_filler_depth = new Noise(&params->np_filler_depth, seed, csize.X, csize.Z);
//// 3D noise
MapgenBasic::np_dungeons = params->np_dungeons;
// Overgeneration to node_min.Y - 1
MapgenBasic::np_cave1 = params->np_cave1; MapgenBasic::np_cave1 = params->np_cave1;
MapgenBasic::np_cave2 = params->np_cave2; MapgenBasic::np_cave2 = params->np_cave2;
MapgenBasic::np_dungeons = params->np_dungeons;
formula = fractal / 2 + fractal % 2; formula = fractal / 2 + fractal % 2;
julia = fractal % 2 == 0; julia = fractal % 2 == 0;
@ -81,7 +86,9 @@ MapgenFractal::MapgenFractal(MapgenFractalParams *params, EmergeManager *emerge)
MapgenFractal::~MapgenFractal() MapgenFractal::~MapgenFractal()
{ {
delete noise_seabed; if (noise_seabed)
delete noise_seabed;
delete noise_filler_depth; delete noise_filler_depth;
} }
@ -153,21 +160,25 @@ void MapgenFractalParams::writeParams(Settings *settings) const
int MapgenFractal::getSpawnLevelAtPoint(v2s16 p) int MapgenFractal::getSpawnLevelAtPoint(v2s16 p)
{ {
bool solid_below = false; // Dry solid node is present below to spawn on bool solid_below = false; // Fractal node is present below to spawn on
u8 air_count = 0; // Consecutive air nodes above the dry solid node u8 air_count = 0; // Consecutive air nodes above a fractal node
s16 seabed_level = NoisePerlin2D(&noise_seabed->np, p.X, p.Y, seed); s16 search_start = 0; // No terrain search start
// 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 terrain present, don't start search below terrain or water level
if (getFractalAtPoint(p.X, y, p.Y)) { // Fractal node 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; solid_below = true;
air_count = 0; air_count = 0;
} else if (solid_below) { // Air above solid node } else if (solid_below) {
// Air above fractal node
air_count++; air_count++;
// 3 to account for snowblock dust // 3 and -2 to account for biome dust nodes
if (air_count == 3) if (air_count == 3)
return y - 2; return y - 2;
} }
@ -189,11 +200,12 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
data->blockpos_requested.Y <= data->blockpos_max.Y && data->blockpos_requested.Y <= data->blockpos_max.Y &&
data->blockpos_requested.Z <= data->blockpos_max.Z); data->blockpos_requested.Z <= data->blockpos_max.Z);
this->generating = true;
this->vm = data->vmanip;
this->ndef = data->nodedef;
//TimeTaker t("makeChunk"); //TimeTaker t("makeChunk");
this->generating = true;
this->vm = data->vmanip;
this->ndef = data->nodedef;
v3s16 blockpos_min = data->blockpos_min; v3s16 blockpos_min = data->blockpos_min;
v3s16 blockpos_max = data->blockpos_max; v3s16 blockpos_max = data->blockpos_max;
node_min = blockpos_min * MAP_BLOCKSIZE; node_min = blockpos_min * MAP_BLOCKSIZE;
@ -203,7 +215,7 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
blockseed = getBlockSeed2(full_node_min, seed); 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(); s16 stone_surface_max_y = generateTerrain();
// Create heightmap // Create heightmap
@ -215,16 +227,16 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
generateBiomes(); generateBiomes();
} }
// Generate tunnels and randomwalk caves
if (flags & MG_CAVES) { if (flags & MG_CAVES) {
// Generate tunnels
generateCavesNoiseIntersection(stone_surface_max_y); generateCavesNoiseIntersection(stone_surface_max_y);
// Generate large randomwalk caves
generateCavesRandomWalk(stone_surface_max_y, large_cave_depth); generateCavesRandomWalk(stone_surface_max_y, large_cave_depth);
} }
// Generate the registered ores // Generate the registered ores
m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max); m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
// Generate dungeons
if ((flags & MG_DUNGEONS) && full_node_min.Y >= dungeon_ymin && if ((flags & MG_DUNGEONS) && full_node_min.Y >= dungeon_ymin &&
full_node_max.Y <= dungeon_ymax) full_node_max.Y <= dungeon_ymax)
generateDungeons(stone_surface_max_y); generateDungeons(stone_surface_max_y);
@ -237,18 +249,18 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
if (flags & MG_BIOMES) if (flags & MG_BIOMES)
dustTopNodes(); dustTopNodes();
//printf("makeChunk: %dms\n", t.stop()); // Update liquids
if (spflags & MGFRACTAL_TERRAIN)
updateLiquid(&data->transforming_liquid, full_node_min, full_node_max); updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
// Calculate lighting
if (flags & MG_LIGHT) if (flags & MG_LIGHT)
calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
full_node_min, full_node_max); 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; this->generating = false;
//printf("makeChunk: %lums\n", t.stop());
} }
@ -391,24 +403,29 @@ s16 MapgenFractal::generateTerrain()
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
u32 index2d = 0; 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 z = node_min.Z; z <= node_max.Z; z++) {
for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; 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); u32 vi = vm->m_area.index(node_min.X, y, z);
for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index2d++) { for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index2d++) {
if (vm->m_data[vi].getContent() == CONTENT_IGNORE) { if (vm->m_data[vi].getContent() != CONTENT_IGNORE)
s16 seabed_height = noise_seabed->result[index2d]; continue;
if (y <= seabed_height || getFractalAtPoint(x, y, z)) { s16 seabed_height;
vm->m_data[vi] = n_stone; if (noise_seabed)
if (y > stone_surface_max_y) seabed_height = noise_seabed->result[index2d];
stone_surface_max_y = y;
} else if (y <= water_level) { if (((spflags & MGFRACTAL_TERRAIN) && y <= seabed_height) ||
vm->m_data[vi] = n_water; getFractalAtPoint(x, y, z)) {
} else { vm->m_data[vi] = n_stone;
vm->m_data[vi] = n_air; 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; index2d -= ystride;

@ -1,7 +1,7 @@
/* /*
Minetest Minetest
Copyright (C) 2015-2018 paramat Copyright (C) 2015-2019 paramat
Copyright (C) 2015-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net> Copyright (C) 2015-2016 kwolekr, Ryan Kwolek
Fractal formulas from http://www.bugman123.com/Hypercomplex/index.html Fractal formulas from http://www.bugman123.com/Hypercomplex/index.html
by Paul Nylander, and from http://www.fractalforums.com, thank you. by Paul Nylander, and from http://www.fractalforums.com, thank you.
@ -25,13 +25,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen.h" #include "mapgen.h"
///////////// Mapgen Fractal flags
#define MGFRACTAL_TERRAIN 0x01
class BiomeManager; class BiomeManager;
extern FlagDesc flagdesc_mapgen_fractal[]; extern FlagDesc flagdesc_mapgen_fractal[];
struct MapgenFractalParams : public MapgenParams struct MapgenFractalParams : public MapgenParams
{ {
u32 spflags = 0; u32 spflags = MGFRACTAL_TERRAIN;
float cave_width = 0.09f; float cave_width = 0.09f;
s16 large_cave_depth = -33; s16 large_cave_depth = -33;
s16 lava_depth = -256; s16 lava_depth = -256;
@ -60,6 +64,7 @@ struct MapgenFractalParams : public MapgenParams
void writeParams(Settings *settings) const; void writeParams(Settings *settings) const;
}; };
class MapgenFractal : public MapgenBasic class MapgenFractal : public MapgenBasic
{ {
public: public:
@ -89,5 +94,5 @@ private:
float julia_y; float julia_y;
float julia_z; float julia_z;
float julia_w; float julia_w;
Noise *noise_seabed; Noise *noise_seabed = nullptr;
}; };