1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Map generation limit: Rewrite

The previous implementation applied the setting to blockpos_over_limit(),
objectpos_over_limit() and in createSector(), causing many bugs near the
world edge.

First revert the previous implementation.
Rename blockpos_over_limit() to blockpos_over_max_limit() for clarity.
Add a new function to mapblock.h called blockpos_over_mapgen_limit() that
checks against the map_generation_limit setting, and call this only from
the code that decides where mapgen stops.
Use MAX_MAP_GENERATION_LIMIT in objectpos_over_limit() to reduce the
chance of bugs, there is no need to use map_generation_limit here.
This commit is contained in:
paramat 2017-03-13 21:35:29 +00:00
parent 525d2a0d51
commit d3131aeae7
4 changed files with 45 additions and 60 deletions

View file

@ -669,41 +669,37 @@ typedef std::vector<MapBlock*> MapBlockVect;
inline bool objectpos_over_limit(v3f p)
{
// MAP_BLOCKSIZE must be subtracted to avoid an object being spawned just
// within the map generation limit but in a block and sector that extend
// beyond the map generation limit.
// This avoids crashes caused by sector over limit in createSector().
const float object_limit = (MYMIN(MAX_MAP_GENERATION_LIMIT,
g_settings->getU16("map_generation_limit")) - MAP_BLOCKSIZE) * BS;
return (p.X < -object_limit
|| p.X > object_limit
|| p.Y < -object_limit
|| p.Y > object_limit
|| p.Z < -object_limit
|| p.Z > object_limit);
const float max_limit_bs = MAX_MAP_GENERATION_LIMIT * BS;
return p.X < -max_limit_bs ||
p.X > max_limit_bs ||
p.Y < -max_limit_bs ||
p.Y > max_limit_bs ||
p.Z < -max_limit_bs ||
p.Z > max_limit_bs;
}
/*
We are checking for any node of the mapblock being beyond the limit.
At the negative limit we are checking for
block minimum nodepos < -mapgenlimit.
At the positive limit we are checking for
block maximum nodepos > mapgenlimit.
Block minimum nodepos = blockpos * mapblocksize.
Block maximum nodepos = (blockpos + 1) * mapblocksize - 1.
*/
inline bool blockpos_over_limit(v3s16 p)
inline bool blockpos_over_max_limit(v3s16 p)
{
const u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
g_settings->getU16("map_generation_limit"));
return (p.X * MAP_BLOCKSIZE < -map_gen_limit
|| (p.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
|| p.Y * MAP_BLOCKSIZE < -map_gen_limit
|| (p.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
|| p.Z * MAP_BLOCKSIZE < -map_gen_limit
|| (p.Z + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit);
const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
return p.X < -max_limit_bp ||
p.X > max_limit_bp ||
p.Y < -max_limit_bp ||
p.Y > max_limit_bp ||
p.Z < -max_limit_bp ||
p.Z > max_limit_bp;
}
inline bool blockpos_over_mapgen_limit(v3s16 p)
{
const s16 mapgen_limit_bp = rangelim(
g_settings->getS16("map_generation_limit"), 0, MAX_MAP_GENERATION_LIMIT) /
MAP_BLOCKSIZE;
return p.X < -mapgen_limit_bp ||
p.X > mapgen_limit_bp ||
p.Y < -mapgen_limit_bp ||
p.Y > mapgen_limit_bp ||
p.Z < -mapgen_limit_bp ||
p.Z > mapgen_limit_bp;
}
/*