add 'below_sea_level' layer property
This commit is contained in:
parent
2a767a3638
commit
c5877684eb
@ -1,6 +1,6 @@
|
||||
layers = {
|
||||
{block="base:grass_block", height=1},
|
||||
{block="base:dirt", height=1},
|
||||
{block="base:grass_block", height=1, below_sea_level=false},
|
||||
{block="base:dirt", height=5, below_sea_level=false},
|
||||
{block="base:stone", height=-1},
|
||||
{block="base:bazalt", height=1},
|
||||
}
|
||||
|
||||
@ -748,7 +748,13 @@ std::unique_ptr<GeneratorScript> scripting::load_generator(
|
||||
lua::pop(L);
|
||||
lua::requirefield(L, "height");
|
||||
int height = lua::tointeger(L, -1);
|
||||
lua::pop(L, 2);
|
||||
lua::pop(L);
|
||||
bool below_sea_level = true;
|
||||
if (lua::getfield(L, "below_sea_level")) {
|
||||
below_sea_level = lua::toboolean(L, -1);
|
||||
lua::pop(L);
|
||||
}
|
||||
lua::pop(L);
|
||||
|
||||
if (hasResizeableLayer) {
|
||||
lastLayersHeight += height;
|
||||
@ -759,7 +765,7 @@ std::unique_ptr<GeneratorScript> scripting::load_generator(
|
||||
}
|
||||
hasResizeableLayer = true;
|
||||
}
|
||||
layers.push_back(BlocksLayer {name, height, {}});
|
||||
layers.push_back(BlocksLayer {name, height, below_sea_level, {}});
|
||||
} catch (const std::runtime_error& err) {
|
||||
lua::pop(L, 2);
|
||||
throw std::runtime_error(
|
||||
|
||||
@ -11,6 +11,7 @@ class Content;
|
||||
struct BlocksLayer {
|
||||
std::string block;
|
||||
int height;
|
||||
bool below_sea_level;
|
||||
|
||||
struct {
|
||||
blockid_t id;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user