refactor blocks layers
This commit is contained in:
@@ -9,31 +9,32 @@
|
||||
#include "voxels/voxel.hpp"
|
||||
#include "world/generator/GeneratorDef.hpp"
|
||||
|
||||
WorldGenerator::WorldGenerator(
|
||||
const GeneratorDef& def,
|
||||
const Content* content
|
||||
) : def(def), content(content) {
|
||||
WorldGenerator::WorldGenerator(const GeneratorDef& def, const Content* content)
|
||||
: def(def), content(content) {
|
||||
}
|
||||
|
||||
static inline void generate_pole(
|
||||
const std::vector<BlocksLayer>& layers,
|
||||
int height, int bottom, int seaLevel, int lastLayersHeight,
|
||||
const BlocksLayers& layers,
|
||||
int height,
|
||||
int bottom,
|
||||
int seaLevel,
|
||||
voxel* voxels,
|
||||
int x, int z
|
||||
int x,
|
||||
int z
|
||||
) {
|
||||
uint y = height;
|
||||
uint layerExtension = 0;
|
||||
for (const auto& layer : layers) {
|
||||
for (const auto& layer : layers.layers) {
|
||||
// skip layer if can't be generated under sea level
|
||||
if (y < seaLevel && !layer.below_sea_level) {
|
||||
layerExtension = std::max(0, layer.height);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
int layerHeight = layer.height;
|
||||
if (layerHeight == -1) {
|
||||
// resizeable layer
|
||||
layerHeight = y - lastLayersHeight - bottom + 1;
|
||||
layerHeight = y - layers.lastLayersHeight - bottom + 1;
|
||||
} else {
|
||||
layerHeight += layerExtension;
|
||||
}
|
||||
@@ -52,15 +53,12 @@ void WorldGenerator::generate(
|
||||
) {
|
||||
timeutil::ScopeLogTimer log(555);
|
||||
auto heightmap = def.script->generateHeightmap(
|
||||
{chunkX*CHUNK_W, chunkZ*CHUNK_D}, {CHUNK_W, CHUNK_D}, seed
|
||||
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed
|
||||
);
|
||||
auto values = heightmap->getValues();
|
||||
const auto& layers = def.script->getLayers();
|
||||
const auto& groundLayers = def.script->getGroundLayers();
|
||||
const auto& seaLayers = def.script->getSeaLayers();
|
||||
|
||||
uint lastLayersHeight = def.script->getLastLayersHeight();
|
||||
uint lastSeaLayersHeight = def.script->getLastSeaLayersHeight();
|
||||
|
||||
uint seaLevel = def.script->getSeaLevel();
|
||||
|
||||
std::memset(voxels, 0, sizeof(voxel) * CHUNK_VOL);
|
||||
@@ -70,8 +68,8 @@ void WorldGenerator::generate(
|
||||
int height = values[z * CHUNK_W + x] * CHUNK_H;
|
||||
height = std::max(0, height);
|
||||
|
||||
generate_pole(seaLayers, seaLevel, height, seaLevel, lastSeaLayersHeight, voxels, x, z);
|
||||
generate_pole(layers, height, 0, seaLevel, lastLayersHeight, voxels, x, z);
|
||||
generate_pole(seaLayers, seaLevel, height, seaLevel, voxels, x, z);
|
||||
generate_pole(groundLayers, height, 0, seaLevel, voxels, x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user