summaryrefslogtreecommitdiff
path: root/src/mapgen.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-06-03 19:57:02 +0200
committerGitHub <noreply@github.com>2017-06-03 19:57:02 +0200
commitc6d54411056da2dd563015c9f90c4c5c0863bc71 (patch)
tree5d3b6fcedf46ce066022dd575b9570352a50a0c1 /src/mapgen.cpp
parent72eec0f6f55b8515606de05d88717a78e978dd2a (diff)
downloadminetest-c6d54411056da2dd563015c9f90c4c5c0863bc71.tar.gz
minetest-c6d54411056da2dd563015c9f90c4c5c0863bc71.tar.bz2
minetest-c6d54411056da2dd563015c9f90c4c5c0863bc71.zip
Properly remove SAO when worldedges are overtaken (#5889)
* LuaEntitySAO: Remove beyond outermost mapchunk edges Based on a commit by, and with help from, nerzhul. Add 2 functions to class Mapgen: A function to calculate actual mapgen edges, called from the Mapgen constructor. A function called indirectly from content_sao.cpp per entity step to check SAO position is within mapgen edges. * Calculate borders from params not mapgen, which is not available everytime
Diffstat (limited to 'src/mapgen.cpp')
-rw-r--r--src/mapgen.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index dfe413a71..1f7f98621 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -317,7 +317,6 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax)
heightmap[index] = y;
}
}
- //printf("updateHeightmap: %dus\n", t.stop());
}
inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3s16 em)
@@ -1049,3 +1048,54 @@ void MapgenParams::writeParams(Settings *settings) const
if (bparams)
bparams->writeParams(settings);
}
+
+// Calculate edges of outermost generated mapchunks (less than
+// 'mapgen_limit'), and corresponding exact limits for SAO entities.
+void MapgenParams::calcMapgenEdges()
+{
+ // Central chunk offset, in blocks
+ s16 ccoff_b = -chunksize / 2;
+
+ // Chunksize, in nodes
+ s32 csize_n = chunksize * MAP_BLOCKSIZE;
+
+ // Minp/maxp of central chunk, in nodes
+ s16 ccmin = ccoff_b * MAP_BLOCKSIZE;
+ s16 ccmax = ccmin + csize_n - 1;
+ // Fullminp/fullmaxp of central chunk, in nodes
+ s16 ccfmin = ccmin - MAP_BLOCKSIZE;
+ s16 ccfmax = ccmax + MAP_BLOCKSIZE;
+ // Effective mapgen limit, in blocks
+ // Uses same calculation as ServerMap::blockpos_over_mapgen_limit(v3s16 p)
+ s16 mapgen_limit_b = rangelim(mapgen_limit,
+ 0, MAX_MAP_GENERATION_LIMIT) / MAP_BLOCKSIZE;
+ // Effective mapgen limits, in nodes
+ s16 mapgen_limit_min = -mapgen_limit_b * MAP_BLOCKSIZE;
+ s16 mapgen_limit_max = (mapgen_limit_b + 1) * MAP_BLOCKSIZE - 1;
+ // Number of complete chunks from central chunk fullminp/fullmaxp
+ // to effective mapgen limits.
+ s16 numcmin = MYMAX((ccfmin - mapgen_limit_min) / csize_n, 0);
+ s16 numcmax = MYMAX((mapgen_limit_max - ccfmax) / csize_n, 0);
+ // Mapgen edges, in nodes
+ // These values may be useful later as additional class members
+ s16 mapgen_edge_min = ccmin - numcmin * csize_n;
+ s16 mapgen_edge_max = ccmax + numcmax * csize_n;
+ // SAO position limits, in Irrlicht units
+ m_sao_limit_min = mapgen_edge_min * BS - 3.0f;
+ m_sao_limit_max = mapgen_edge_max * BS + 3.0f;
+}
+
+
+bool MapgenParams::saoPosOverLimit(const v3f &p)
+{
+ if (!m_sao_limit_calculated) {
+ calcMapgenEdges();
+ m_sao_limit_calculated = true;
+ }
+ return p.X < m_sao_limit_min ||
+ p.X > m_sao_limit_max ||
+ p.Y < m_sao_limit_min ||
+ p.Y > m_sao_limit_max ||
+ p.Z < m_sao_limit_min ||
+ p.Z > m_sao_limit_max;
+}