aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen_flat.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2016-04-28 03:43:09 -0400
committerkwolekr <kwolekr@minetest.net>2016-05-27 23:23:58 -0400
commit76f485647983ebd7eb4c3abbca0869d13f76920b (patch)
tree6e6f4745311f2ac834780b5bf142dfeeea3aceb0 /src/mapgen_flat.cpp
parentfa6b21a15b415cd82dce6896b94a5341b7dd76f0 (diff)
downloadminetest-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_flat.cpp')
-rw-r--r--src/mapgen_flat.cpp48
1 files changed, 13 insertions, 35 deletions
diff --git a/src/mapgen_flat.cpp b/src/mapgen_flat.cpp
index 4669f1716..cb9aa9a8b 100644
--- a/src/mapgen_flat.cpp
+++ b/src/mapgen_flat.cpp
@@ -61,10 +61,7 @@ MapgenFlat::MapgenFlat(int mapgenid, MapgenParams *params, EmergeManager *emerge
// 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;
+ this->heightmap = new s16[csize.X * csize.Z];
MapgenFlatParams *sp = (MapgenFlatParams *)params->sparams;
@@ -86,15 +83,12 @@ MapgenFlat::MapgenFlat(int mapgenid, MapgenParams *params, EmergeManager *emerge
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(&params->np_biome_heat, seed, csize.X, csize.Z);
- noise_humidity = new Noise(&params->np_biome_humidity, seed, csize.X, csize.Z);
- noise_heat_blend = new Noise(&params->np_biome_heat_blend, seed, csize.X, csize.Z);
- noise_humidity_blend = new Noise(&params->np_biome_humidity_blend, seed, csize.X, csize.Z);
+ //// Initialize biome generator
+ biomegen = emerge->biomemgr->createBiomeGen(
+ BIOMEGEN_ORIGINAL, params->bparams, csize);
+ biomemap = biomegen->biomemap;
//// 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");
@@ -128,13 +122,9 @@ MapgenFlat::~MapgenFlat()
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;
}
@@ -252,12 +242,10 @@ void MapgenFlat::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);
@@ -343,18 +331,7 @@ void MapgenFlat::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());
}
@@ -406,7 +383,7 @@ s16 MapgenFlat::generateTerrain()
}
-MgStoneType MapgenFlat::generateBiomes(float *heat_map, float *humidity_map)
+MgStoneType MapgenFlat::generateBiomes()
{
v3s16 em = vm->m_area.getExtent();
u32 index = 0;
@@ -443,7 +420,8 @@ MgStoneType MapgenFlat::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);