add 'heights-interpolation', 'biomes-interpolation'

This commit is contained in:
MihailRis 2024-10-28 09:22:02 +03:00
parent 99d9533453
commit d8c3940451
5 changed files with 33 additions and 3 deletions

View File

@ -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")) {

View File

@ -5,6 +5,17 @@
#include <stdexcept>
#include <glm/glm.hpp>
std::optional<InterpolationType> 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,

View File

@ -2,6 +2,7 @@
#include <vector>
#include <string>
#include <optional>
#include "typedefs.hpp"
#include "maths/Heightmap.hpp"
@ -12,6 +13,8 @@ enum class InterpolationType {
CUBIC,
};
std::optional<InterpolationType> InterpolationType_from(std::string_view str);
class Heightmap {
std::vector<float> buffer;
uint width, height;

View File

@ -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;

View File

@ -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;