add biome 'parameters' field
This commit is contained in:
parent
efa27496ab
commit
c3831afd19
@ -5,6 +5,10 @@ sea_level = 64
|
||||
biome_parameters = 2
|
||||
|
||||
biome = {
|
||||
parameters = {
|
||||
{value=0.5, weight=1.0},
|
||||
{value=0.5, weight=1.0},
|
||||
},
|
||||
sea_layers = {
|
||||
{block="base:water", height=-1},
|
||||
},
|
||||
|
||||
@ -566,7 +566,7 @@ namespace lua {
|
||||
) {
|
||||
requirefield(L, name, idx);
|
||||
auto value = require_string(L, -1);
|
||||
lua::pop(L);
|
||||
pop(L);
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -575,7 +575,16 @@ namespace lua {
|
||||
) {
|
||||
requirefield(L, name, idx);
|
||||
auto value = tointeger(L, -1);
|
||||
lua::pop(L);
|
||||
pop(L);
|
||||
return value;
|
||||
}
|
||||
|
||||
inline Number require_number_field(
|
||||
lua::State* L, const std::string& name, int idx=-1
|
||||
) {
|
||||
requirefield(L, name, idx);
|
||||
auto value = tonumber(L, -1);
|
||||
pop(L);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@ -112,9 +112,25 @@ static inline BlocksLayers load_layers(
|
||||
}
|
||||
|
||||
static inline Biome load_biome(
|
||||
lua::State* L, const std::string& name, int idx
|
||||
lua::State* L, const std::string& name, uint parametersCount, int idx
|
||||
) {
|
||||
lua::pushvalue(L, idx);
|
||||
|
||||
std::vector<BiomeParameter> parameters(parametersCount);
|
||||
lua::requirefield(L, "parameters");
|
||||
if (lua::objlen(L, -1) < parametersCount) {
|
||||
throw std::runtime_error(
|
||||
std::to_string(parametersCount)+" parameters expected");
|
||||
}
|
||||
for (uint i = 1; i <= parametersCount; i++) {
|
||||
lua::rawgeti(L, i);
|
||||
float value = lua::require_number_field(L, "value");
|
||||
float weight = lua::require_number_field(L, "weight");
|
||||
parameters.push_back(BiomeParameter {value, weight});
|
||||
lua::pop(L);
|
||||
}
|
||||
lua::pop(L);
|
||||
|
||||
BlocksLayers groundLayers;
|
||||
BlocksLayers seaLayers;
|
||||
try {
|
||||
@ -124,7 +140,11 @@ static inline Biome load_biome(
|
||||
throw std::runtime_error("biome "+name+": "+err.what());
|
||||
}
|
||||
lua::pop(L);
|
||||
return Biome {name, std::move(groundLayers), std::move(seaLayers)};
|
||||
return Biome {
|
||||
name,
|
||||
std::move(parameters),
|
||||
std::move(groundLayers),
|
||||
std::move(seaLayers)};
|
||||
}
|
||||
|
||||
std::unique_ptr<GeneratorScript> scripting::load_generator(
|
||||
@ -141,7 +161,7 @@ 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", -1);
|
||||
Biome biome = load_biome(L, "default", biomeParameters, -1);
|
||||
lua::pop(L);
|
||||
|
||||
lua::pop(L);
|
||||
|
||||
@ -33,8 +33,17 @@ struct BlocksLayers {
|
||||
uint lastLayersHeight;
|
||||
};
|
||||
|
||||
struct BiomeParameter {
|
||||
/// @brief Central parameter value for the biome
|
||||
float origin;
|
||||
/// @brief Parameter score multiplier
|
||||
/// (the higher the value, the greater the chance of biome choosing)
|
||||
float weight;
|
||||
};
|
||||
|
||||
struct Biome {
|
||||
std::string name;
|
||||
std::vector<BiomeParameter> parameters;
|
||||
BlocksLayers groundLayers;
|
||||
BlocksLayers seaLayers;
|
||||
};
|
||||
@ -67,6 +76,7 @@ public:
|
||||
|
||||
/// @brief Generator information
|
||||
struct GeneratorDef {
|
||||
/// @brief Generator full name - packid:name
|
||||
std::string name;
|
||||
std::unique_ptr<GeneratorScript> script;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user