feat: heightmap-inputs

This commit is contained in:
MihailRis
2024-10-16 00:38:58 +03:00
parent 5e79bc07e9
commit 59c4e26eda
10 changed files with 76 additions and 14 deletions
+7 -2
View File
@@ -128,12 +128,14 @@ public:
/// @param size size of the heightmap
/// @param seed world seed
/// @param bpd blocks per dot
/// @param inputs biome parameter maps passed to generate_heightmap
/// @return generated heightmap (can't be nullptr)
virtual std::shared_ptr<Heightmap> generateHeightmap(
const glm::ivec2& offset,
const glm::ivec2& size,
uint64_t seed,
uint bpd
uint bpd,
const std::vector<std::shared_ptr<Heightmap>>& inputs
) = 0;
/// @brief Generate a biomes parameters maps
@@ -207,12 +209,15 @@ struct GeneratorDef {
uint biomesBPD = 8;
/// @brief Heightmap blocks per dot
uint heightsBPD = 4;
uint heightsBPD = 8;
/// @brief Number of chunks must be generated before and after wide
/// structures placement triggered
uint wideStructsChunksRadius = 3;
/// @brief Indices of biome parameter maps passed to generate_heightmap
std::vector<uint8_t> heightmapInputs;
std::unordered_map<std::string, size_t> structuresIndices;
std::vector<std::unique_ptr<VoxelStructure>> structures;
std::vector<Biome> biomes;
+15 -3
View File
@@ -300,6 +300,16 @@ void WorldGenerator::generateBiomes(
seed,
bpd
);
for (auto index : def.heightmapInputs) {
// copy non-scaled maps
auto copy = std::make_shared<Heightmap>(*biomeParams[index]);
copy->resize(
floordiv(CHUNK_W, def.heightsBPD) + 1,
floordiv(CHUNK_D, def.heightsBPD) + 1,
InterpolationType::LINEAR
);
prototype.heightmapInputs.push_back(std::move(copy));
}
for (const auto& map : biomeParams) {
map->resize(
CHUNK_W + bpd, CHUNK_D + bpd, InterpolationType::LINEAR
@@ -330,8 +340,10 @@ void WorldGenerator::generateHeightmap(
{floordiv(chunkX * CHUNK_W, bpd), floordiv(chunkZ * CHUNK_D, bpd)},
{floordiv(CHUNK_W, bpd)+1, floordiv(CHUNK_D, bpd)+1},
seed,
bpd
bpd,
prototype.heightmapInputs
);
prototype.heightmap->clamp();
prototype.heightmap->resize(
CHUNK_W + bpd, CHUNK_D + bpd, InterpolationType::LINEAR
);
@@ -363,9 +375,9 @@ void WorldGenerator::generatePlants(
const Biome* biome = biomes[z * CHUNK_W + x];
int height = heights[z * CHUNK_W + x] * CHUNK_H;
height = std::max(0, height);
height = std::min(std::max(0, height), CHUNK_H-1);
if (height+1 > def.seaLevel) {
if (height+1 > def.seaLevel && height+1 < CHUNK_H) {
float rand = plantsRand.randFloat();
blockid_t plant = biome->plants.choose(rand);
if (plant) {
+3
View File
@@ -32,6 +32,9 @@ struct ChunkPrototype {
std::shared_ptr<Heightmap> heightmap;
std::vector<Placement> placements;
/// @brief biome parameters maps saved until heightmaps generation
std::vector<std::shared_ptr<Heightmap>> heightmapInputs {};
};
struct WorldGenDebugInfo {