diff options
author | sfan5 <sfan5@live.de> | 2021-03-23 15:43:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-23 15:43:26 +0100 |
commit | 2da1eee394554879bf1cee6bc0f7b77acf0b6c43 (patch) | |
tree | c27bf698c21f13263fa3d56cd51ebaeace30ce2e /src/mapgen | |
parent | c9eba8440d3dc293a8aa6ffafc045737732da1e1 (diff) | |
download | minetest-2da1eee394554879bf1cee6bc0f7b77acf0b6c43.tar.gz minetest-2da1eee394554879bf1cee6bc0f7b77acf0b6c43.tar.bz2 minetest-2da1eee394554879bf1cee6bc0f7b77acf0b6c43.zip |
Fix broken `BiomeGen` abstraction (#11107)
Diffstat (limited to 'src/mapgen')
-rw-r--r-- | src/mapgen/mapgen.cpp | 4 | ||||
-rw-r--r-- | src/mapgen/mapgen_valleys.cpp | 3 | ||||
-rw-r--r-- | src/mapgen/mg_biome.cpp | 90 | ||||
-rw-r--r-- | src/mapgen/mg_biome.h | 27 |
4 files changed, 38 insertions, 86 deletions
diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index e0dfd2d71..7984ff609 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -595,7 +595,8 @@ MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerg this->heightmap = new s16[csize.X * csize.Z]; //// Initialize biome generator - biomegen = m_bmgr->createBiomeGen(BIOMEGEN_ORIGINAL, params->bparams, csize); + biomegen = emerge->biomegen; + biomegen->assertChunkSize(csize); biomemap = biomegen->biomemap; //// Look up some commonly used content @@ -621,7 +622,6 @@ MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerg MapgenBasic::~MapgenBasic() { - delete biomegen; delete []heightmap; delete m_emerge; // destroying EmergeParams is our responsibility diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index c4234857e..80a99b1f0 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -57,7 +57,8 @@ FlagDesc flagdesc_mapgen_valleys[] = { MapgenValleys::MapgenValleys(MapgenValleysParams *params, EmergeParams *emerge) : MapgenBasic(MAPGEN_VALLEYS, params, emerge) { - // NOTE: MapgenValleys has a hard dependency on BiomeGenOriginal + FATAL_ERROR_IF(biomegen->getType() != BIOMEGEN_ORIGINAL, + "MapgenValleys has a hard dependency on BiomeGenOriginal"); m_bgen = (BiomeGenOriginal *)biomegen; spflags = params->spflags; diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp index 610c38594..f08cc190f 100644 --- a/src/mapgen/mg_biome.cpp +++ b/src/mapgen/mg_biome.cpp @@ -101,71 +101,6 @@ BiomeManager *BiomeManager::clone() const return mgr; } - -// For BiomeGen type 'BiomeGenOriginal' -float BiomeManager::getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat, - NoiseParams &np_heat_blend, u64 seed) const -{ - return - NoisePerlin2D(&np_heat, pos.X, pos.Z, seed) + - NoisePerlin2D(&np_heat_blend, pos.X, pos.Z, seed); -} - - -// For BiomeGen type 'BiomeGenOriginal' -float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity, - NoiseParams &np_humidity_blend, u64 seed) const -{ - return - NoisePerlin2D(&np_humidity, pos.X, pos.Z, seed) + - NoisePerlin2D(&np_humidity_blend, pos.X, pos.Z, seed); -} - - -// For BiomeGen type 'BiomeGenOriginal' -const Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, - float humidity, v3s16 pos) const -{ - Biome *biome_closest = nullptr; - Biome *biome_closest_blend = nullptr; - float dist_min = FLT_MAX; - float dist_min_blend = FLT_MAX; - - for (size_t i = 1; i < getNumObjects(); i++) { - Biome *b = (Biome *)getRaw(i); - if (!b || - pos.Y < b->min_pos.Y || pos.Y > b->max_pos.Y + b->vertical_blend || - pos.X < b->min_pos.X || pos.X > b->max_pos.X || - pos.Z < b->min_pos.Z || pos.Z > b->max_pos.Z) - continue; - - float d_heat = heat - b->heat_point; - float d_humidity = humidity - b->humidity_point; - float dist = (d_heat * d_heat) + (d_humidity * d_humidity); - - if (pos.Y <= b->max_pos.Y) { // Within y limits of biome b - if (dist < dist_min) { - dist_min = dist; - biome_closest = b; - } - } else if (dist < dist_min_blend) { // Blend area above biome b - dist_min_blend = dist; - biome_closest_blend = b; - } - } - - const u64 seed = pos.Y + (heat + humidity) * 0.9f; - PcgRandom rng(seed); - - if (biome_closest_blend && dist_min_blend <= dist_min && - rng.range(0, biome_closest_blend->vertical_blend) >= - pos.Y - biome_closest_blend->max_pos.Y) - return biome_closest_blend; - - return (biome_closest) ? biome_closest : (Biome *)getRaw(BIOME_NONE); -} - - //////////////////////////////////////////////////////////////////////////////// void BiomeParamsOriginal::readParams(const Settings *settings) @@ -189,7 +124,7 @@ void BiomeParamsOriginal::writeParams(Settings *settings) const //////////////////////////////////////////////////////////////////////////////// BiomeGenOriginal::BiomeGenOriginal(BiomeManager *biomemgr, - BiomeParamsOriginal *params, v3s16 chunksize) + const BiomeParamsOriginal *params, v3s16 chunksize) { m_bmgr = biomemgr; m_params = params; @@ -224,17 +159,26 @@ BiomeGenOriginal::~BiomeGenOriginal() delete noise_humidity_blend; } -// Only usable in a mapgen thread -Biome *BiomeGenOriginal::calcBiomeAtPoint(v3s16 pos) const +BiomeGen *BiomeGenOriginal::clone(BiomeManager *biomemgr) const +{ + return new BiomeGenOriginal(biomemgr, m_params, m_csize); +} + +float BiomeGenOriginal::calcHeatAtPoint(v3s16 pos) const { - float heat = - NoisePerlin2D(&m_params->np_heat, pos.X, pos.Z, m_params->seed) + + return NoisePerlin2D(&m_params->np_heat, pos.X, pos.Z, m_params->seed) + NoisePerlin2D(&m_params->np_heat_blend, pos.X, pos.Z, m_params->seed); - float humidity = - NoisePerlin2D(&m_params->np_humidity, pos.X, pos.Z, m_params->seed) + +} + +float BiomeGenOriginal::calcHumidityAtPoint(v3s16 pos) const +{ + return NoisePerlin2D(&m_params->np_humidity, pos.X, pos.Z, m_params->seed) + NoisePerlin2D(&m_params->np_humidity_blend, pos.X, pos.Z, m_params->seed); +} - return calcBiomeFromNoise(heat, humidity, pos); +Biome *BiomeGenOriginal::calcBiomeAtPoint(v3s16 pos) const +{ + return calcBiomeFromNoise(calcHeatAtPoint(pos), calcHumidityAtPoint(pos), pos); } diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index be4cfea4d..c85afc3a0 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -97,6 +97,15 @@ public: virtual BiomeGenType getType() const = 0; + // Clone this BiomeGen and set a the new BiomeManager to be used by the copy + virtual BiomeGen *clone(BiomeManager *biomemgr) const = 0; + + // Check that the internal chunk size is what the mapgen expects, just to be sure. + inline void assertChunkSize(v3s16 expect) const + { + FATAL_ERROR_IF(m_csize != expect, "Chunk size mismatches"); + } + // Calculates the biome at the exact position provided. This function can // be called at any time, but may be less efficient than the latter methods, // depending on implementation. @@ -158,12 +167,18 @@ struct BiomeParamsOriginal : public BiomeParams { class BiomeGenOriginal : public BiomeGen { public: BiomeGenOriginal(BiomeManager *biomemgr, - BiomeParamsOriginal *params, v3s16 chunksize); + const BiomeParamsOriginal *params, v3s16 chunksize); virtual ~BiomeGenOriginal(); BiomeGenType getType() const { return BIOMEGEN_ORIGINAL; } + BiomeGen *clone(BiomeManager *biomemgr) const; + + // Slower, meant for Script API use + float calcHeatAtPoint(v3s16 pos) const; + float calcHumidityAtPoint(v3s16 pos) const; Biome *calcBiomeAtPoint(v3s16 pos) const; + void calcBiomeNoise(v3s16 pmin); biome_t *getBiomes(s16 *heightmap, v3s16 pmin); @@ -176,7 +191,7 @@ public: float *humidmap; private: - BiomeParamsOriginal *m_params; + const BiomeParamsOriginal *m_params; Noise *noise_heat; Noise *noise_humidity; @@ -229,14 +244,6 @@ public: virtual void clear(); - // For BiomeGen type 'BiomeGenOriginal' - float getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat, - NoiseParams &np_heat_blend, u64 seed) const; - float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity, - NoiseParams &np_humidity_blend, u64 seed) const; - const Biome *getBiomeFromNoiseOriginal(float heat, float humidity, - v3s16 pos) const; - private: BiomeManager() {}; |