diff options
author | kwolekr <kwolekr@minetest.net> | 2016-04-28 03:43:09 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2016-05-27 23:23:58 -0400 |
commit | 76f485647983ebd7eb4c3abbca0869d13f76920b (patch) | |
tree | 6e6f4745311f2ac834780b5bf142dfeeea3aceb0 /src/mapgen_fractal.cpp | |
parent | fa6b21a15b415cd82dce6896b94a5341b7dd76f0 (diff) | |
download | minetest-76f485647983ebd7eb4c3abbca0869d13f76920b.tar.gz minetest-76f485647983ebd7eb4c3abbca0869d13f76920b.tar.bz2 minetest-76f485647983ebd7eb4c3abbca0869d13f76920b.zip |
Move biome calculation to BiomeGen
BiomeGen defines an interface that, given a set of BiomeParams, computes biomes
for a given area using the algorithm implemented by that specific BiomeGen.
This abstracts away the old system where each mapgen supplied the noises
required for biome generation.
Diffstat (limited to 'src/mapgen_fractal.cpp')
-rw-r--r-- | src/mapgen_fractal.cpp | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/src/mapgen_fractal.cpp b/src/mapgen_fractal.cpp index e2e29f875..9671a2143 100644 --- a/src/mapgen_fractal.cpp +++ b/src/mapgen_fractal.cpp @@ -59,10 +59,7 @@ MapgenFractal::MapgenFractal(int mapgenid, MapgenParams *params, EmergeManager * // 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]; - this->heatmap = NULL; - this->humidmap = NULL; MapgenFractalParams *sp = (MapgenFractalParams *)params->sparams; @@ -87,18 +84,15 @@ MapgenFractal::MapgenFractal(int mapgenid, MapgenParams *params, EmergeManager * 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); - noise_humidity = new Noise(¶ms->np_biome_humidity, seed, csize.X, csize.Z); - noise_heat_blend = new Noise(¶ms->np_biome_heat_blend, seed, csize.X, csize.Z); - noise_humidity_blend = new Noise(¶ms->np_biome_humidity_blend, seed, csize.X, csize.Z); + //// Initialize biome generator + biomegen = emerge->biomemgr->createBiomeGen( + BIOMEGEN_ORIGINAL, params->bparams, csize); + biomemap = biomegen->biomemap; this->formula = fractal / 2 + fractal % 2; this->julia = fractal % 2 == 0; //// Resolve nodes to be used - INodeDefManager *ndef = emerge->ndef; - c_stone = ndef->getId("mapgen_stone"); c_water_source = ndef->getId("mapgen_water_source"); c_lava_source = ndef->getId("mapgen_lava_source"); @@ -132,13 +126,9 @@ MapgenFractal::~MapgenFractal() delete noise_cave1; delete noise_cave2; - delete noise_heat; - delete noise_humidity; - delete noise_heat_blend; - delete noise_humidity_blend; + delete biomegen; delete[] heightmap; - delete[] biomemap; } @@ -217,7 +207,7 @@ int MapgenFractal::getSpawnLevelAtPoint(v2s16 p) 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 solid_below = true; @@ -268,12 +258,10 @@ void MapgenFractal::makeChunk(BlockMakeData *data) // Create heightmap updateHeightmap(node_min, node_max); - // Create biomemap at heightmap surface - bmgr->calcBiomes(csize.X, csize.Z, noise_heat->result, - noise_humidity->result, heightmap, biomemap); - - // Actually place the biome-specific nodes - MgStoneType stone_type = generateBiomes(noise_heat->result, noise_humidity->result); + // Init biome generator, place biome-specific nodes, and build biomemap + biomegen->calcBiomeNoise(node_min); + biomegen->getBiomes(heightmap); + MgStoneType stone_type = generateBiomes(); if (flags & MG_CAVES) generateCaves(stone_surface_max_y); @@ -358,18 +346,7 @@ void MapgenFractal::calculateNoise() // 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); - noise_humidity_blend->perlinMap2D(x, z); - - for (s32 i = 0; i < csize.X * csize.Z; i++) { - noise_heat->result[i] += noise_heat_blend->result[i]; - noise_humidity->result[i] += noise_humidity_blend->result[i]; - } - heatmap = noise_heat->result; - humidmap = noise_humidity->result; //printf("calculateNoise: %dus\n", t.stop()); } @@ -530,7 +507,7 @@ s16 MapgenFractal::generateTerrain() } -MgStoneType MapgenFractal::generateBiomes(float *heat_map, float *humidity_map) +MgStoneType MapgenFractal::generateBiomes() { v3s16 em = vm->m_area.getExtent(); u32 index = 0; @@ -567,7 +544,8 @@ MgStoneType MapgenFractal::generateBiomes(float *heat_map, float *humidity_map) // 3. When stone or water is detected but biome has not yet been calculated. if ((c == c_stone && (air_above || water_above || !biome)) || (c == c_water_source && (air_above || !biome))) { - biome = bmgr->getBiome(heat_map[index], humidity_map[index], y); + biome = biomegen->getBiomeAtIndex(index, y); + depth_top = biome->depth_top; base_filler = MYMAX(depth_top + biome->depth_filler + noise_filler_depth->result[index], 0); |