Skip to content

Commit d3131ae

Browse files
committedMar 20, 2017
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.
1 parent 525d2a0 commit d3131ae

File tree

4 files changed

+44
-59
lines changed

4 files changed

+44
-59
lines changed
 

Diff for: ‎src/clientiface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ void RemoteClient::GetNextBlocks (
238238
continue;
239239

240240
/*
241-
Do not go over-limit
241+
Do not go over max mapgen limit
242242
*/
243-
if (blockpos_over_limit(p))
243+
if (blockpos_over_max_limit(p))
244244
continue;
245245

246246
// If this is true, inexistent block will be made from scratch

Diff for: ‎src/emerge.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void *EmergeThread::run()
606606
continue;
607607
}
608608

609-
if (blockpos_over_limit(pos))
609+
if (blockpos_over_max_limit(pos))
610610
continue;
611611

612612
bool allow_gen = bedata.flags & BLOCK_EMERGE_ALLOW_GEN;

Diff for: ‎src/map.cpp

+14-25
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,9 @@ bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data)
13801380
v3s16 full_bpmin = bpmin - extra_borders;
13811381
v3s16 full_bpmax = bpmax + extra_borders;
13821382

1383-
// Do nothing if not inside limits (+-1 because of neighbors)
1384-
if (blockpos_over_limit(full_bpmin) ||
1385-
blockpos_over_limit(full_bpmax))
1383+
// Do nothing if not inside mapgen limits (+-1 because of neighbors)
1384+
if (blockpos_over_mapgen_limit(full_bpmin) ||
1385+
blockpos_over_mapgen_limit(full_bpmax))
13861386
return false;
13871387

13881388
data->seed = getSeed();
@@ -1549,25 +1549,14 @@ ServerMapSector *ServerMap::createSector(v2s16 p2d)
15491549
#endif
15501550

15511551
/*
1552-
Do not create over-limit.
1553-
We are checking for any nodes of the mapblocks of the sector being beyond the limit.
1554-
A sector is a vertical column of mapblocks, so sectorpos is like a 2D blockpos.
1555-
1556-
At the negative limit we are checking for
1557-
block minimum nodepos < -mapgenlimit.
1558-
At the positive limit we are checking for
1559-
block maximum nodepos > mapgenlimit.
1560-
1561-
Block minimum nodepos = blockpos * mapblocksize.
1562-
Block maximum nodepos = (blockpos + 1) * mapblocksize - 1.
1552+
Do not create over max mapgen limit
15631553
*/
1564-
const u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
1565-
g_settings->getU16("map_generation_limit"));
1566-
if (p2d.X * MAP_BLOCKSIZE < -map_gen_limit
1567-
|| (p2d.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
1568-
|| p2d.Y * MAP_BLOCKSIZE < -map_gen_limit
1569-
|| (p2d.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit)
1570-
throw InvalidPositionException("createSector(): pos. over limit");
1554+
const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
1555+
if (p2d.X < -max_limit_bp ||
1556+
p2d.X > max_limit_bp ||
1557+
p2d.Y < -max_limit_bp ||
1558+
p2d.Y > max_limit_bp)
1559+
throw InvalidPositionException("createSector(): pos. over max mapgen limit");
15711560

15721561
/*
15731562
Generate blank sector
@@ -1708,10 +1697,10 @@ MapBlock * ServerMap::createBlock(v3s16 p)
17081697
FUNCTION_NAME, p.X, p.Y, p.Z);
17091698

17101699
/*
1711-
Do not create over-limit
1700+
Do not create over max mapgen limit
17121701
*/
1713-
if (blockpos_over_limit(p))
1714-
throw InvalidPositionException("createBlock(): pos. over limit");
1702+
if (blockpos_over_max_limit(p))
1703+
throw InvalidPositionException("createBlock(): pos. over max mapgen limit");
17151704

17161705
v2s16 p2d(p.X, p.Z);
17171706
s16 block_y = p.Y;
@@ -2655,7 +2644,7 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
26552644
if(block_data_inexistent)
26562645
{
26572646

2658-
if (load_if_inexistent && !blockpos_over_limit(p)) {
2647+
if (load_if_inexistent && !blockpos_over_max_limit(p)) {
26592648
ServerMap *svrmap = (ServerMap *)m_map;
26602649
block = svrmap->emergeBlock(p, false);
26612650
if (block == NULL)

Diff for: ‎src/mapblock.h

+27-31
Original file line numberDiff line numberDiff line change
@@ -669,41 +669,37 @@ typedef std::vector<MapBlock*> MapBlockVect;
669669

670670
inline bool objectpos_over_limit(v3f p)
671671
{
672-
// MAP_BLOCKSIZE must be subtracted to avoid an object being spawned just
673-
// within the map generation limit but in a block and sector that extend
674-
// beyond the map generation limit.
675-
// This avoids crashes caused by sector over limit in createSector().
676-
const float object_limit = (MYMIN(MAX_MAP_GENERATION_LIMIT,
677-
g_settings->getU16("map_generation_limit")) - MAP_BLOCKSIZE) * BS;
678-
return (p.X < -object_limit
679-
|| p.X > object_limit
680-
|| p.Y < -object_limit
681-
|| p.Y > object_limit
682-
|| p.Z < -object_limit
683-
|| p.Z > object_limit);
672+
const float max_limit_bs = MAX_MAP_GENERATION_LIMIT * BS;
673+
return p.X < -max_limit_bs ||
674+
p.X > max_limit_bs ||
675+
p.Y < -max_limit_bs ||
676+
p.Y > max_limit_bs ||
677+
p.Z < -max_limit_bs ||
678+
p.Z > max_limit_bs;
684679
}
685680

686-
/*
687-
We are checking for any node of the mapblock being beyond the limit.
688-
689-
At the negative limit we are checking for
690-
block minimum nodepos < -mapgenlimit.
691-
At the positive limit we are checking for
692-
block maximum nodepos > mapgenlimit.
681+
inline bool blockpos_over_max_limit(v3s16 p)
682+
{
683+
const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
684+
return p.X < -max_limit_bp ||
685+
p.X > max_limit_bp ||
686+
p.Y < -max_limit_bp ||
687+
p.Y > max_limit_bp ||
688+
p.Z < -max_limit_bp ||
689+
p.Z > max_limit_bp;
690+
}
693691

694-
Block minimum nodepos = blockpos * mapblocksize.
695-
Block maximum nodepos = (blockpos + 1) * mapblocksize - 1.
696-
*/
697-
inline bool blockpos_over_limit(v3s16 p)
692+
inline bool blockpos_over_mapgen_limit(v3s16 p)
698693
{
699-
const u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
700-
g_settings->getU16("map_generation_limit"));
701-
return (p.X * MAP_BLOCKSIZE < -map_gen_limit
702-
|| (p.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
703-
|| p.Y * MAP_BLOCKSIZE < -map_gen_limit
704-
|| (p.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
705-
|| p.Z * MAP_BLOCKSIZE < -map_gen_limit
706-
|| (p.Z + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit);
694+
const s16 mapgen_limit_bp = rangelim(
695+
g_settings->getS16("map_generation_limit"), 0, MAX_MAP_GENERATION_LIMIT) /
696+
MAP_BLOCKSIZE;
697+
return p.X < -mapgen_limit_bp ||
698+
p.X > mapgen_limit_bp ||
699+
p.Y < -mapgen_limit_bp ||
700+
p.Y > mapgen_limit_bp ||
701+
p.Z < -mapgen_limit_bp ||
702+
p.Z > mapgen_limit_bp;
707703
}
708704

709705
/*

0 commit comments

Comments
 (0)