From d8c39404516c69920170b28e69c51622276d476a Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 28 Oct 2024 09:22:02 +0300 Subject: [PATCH] add 'heights-interpolation', 'biomes-interpolation' --- src/content/loading/GeneratorLoader.cpp | 10 ++++++++++ src/maths/Heightmap.cpp | 11 +++++++++++ src/maths/Heightmap.hpp | 3 +++ src/world/generator/GeneratorDef.hpp | 6 ++++++ src/world/generator/WorldGenerator.cpp | 6 +++--- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/content/loading/GeneratorLoader.cpp b/src/content/loading/GeneratorLoader.cpp index 299565a4..ebae9118 100644 --- a/src/content/loading/GeneratorLoader.cpp +++ b/src/content/loading/GeneratorLoader.cpp @@ -202,6 +202,16 @@ void ContentLoader::loadGenerator( map.at("biome-parameters").get(def.biomeParameters); map.at("biome-bpd").get(def.biomesBPD); map.at("heights-bpd").get(def.heightsBPD); + std::string interpName; + map.at("heights-interpolation").get(interpName); + if (auto interp = InterpolationType_from(interpName)) { + def.heightsInterpolation = *interp; + } + map.at("biomes-interpolation").get(interpName); + if (auto interp = InterpolationType_from(interpName)) { + def.biomesInterpolation = *interp; + } + map.at("sea-level").get(def.seaLevel); map.at("wide-structs-chunks-radius").get(def.wideStructsChunksRadius); if (map.has("heightmap-inputs")) { diff --git a/src/maths/Heightmap.cpp b/src/maths/Heightmap.cpp index 99c27098..ab6ad153 100644 --- a/src/maths/Heightmap.cpp +++ b/src/maths/Heightmap.cpp @@ -5,6 +5,17 @@ #include #include +std::optional InterpolationType_from(std::string_view str) { + if (str == "nearest") { + return InterpolationType::NEAREST; + } else if (str == "linear") { + return InterpolationType::LINEAR; + } else if (str == "cubic") { + return InterpolationType::CUBIC; + } + return std::nullopt; +} + static inline float sample_at( const float* buffer, uint width, diff --git a/src/maths/Heightmap.hpp b/src/maths/Heightmap.hpp index 5f903756..37f5130d 100644 --- a/src/maths/Heightmap.hpp +++ b/src/maths/Heightmap.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "typedefs.hpp" #include "maths/Heightmap.hpp" @@ -12,6 +13,8 @@ enum class InterpolationType { CUBIC, }; +std::optional InterpolationType_from(std::string_view str); + class Heightmap { std::vector buffer; uint width, height; diff --git a/src/world/generator/GeneratorDef.hpp b/src/world/generator/GeneratorDef.hpp index f3abd893..b21a2425 100644 --- a/src/world/generator/GeneratorDef.hpp +++ b/src/world/generator/GeneratorDef.hpp @@ -209,6 +209,12 @@ struct GeneratorDef { /// @brief Heightmap blocks per dot uint heightsBPD = 4; + /// @brief Biome parameter maps interpolation method + InterpolationType biomesInterpolation = InterpolationType::LINEAR; + + /// @brief Height maps interpolation method + InterpolationType heightsInterpolation = InterpolationType::LINEAR; + /// @brief Number of chunks must be generated before and after wide /// structures placement triggered uint wideStructsChunksRadius = 3; diff --git a/src/world/generator/WorldGenerator.cpp b/src/world/generator/WorldGenerator.cpp index f585e71b..c0084df4 100644 --- a/src/world/generator/WorldGenerator.cpp +++ b/src/world/generator/WorldGenerator.cpp @@ -307,13 +307,13 @@ void WorldGenerator::generateBiomes( copy->resize( floordiv(CHUNK_W, def.heightsBPD) + 1, floordiv(CHUNK_D, def.heightsBPD) + 1, - InterpolationType::LINEAR + def.heightsInterpolation ); prototype.heightmapInputs.push_back(std::move(copy)); } for (const auto& map : biomeParams) { map->resize( - CHUNK_W + bpd, CHUNK_D + bpd, InterpolationType::LINEAR + CHUNK_W + bpd, CHUNK_D + bpd, def.biomesInterpolation ); map->crop(0, 0, CHUNK_W, CHUNK_D); } @@ -345,7 +345,7 @@ void WorldGenerator::generateHeightmap( ); prototype.heightmap->clamp(); prototype.heightmap->resize( - CHUNK_W + bpd, CHUNK_D + bpd, InterpolationType::LINEAR + CHUNK_W + bpd, CHUNK_D + bpd, def.heightsInterpolation ); prototype.heightmap->crop(0, 0, CHUNK_W, CHUNK_D); prototype.level = ChunkPrototypeLevel::HEIGHTMAP;