Skip to content

Commit ddcf842

Browse files
committedJan 8, 2017
Map generation limit: Fix checks for block/sector over-limit
Fix the maths that check if any part of a mapblock or sector is over the set map_generation_limit. Therefore avoid the loading of any over-limit blocks that were previously generated when map_generation_limit was larger. The set limit can vary for a world because it is not yet a per-world mapgen parameter, even when it is sometimes it will be changed deliberately. Therefore avoid a player being returned to world centre if they re-enter a world while being over-limit. Fix the createSector() crash caused by a mob spawning over-limit in an over-limit mapblock
1 parent 1fee649 commit ddcf842

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed
 

‎src/map.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -2064,15 +2064,26 @@ ServerMapSector *ServerMap::createSector(v2s16 p2d)
20642064
return sector;
20652065
}
20662066
#endif
2067+
20672068
/*
2068-
Do not create over-limit
2069+
Do not create over-limit.
2070+
We are checking for any nodes of the mapblocks of the sector being beyond the limit.
2071+
A sector is a vertical column of mapblocks, so sectorpos is like a 2D blockpos.
2072+
2073+
At the negative limit we are checking for
2074+
block minimum nodepos < -mapgenlimit.
2075+
At the positive limit we are checking for
2076+
block maximum nodepos > mapgenlimit.
2077+
2078+
Block minimum nodepos = blockpos * mapblocksize.
2079+
Block maximum nodepos = (blockpos + 1) * mapblocksize - 1.
20692080
*/
20702081
const static u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
20712082
g_settings->getU16("map_generation_limit"));
2072-
if(p2d.X < -map_gen_limit / MAP_BLOCKSIZE
2073-
|| p2d.X > map_gen_limit / MAP_BLOCKSIZE
2074-
|| p2d.Y < -map_gen_limit / MAP_BLOCKSIZE
2075-
|| p2d.Y > map_gen_limit / MAP_BLOCKSIZE)
2083+
if (p2d.X * MAP_BLOCKSIZE < -map_gen_limit
2084+
|| (p2d.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
2085+
|| p2d.Y * MAP_BLOCKSIZE < -map_gen_limit
2086+
|| (p2d.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit)
20762087
throw InvalidPositionException("createSector(): pos. over limit");
20772088

20782089
/*

‎src/mapblock.h

+20-9
Original file line numberDiff line numberDiff line change
@@ -656,23 +656,34 @@ inline bool objectpos_over_limit(v3f p)
656656
const static float map_gen_limit_bs = MYMIN(MAX_MAP_GENERATION_LIMIT,
657657
g_settings->getU16("map_generation_limit")) * BS;
658658
return (p.X < -map_gen_limit_bs
659-
|| p.X > map_gen_limit_bs
659+
|| p.X > map_gen_limit_bs
660660
|| p.Y < -map_gen_limit_bs
661-
|| p.Y > map_gen_limit_bs
661+
|| p.Y > map_gen_limit_bs
662662
|| p.Z < -map_gen_limit_bs
663-
|| p.Z > map_gen_limit_bs);
663+
|| p.Z > map_gen_limit_bs);
664664
}
665665

666+
/*
667+
We are checking for any node of the mapblock being beyond the limit.
668+
669+
At the negative limit we are checking for
670+
block minimum nodepos < -mapgenlimit.
671+
At the positive limit we are checking for
672+
block maximum nodepos > mapgenlimit.
673+
674+
Block minimum nodepos = blockpos * mapblocksize.
675+
Block maximum nodepos = (blockpos + 1) * mapblocksize - 1.
676+
*/
666677
inline bool blockpos_over_limit(v3s16 p)
667678
{
668679
const static u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
669680
g_settings->getU16("map_generation_limit"));
670-
return (p.X < -map_gen_limit / MAP_BLOCKSIZE
671-
|| p.X > map_gen_limit / MAP_BLOCKSIZE
672-
|| p.Y < -map_gen_limit / MAP_BLOCKSIZE
673-
|| p.Y > map_gen_limit / MAP_BLOCKSIZE
674-
|| p.Z < -map_gen_limit / MAP_BLOCKSIZE
675-
|| p.Z > map_gen_limit / MAP_BLOCKSIZE);
681+
return (p.X * MAP_BLOCKSIZE < -map_gen_limit
682+
|| (p.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
683+
|| p.Y * MAP_BLOCKSIZE < -map_gen_limit
684+
|| (p.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
685+
|| p.Z * MAP_BLOCKSIZE < -map_gen_limit
686+
|| (p.Z + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit);
676687
}
677688

678689
/*

0 commit comments

Comments
 (0)
Please sign in to comment.