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:
parent
525d2a0d51
commit
d3131aeae7
@ -238,9 +238,9 @@ void RemoteClient::GetNextBlocks (
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Do not go over-limit
|
Do not go over max mapgen limit
|
||||||
*/
|
*/
|
||||||
if (blockpos_over_limit(p))
|
if (blockpos_over_max_limit(p))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If this is true, inexistent block will be made from scratch
|
// If this is true, inexistent block will be made from scratch
|
||||||
|
@ -606,7 +606,7 @@ void *EmergeThread::run()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockpos_over_limit(pos))
|
if (blockpos_over_max_limit(pos))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool allow_gen = bedata.flags & BLOCK_EMERGE_ALLOW_GEN;
|
bool allow_gen = bedata.flags & BLOCK_EMERGE_ALLOW_GEN;
|
||||||
|
39
src/map.cpp
39
src/map.cpp
@ -1380,9 +1380,9 @@ bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data)
|
|||||||
v3s16 full_bpmin = bpmin - extra_borders;
|
v3s16 full_bpmin = bpmin - extra_borders;
|
||||||
v3s16 full_bpmax = bpmax + extra_borders;
|
v3s16 full_bpmax = bpmax + extra_borders;
|
||||||
|
|
||||||
// Do nothing if not inside limits (+-1 because of neighbors)
|
// Do nothing if not inside mapgen limits (+-1 because of neighbors)
|
||||||
if (blockpos_over_limit(full_bpmin) ||
|
if (blockpos_over_mapgen_limit(full_bpmin) ||
|
||||||
blockpos_over_limit(full_bpmax))
|
blockpos_over_mapgen_limit(full_bpmax))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
data->seed = getSeed();
|
data->seed = getSeed();
|
||||||
@ -1549,25 +1549,14 @@ ServerMapSector *ServerMap::createSector(v2s16 p2d)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Do not create over-limit.
|
Do not create over max mapgen limit
|
||||||
We are checking for any nodes of the mapblocks of the sector being beyond the limit.
|
|
||||||
A sector is a vertical column of mapblocks, so sectorpos is like a 2D blockpos.
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
*/
|
||||||
const u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
|
const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
|
||||||
g_settings->getU16("map_generation_limit"));
|
if (p2d.X < -max_limit_bp ||
|
||||||
if (p2d.X * MAP_BLOCKSIZE < -map_gen_limit
|
p2d.X > max_limit_bp ||
|
||||||
|| (p2d.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
|
p2d.Y < -max_limit_bp ||
|
||||||
|| p2d.Y * MAP_BLOCKSIZE < -map_gen_limit
|
p2d.Y > max_limit_bp)
|
||||||
|| (p2d.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit)
|
throw InvalidPositionException("createSector(): pos. over max mapgen limit");
|
||||||
throw InvalidPositionException("createSector(): pos. over limit");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generate blank sector
|
Generate blank sector
|
||||||
@ -1708,10 +1697,10 @@ MapBlock * ServerMap::createBlock(v3s16 p)
|
|||||||
FUNCTION_NAME, p.X, p.Y, p.Z);
|
FUNCTION_NAME, p.X, p.Y, p.Z);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Do not create over-limit
|
Do not create over max mapgen limit
|
||||||
*/
|
*/
|
||||||
if (blockpos_over_limit(p))
|
if (blockpos_over_max_limit(p))
|
||||||
throw InvalidPositionException("createBlock(): pos. over limit");
|
throw InvalidPositionException("createBlock(): pos. over max mapgen limit");
|
||||||
|
|
||||||
v2s16 p2d(p.X, p.Z);
|
v2s16 p2d(p.X, p.Z);
|
||||||
s16 block_y = p.Y;
|
s16 block_y = p.Y;
|
||||||
@ -2655,7 +2644,7 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
|
|||||||
if(block_data_inexistent)
|
if(block_data_inexistent)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (load_if_inexistent && !blockpos_over_limit(p)) {
|
if (load_if_inexistent && !blockpos_over_max_limit(p)) {
|
||||||
ServerMap *svrmap = (ServerMap *)m_map;
|
ServerMap *svrmap = (ServerMap *)m_map;
|
||||||
block = svrmap->emergeBlock(p, false);
|
block = svrmap->emergeBlock(p, false);
|
||||||
if (block == NULL)
|
if (block == NULL)
|
||||||
|
@ -669,41 +669,37 @@ typedef std::vector<MapBlock*> MapBlockVect;
|
|||||||
|
|
||||||
inline bool objectpos_over_limit(v3f p)
|
inline bool objectpos_over_limit(v3f p)
|
||||||
{
|
{
|
||||||
// MAP_BLOCKSIZE must be subtracted to avoid an object being spawned just
|
const float max_limit_bs = MAX_MAP_GENERATION_LIMIT * BS;
|
||||||
// within the map generation limit but in a block and sector that extend
|
return p.X < -max_limit_bs ||
|
||||||
// beyond the map generation limit.
|
p.X > max_limit_bs ||
|
||||||
// This avoids crashes caused by sector over limit in createSector().
|
p.Y < -max_limit_bs ||
|
||||||
const float object_limit = (MYMIN(MAX_MAP_GENERATION_LIMIT,
|
p.Y > max_limit_bs ||
|
||||||
g_settings->getU16("map_generation_limit")) - MAP_BLOCKSIZE) * BS;
|
p.Z < -max_limit_bs ||
|
||||||
return (p.X < -object_limit
|
p.Z > max_limit_bs;
|
||||||
|| p.X > object_limit
|
|
||||||
|| p.Y < -object_limit
|
|
||||||
|| p.Y > object_limit
|
|
||||||
|| p.Z < -object_limit
|
|
||||||
|| p.Z > object_limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
inline bool blockpos_over_max_limit(v3s16 p)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
const u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
|
const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
|
||||||
g_settings->getU16("map_generation_limit"));
|
return p.X < -max_limit_bp ||
|
||||||
return (p.X * MAP_BLOCKSIZE < -map_gen_limit
|
p.X > max_limit_bp ||
|
||||||
|| (p.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
|
p.Y < -max_limit_bp ||
|
||||||
|| p.Y * MAP_BLOCKSIZE < -map_gen_limit
|
p.Y > max_limit_bp ||
|
||||||
|| (p.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
|
p.Z < -max_limit_bp ||
|
||||||
|| p.Z * MAP_BLOCKSIZE < -map_gen_limit
|
p.Z > max_limit_bp;
|
||||||
|| (p.Z + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit);
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user