add 'heights-interpolation', 'biomes-interpolation'
This commit is contained in:
@@ -202,6 +202,16 @@ void ContentLoader::loadGenerator(
|
|||||||
map.at("biome-parameters").get(def.biomeParameters);
|
map.at("biome-parameters").get(def.biomeParameters);
|
||||||
map.at("biome-bpd").get(def.biomesBPD);
|
map.at("biome-bpd").get(def.biomesBPD);
|
||||||
map.at("heights-bpd").get(def.heightsBPD);
|
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("sea-level").get(def.seaLevel);
|
||||||
map.at("wide-structs-chunks-radius").get(def.wideStructsChunksRadius);
|
map.at("wide-structs-chunks-radius").get(def.wideStructsChunksRadius);
|
||||||
if (map.has("heightmap-inputs")) {
|
if (map.has("heightmap-inputs")) {
|
||||||
|
|||||||
@@ -5,6 +5,17 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <glm/glm.hpp>
|
#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(
|
static inline float sample_at(
|
||||||
const float* buffer,
|
const float* buffer,
|
||||||
uint width,
|
uint width,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
#include "maths/Heightmap.hpp"
|
#include "maths/Heightmap.hpp"
|
||||||
@@ -12,6 +13,8 @@ enum class InterpolationType {
|
|||||||
CUBIC,
|
CUBIC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::optional<InterpolationType> InterpolationType_from(std::string_view str);
|
||||||
|
|
||||||
class Heightmap {
|
class Heightmap {
|
||||||
std::vector<float> buffer;
|
std::vector<float> buffer;
|
||||||
uint width, height;
|
uint width, height;
|
||||||
|
|||||||
@@ -209,6 +209,12 @@ struct GeneratorDef {
|
|||||||
/// @brief Heightmap blocks per dot
|
/// @brief Heightmap blocks per dot
|
||||||
uint heightsBPD = 4;
|
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
|
/// @brief Number of chunks must be generated before and after wide
|
||||||
/// structures placement triggered
|
/// structures placement triggered
|
||||||
uint wideStructsChunksRadius = 3;
|
uint wideStructsChunksRadius = 3;
|
||||||
|
|||||||
@@ -307,13 +307,13 @@ void WorldGenerator::generateBiomes(
|
|||||||
copy->resize(
|
copy->resize(
|
||||||
floordiv(CHUNK_W, def.heightsBPD) + 1,
|
floordiv(CHUNK_W, def.heightsBPD) + 1,
|
||||||
floordiv(CHUNK_D, def.heightsBPD) + 1,
|
floordiv(CHUNK_D, def.heightsBPD) + 1,
|
||||||
InterpolationType::LINEAR
|
def.heightsInterpolation
|
||||||
);
|
);
|
||||||
prototype.heightmapInputs.push_back(std::move(copy));
|
prototype.heightmapInputs.push_back(std::move(copy));
|
||||||
}
|
}
|
||||||
for (const auto& map : biomeParams) {
|
for (const auto& map : biomeParams) {
|
||||||
map->resize(
|
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);
|
map->crop(0, 0, CHUNK_W, CHUNK_D);
|
||||||
}
|
}
|
||||||
@@ -345,7 +345,7 @@ void WorldGenerator::generateHeightmap(
|
|||||||
);
|
);
|
||||||
prototype.heightmap->clamp();
|
prototype.heightmap->clamp();
|
||||||
prototype.heightmap->resize(
|
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.heightmap->crop(0, 0, CHUNK_W, CHUNK_D);
|
||||||
prototype.level = ChunkPrototypeLevel::HEIGHTMAP;
|
prototype.level = ChunkPrototypeLevel::HEIGHTMAP;
|
||||||
|
|||||||
Reference in New Issue
Block a user