add plants
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include "maths/util.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
#include "voxels/Chunk.hpp"
|
||||
@@ -63,7 +64,7 @@ static inline const Biome* choose_biome(
|
||||
for (const auto& biome : biomes) {
|
||||
float score = 0.0f;
|
||||
for (uint i = 0; i < paramsCount; i++) {
|
||||
score += glm::abs((params[i] - biome.parameters[i].origin) /
|
||||
score += glm::abs((params[i] - biome.parameters[i].value) /
|
||||
biome.parameters[i].weight);
|
||||
}
|
||||
if (score < chosenScore) {
|
||||
@@ -92,6 +93,9 @@ void WorldGenerator::generate(
|
||||
|
||||
std::memset(voxels, 0, sizeof(voxel) * CHUNK_VOL);
|
||||
|
||||
PseudoRandom plantsRand;
|
||||
plantsRand.setSeed(chunkX, chunkZ);
|
||||
|
||||
for (uint z = 0; z < CHUNK_D; z++) {
|
||||
for (uint x = 0; x < CHUNK_W; x++) {
|
||||
const Biome* biome = choose_biome(biomes, biomeParams, x, z);
|
||||
@@ -104,6 +108,15 @@ void WorldGenerator::generate(
|
||||
|
||||
generate_pole(seaLayers, seaLevel, height, seaLevel, voxels, x, z);
|
||||
generate_pole(groundLayers, height, 0, seaLevel, voxels, x, z);
|
||||
|
||||
if (height+1 > seaLevel) {
|
||||
// TODO: add underwater plants support
|
||||
float rand = (plantsRand.randU32() % RAND_MAX) / static_cast<float>(RAND_MAX);
|
||||
blockid_t plant = biome->plants.choose(rand);
|
||||
if (plant) {
|
||||
voxels[vox_index(x, height+1, z)].id = plant;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user