1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Huge overhaul of the entire MapgenParams system

MapgenParams is no longer a polymorphic class, eliminating the need for messy and bug-prone reallocations.
Separation between the common and mapgen-specific parameters is now strongly defined.
Mapgen parameters objects are now properly encapsulated within the proper subsystems.
This commit is contained in:
kwolekr 2014-02-03 22:42:10 -05:00
parent a439343844
commit 5a34f40d80
24 changed files with 402 additions and 619 deletions

View file

@ -37,62 +37,47 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "treegen.h"
#include "mapgen_v6.h"
/////////////////// Mapgen V6 perlin noise default values
NoiseParams nparams_v6_def_terrain_base =
{-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6};
NoiseParams nparams_v6_def_terrain_higher =
{20.0, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6};
NoiseParams nparams_v6_def_steepness =
{0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7};
NoiseParams nparams_v6_def_height_select =
{0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69};
NoiseParams nparams_v6_def_mud =
{AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55};
NoiseParams nparams_v6_def_beach =
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50};
NoiseParams nparams_v6_def_biome =
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50};
NoiseParams nparams_v6_def_cave =
{6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50};
NoiseParams nparams_v6_def_humidity =
{0.5, 0.5, v3f(500.0, 500.0, 500.0), 72384, 4, 0.66};
NoiseParams nparams_v6_def_trees =
{0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
NoiseParams nparams_v6_def_apple_trees =
{0.0, 1.0, v3f(100.0, 100.0, 100.0), 342902, 3, 0.45};
FlagDesc flagdesc_mapgen_v6[] = {
{"v6_jungles", MGV6_JUNGLES},
{"v6_biome_blend", MGV6_BIOME_BLEND},
{"v6_nomudflow", MGV6_NOMUDFLOW},
{NULL, 0}
};
///////////////////////////////////////////////////////////////////////////////
MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params, EmergeManager *emerge) {
MapgenV6::MapgenV6(int mapgenid, MapgenParams *params, EmergeManager *emerge) {
this->generating = false;
this->id = mapgenid;
this->emerge = emerge;
this->seed = (int)params->seed;
this->seed = (int)params->seed;
this->water_level = params->water_level;
this->flags = params->flags;
this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE;
this->gennotify = emerge->gennotify;
this->freq_desert = params->freq_desert;
this->freq_beach = params->freq_beach;
this->flags = params->flags;
this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE;
this->gennotify = emerge->gennotify;
this->ystride = csize.X; //////fix this
np_cave = &params->np_cave;
np_humidity = &params->np_humidity;
np_trees = &params->np_trees;
np_apple_trees = &params->np_apple_trees;
MapgenV6Params *sp = (MapgenV6Params *)params->sparams;
noise_terrain_base = new Noise(&params->np_terrain_base, seed, csize.X, csize.Y);
noise_terrain_higher = new Noise(&params->np_terrain_higher, seed, csize.X, csize.Y);
noise_steepness = new Noise(&params->np_steepness, seed, csize.X, csize.Y);
noise_height_select = new Noise(&params->np_height_select, seed, csize.X, csize.Y);
noise_mud = new Noise(&params->np_mud, seed, csize.X, csize.Y);
noise_beach = new Noise(&params->np_beach, seed, csize.X, csize.Y);
noise_biome = new Noise(&params->np_biome, seed, csize.X, csize.Y);
this->spflags = sp->spflags;
this->freq_desert = sp->freq_desert;
this->freq_beach = sp->freq_beach;
np_cave = &sp->np_cave;
np_humidity = &sp->np_humidity;
np_trees = &sp->np_trees;
np_apple_trees = &sp->np_apple_trees;
noise_terrain_base = new Noise(&sp->np_terrain_base, seed, csize.X, csize.Y);
noise_terrain_higher = new Noise(&sp->np_terrain_higher, seed, csize.X, csize.Y);
noise_steepness = new Noise(&sp->np_steepness, seed, csize.X, csize.Y);
noise_height_select = new Noise(&sp->np_height_select, seed, csize.X, csize.Y);
noise_mud = new Noise(&sp->np_mud, seed, csize.X, csize.Y);
noise_beach = new Noise(&sp->np_beach, seed, csize.X, csize.Y);
noise_biome = new Noise(&sp->np_biome, seed, csize.X, csize.Y);
}
@ -107,6 +92,63 @@ MapgenV6::~MapgenV6() {
}
MapgenV6Params::MapgenV6Params() {
spflags = MGV6_BIOME_BLEND;
freq_desert = 0.45;
freq_beach = 0.15;
np_terrain_base = NoiseParams(-4, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6);
np_terrain_higher = NoiseParams(20, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6);
np_steepness = NoiseParams(0.85,0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7);
np_height_select = NoiseParams(0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69);
np_mud = NoiseParams(4, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55);
np_beach = NoiseParams(0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50);
np_biome = NoiseParams(0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50);
np_cave = NoiseParams(6, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50);
np_humidity = NoiseParams(0.5, 0.5, v3f(500.0, 500.0, 500.0), 72384, 4, 0.66);
np_trees = NoiseParams(0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66);
np_apple_trees = NoiseParams(0, 1.0, v3f(100.0, 100.0, 100.0), 342902, 3, 0.45);
}
void MapgenV6Params::readParams(Settings *settings) {
settings->tryGetFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6);
settings->tryGetFloat("mgv6_freq_desert", freq_desert);
settings->tryGetFloat("mgv6_freq_beach", freq_beach);
settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base);
settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
settings->getNoiseParams("mgv6_np_steepness", np_steepness);
settings->getNoiseParams("mgv6_np_height_select", np_height_select);
settings->getNoiseParams("mgv6_np_mud", np_mud);
settings->getNoiseParams("mgv6_np_beach", np_beach);
settings->getNoiseParams("mgv6_np_biome", np_biome);
settings->getNoiseParams("mgv6_np_cave", np_cave);
settings->getNoiseParams("mgv6_np_humidity", np_humidity);
settings->getNoiseParams("mgv6_np_trees", np_trees);
settings->getNoiseParams("mgv6_np_apple_trees", np_apple_trees);
}
void MapgenV6Params::writeParams(Settings *settings) {
settings->setFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6);
settings->setFloat("mgv6_freq_desert", freq_desert);
settings->setFloat("mgv6_freq_beach", freq_beach);
settings->setNoiseParams("mgv6_np_terrain_base", np_terrain_base);
settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
settings->setNoiseParams("mgv6_np_steepness", np_steepness);
settings->setNoiseParams("mgv6_np_height_select", np_height_select);
settings->setNoiseParams("mgv6_np_mud", np_mud);
settings->setNoiseParams("mgv6_np_beach", np_beach);
settings->setNoiseParams("mgv6_np_biome", np_biome);
settings->setNoiseParams("mgv6_np_cave", np_cave);
settings->setNoiseParams("mgv6_np_humidity", np_humidity);
settings->setNoiseParams("mgv6_np_trees", np_trees);
settings->setNoiseParams("mgv6_np_apple_trees", np_apple_trees);
}
//////////////////////// Some helper functions for the map generator
@ -323,7 +365,7 @@ BiomeType MapgenV6::getBiome(int index, v2s16 p)
if (d > freq_desert)
return BT_DESERT;
if ((flags & MGV6_BIOME_BLEND) &&
if ((spflags & MGV6_BIOME_BLEND) &&
(d > freq_desert - 0.10) &&
((noise2d(p.X, p.Y, seed) + 1.0) > (freq_desert - d) * 20.0))
return BT_DESERT;
@ -439,7 +481,7 @@ void MapgenV6::makeChunk(BlockMakeData *data) {
addDirtGravelBlobs();
// Flow mud away from steep edges
if (!(flags & MGV6_NOMUDFLOW))
if (!(spflags & MGV6_NOMUDFLOW))
flowMud(mudflow_minpos, mudflow_maxpos);
}
@ -866,7 +908,7 @@ void MapgenV6::placeTreesAndJungleGrass() {
float humidity;
bool is_jungle = false;
if (flags & MGV6_JUNGLES) {
if (spflags & MGV6_JUNGLES) {
humidity = getHumidity(p2d_center);
if (humidity > 0.75) {
is_jungle = true;