add 'below_sea_level' layer property

This commit is contained in:
MihailRis
2024-08-17 18:44:08 +03:00
parent 2a767a3638
commit c5877684eb
4 changed files with 22 additions and 6 deletions
+11 -2
View File
@@ -16,10 +16,11 @@ WorldGenerator::WorldGenerator(
#include "util/timeutil.hpp"
void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ, int seed) {
timeutil::ScopeLogTimer log(555);
auto heightmap = def.script->generateHeightmap(
{chunkX*CHUNK_W, chunkZ*CHUNK_D}, {CHUNK_W, CHUNK_D}
);
timeutil::ScopeLogTimer log(555);
uint seaLevel = 64;
auto values = heightmap->getValues();
const auto& layers = def.script->getLayers();
uint lastLayersHeight = def.script->getLastLayersHeight();
@@ -30,19 +31,27 @@ void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ, int seed) {
for (uint z = 0; z < CHUNK_D; z++) {
for (uint x = 0; x < CHUNK_W; x++) {
int height = values[z * CHUNK_W + x] * 255 + 10;
for (uint y = height+1; y < 64; y++) {
for (uint y = height+1; y <= seaLevel; y++) {
voxels[vox_index(x, y, z)].id = baseWater;
}
uint y = height;
uint layerExtension = 0;
for (const auto& layer : layers) {
if (y < seaLevel && !layer.below_sea_level) {
layerExtension = std::max(0, layer.height);
continue;
}
uint layerHeight = layer.height;
if (layerHeight == -1) {
layerHeight = y - lastLayersHeight + 1;
} else {
layerHeight += layerExtension;
}
for (uint i = 0; i < layerHeight; i++, y--) {
voxels[vox_index(x, y, z)].id = layer.rt.id;
}
layerExtension = 0;
}
}
}