mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-30 19:22:14 +00:00
Allow chunksize to be non-cubic
This commit is contained in:
parent
0deeb57d44
commit
630ca5daa0
5 changed files with 35 additions and 6 deletions
|
@ -6704,7 +6704,7 @@ Environment access
|
||||||
in that order.
|
in that order.
|
||||||
* `mapgen_limit` is an optional number. If it is absent, its value is that
|
* `mapgen_limit` is an optional number. If it is absent, its value is that
|
||||||
of the *active* mapgen setting `"mapgen_limit"`.
|
of the *active* mapgen setting `"mapgen_limit"`.
|
||||||
* `chunksize` is an optional number. If it is absent, its value is that
|
* `chunksize` is an optional number or vector. If it is absent, its value is that
|
||||||
of the *active* mapgen setting `"chunksize"`.
|
of the *active* mapgen setting `"chunksize"`.
|
||||||
* `core.get_mapgen_chunksize()`
|
* `core.get_mapgen_chunksize()`
|
||||||
* Returns the currently active chunksize of the mapgen, as a vector.
|
* Returns the currently active chunksize of the mapgen, as a vector.
|
||||||
|
|
|
@ -249,7 +249,7 @@ Example content:
|
||||||
|
|
||||||
# Map File Format
|
# Map File Format
|
||||||
|
|
||||||
Luanti maps consist of `MapBlock`s, chunks of 16x16x16 nodes.
|
Luanti maps consist of `MapBlock`s, each holds 16x16x16 nodes.
|
||||||
|
|
||||||
In addition to the bulk node data, `MapBlock`s stored on disk also contain
|
In addition to the bulk node data, `MapBlock`s stored on disk also contain
|
||||||
other things.
|
other things.
|
||||||
|
|
|
@ -1073,9 +1073,27 @@ void MapgenParams::readParams(const Settings *settings)
|
||||||
settings->getS16NoEx("mapgen_limit", mapgen_limit);
|
settings->getS16NoEx("mapgen_limit", mapgen_limit);
|
||||||
settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen);
|
settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen);
|
||||||
|
|
||||||
s16 tmp;
|
std::string chunksize_str;
|
||||||
settings->getS16NoEx("chunksize", tmp);
|
settings->getNoEx("chunksize", chunksize_str);
|
||||||
chunksize = v3s16(rangelim(tmp, 1, 24));
|
if (is_number(chunksize_str)) {
|
||||||
|
chunksize = v3s16(stoi(chunksize_str, 1, 999));
|
||||||
|
} else if (auto tmp = str_to_v3f(chunksize_str); tmp.has_value()) {
|
||||||
|
chunksize = v3s16(
|
||||||
|
rangelim(tmp->X, 1, 999),
|
||||||
|
rangelim(tmp->Y, 1, 999),
|
||||||
|
rangelim(tmp->Z, 1, 999)
|
||||||
|
);
|
||||||
|
} else if (!chunksize_str.empty()) {
|
||||||
|
errorstream << "MapgenParams: invalid chunksize \"" << chunksize_str
|
||||||
|
<< "\"" << std::endl;
|
||||||
|
}
|
||||||
|
// Finally check the volume limit
|
||||||
|
if (u32 v = chunksize.X * chunksize.Y * chunksize.Z; v > MAX_CHUNK_VOLUME) {
|
||||||
|
errorstream << "MapgenParams: chunksize " << chunksize
|
||||||
|
<< " is too big (volume > " << MAX_CHUNK_VOLUME
|
||||||
|
<< "), falling back to the default." << std::endl;
|
||||||
|
chunksize = v3s16(5);
|
||||||
|
}
|
||||||
|
|
||||||
delete bparams;
|
delete bparams;
|
||||||
bparams = BiomeManager::createBiomeParams(BIOMEGEN_ORIGINAL);
|
bparams = BiomeManager::createBiomeParams(BIOMEGEN_ORIGINAL);
|
||||||
|
@ -1092,9 +1110,15 @@ void MapgenParams::writeParams(Settings *settings) const
|
||||||
settings->setU64("seed", seed);
|
settings->setU64("seed", seed);
|
||||||
settings->setS16("water_level", water_level);
|
settings->setS16("water_level", water_level);
|
||||||
settings->setS16("mapgen_limit", mapgen_limit);
|
settings->setS16("mapgen_limit", mapgen_limit);
|
||||||
settings->setS16("chunksize", chunksize.X); // TODO
|
|
||||||
settings->setFlagStr("mg_flags", flags, flagdesc_mapgen);
|
settings->setFlagStr("mg_flags", flags, flagdesc_mapgen);
|
||||||
|
|
||||||
|
// Write as number if cubic, for backwards-compatibility
|
||||||
|
if (chunksize.X == chunksize.Y && chunksize.Y == chunksize.Z) {
|
||||||
|
settings->setS16("chunksize", chunksize.X);
|
||||||
|
} else {
|
||||||
|
settings->setV3F("chunksize", v3f::from(chunksize));
|
||||||
|
}
|
||||||
|
|
||||||
if (bparams)
|
if (bparams)
|
||||||
bparams->writeParams(settings);
|
bparams->writeParams(settings);
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,9 @@ struct MapgenParams {
|
||||||
virtual void setDefaultSettings(Settings *settings) {};
|
virtual void setDefaultSettings(Settings *settings) {};
|
||||||
|
|
||||||
s32 getSpawnRangeMax();
|
s32 getSpawnRangeMax();
|
||||||
|
|
||||||
|
// Mostly arbitrary limit
|
||||||
|
constexpr static u32 MAX_CHUNK_VOLUME = 2000;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -861,6 +861,8 @@ int ModApiMapgen::l_get_mapgen_edges(lua_State *L)
|
||||||
v3s16 chunksize;
|
v3s16 chunksize;
|
||||||
if (lua_isnumber(L, 2)) {
|
if (lua_isnumber(L, 2)) {
|
||||||
chunksize = v3s16(lua_tointeger(L, 2));
|
chunksize = v3s16(lua_tointeger(L, 2));
|
||||||
|
} else if (lua_istable(L, 2)) {
|
||||||
|
chunksize = check_v3s16(L, 2);
|
||||||
} else {
|
} else {
|
||||||
chunksize = params->chunksize;
|
chunksize = params->chunksize;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue