add biomes table
This commit is contained in:
parent
c3831afd19
commit
4bd5f1b629
@ -4,19 +4,21 @@ sea_level = 64
|
||||
-- 2 - humidity
|
||||
biome_parameters = 2
|
||||
|
||||
biome = {
|
||||
parameters = {
|
||||
{value=0.5, weight=1.0},
|
||||
{value=0.5, weight=1.0},
|
||||
},
|
||||
sea_layers = {
|
||||
{block="base:water", height=-1},
|
||||
},
|
||||
layers = {
|
||||
{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},
|
||||
biomes = {
|
||||
plains = {
|
||||
parameters = {
|
||||
{value=0.5, weight=1.0},
|
||||
{value=0.5, weight=1.0},
|
||||
},
|
||||
sea_layers = {
|
||||
{block="base:water", height=-1},
|
||||
},
|
||||
layers = {
|
||||
{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},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,17 +11,17 @@
|
||||
|
||||
class LuaGeneratorScript : public GeneratorScript {
|
||||
scriptenv env;
|
||||
Biome biome;
|
||||
std::vector<Biome> biomes;
|
||||
uint biomeParameters;
|
||||
uint seaLevel;
|
||||
public:
|
||||
LuaGeneratorScript(
|
||||
scriptenv env,
|
||||
Biome biome,
|
||||
std::vector<Biome> biomes,
|
||||
uint biomeParameters,
|
||||
uint seaLevel)
|
||||
: env(std::move(env)),
|
||||
biome(std::move(biome)),
|
||||
biomes(std::move(biomes)),
|
||||
biomeParameters(biomeParameters),
|
||||
seaLevel(seaLevel)
|
||||
{}
|
||||
@ -46,16 +46,18 @@ public:
|
||||
}
|
||||
|
||||
void prepare(const Content* content) override {
|
||||
for (auto& layer : biome.groundLayers.layers) {
|
||||
layer.rt.id = content->blocks.require(layer.block).rt.id;
|
||||
}
|
||||
for (auto& layer : biome.seaLayers.layers) {
|
||||
layer.rt.id = content->blocks.require(layer.block).rt.id;
|
||||
for (auto& biome : biomes) {
|
||||
for (auto& layer : biome.groundLayers.layers) {
|
||||
layer.rt.id = content->blocks.require(layer.block).rt.id;
|
||||
}
|
||||
for (auto& layer : biome.seaLayers.layers) {
|
||||
layer.rt.id = content->blocks.require(layer.block).rt.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Biome& getBiome() const override {
|
||||
return biome;
|
||||
const std::vector<Biome>& getBiomes() const override {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
uint getBiomeParameters() const override {
|
||||
@ -160,14 +162,30 @@ std::unique_ptr<GeneratorScript> scripting::load_generator(
|
||||
|
||||
uint biomeParameters = lua::get_integer_field(L, "biome_parameters", 0, 0, 16);
|
||||
uint seaLevel = lua::get_integer_field(L, "sea_level", 0, 0, CHUNK_H);
|
||||
lua::requirefield(L, "biome");
|
||||
Biome biome = load_biome(L, "default", biomeParameters, -1);
|
||||
|
||||
std::vector<Biome> biomes;
|
||||
lua::requirefield(L, "biomes");
|
||||
if (!lua::istable(L, -1)) {
|
||||
throw std::runtime_error("'biomes' must be a table");
|
||||
}
|
||||
lua::pushnil(L);
|
||||
while (lua::next(L, -2)) {
|
||||
lua::pushvalue(L, -2);
|
||||
std::string biomeName = lua::tostring(L, -1);
|
||||
try {
|
||||
biomes.push_back(
|
||||
load_biome(L, biomeName, biomeParameters, -2));
|
||||
} catch (const std::runtime_error& err) {
|
||||
throw std::runtime_error("biome "+biomeName+": "+err.what());
|
||||
}
|
||||
lua::pop(L, 2);
|
||||
}
|
||||
lua::pop(L);
|
||||
|
||||
lua::pop(L);
|
||||
return std::make_unique<LuaGeneratorScript>(
|
||||
std::move(env),
|
||||
std::move(biome),
|
||||
std::move(biomes),
|
||||
biomeParameters,
|
||||
seaLevel);
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public:
|
||||
virtual std::shared_ptr<Heightmap> generateHeightmap(
|
||||
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0;
|
||||
|
||||
virtual const Biome& getBiome() const = 0;
|
||||
virtual const std::vector<Biome>& getBiomes() const = 0;
|
||||
|
||||
/// @return Number of biome parameters, that biome choosing depending on
|
||||
virtual uint getBiomeParameters() const = 0;
|
||||
|
||||
@ -56,7 +56,8 @@ void WorldGenerator::generate(
|
||||
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed
|
||||
);
|
||||
auto values = heightmap->getValues();
|
||||
const auto& biome = def.script->getBiome();
|
||||
const auto& biomes = def.script->getBiomes();
|
||||
const auto& biome = biomes.at(0);
|
||||
const auto& groundLayers = biome.groundLayers;
|
||||
const auto& seaLayers = biome.seaLayers;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user