summaryrefslogtreecommitdiff
path: root/src/mapgen.cpp
diff options
context:
space:
mode:
authorparamat <paramat@users.noreply.github.com>2017-06-04 22:28:32 +0100
committerSmallJoker <mk939@ymail.com>2018-06-03 17:31:59 +0200
commit7aa52fe4e195ad9d66f0bda51688b81d31391346 (patch)
treeadd64962f2b2f6397cf32d5b9aac58d558b7e6af /src/mapgen.cpp
parent0664b5f77226b7a2308e85898295378e04158923 (diff)
downloadminetest-7aa52fe4e195ad9d66f0bda51688b81d31391346.tar.gz
minetest-7aa52fe4e195ad9d66f0bda51688b81d31391346.tar.bz2
minetest-7aa52fe4e195ad9d66f0bda51688b81d31391346.zip
(Re)spawn players within 'mapgen_limit'
Previously, findSpawnPos() did not take the 'mapgen_limit' setting into account, a small limit often resulted in a spawn out in the void. Use the recently added 'calcMapgenEdges()' to get max spawn range through a new mapgenParams function 'getSpawnRangeMax()'. Previously, when a player respawned into a world, 'objectpos_over_limit()' was used as a check, which was inaccurate. Use the recently added 'saoPosOverLimit()' to get exact mapgen edges. Also fix default value of 'm_sao_limit_min'.
Diffstat (limited to 'src/mapgen.cpp')
-rw-r--r--src/mapgen.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index 1f7f98621..1aa3be302 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -1053,12 +1053,13 @@ void MapgenParams::writeParams(Settings *settings) const
// 'mapgen_limit'), and corresponding exact limits for SAO entities.
void MapgenParams::calcMapgenEdges()
{
+ if (m_mapgen_edges_calculated)
+ return;
+
// 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;
@@ -1077,21 +1078,21 @@ void MapgenParams::calcMapgenEdges()
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;
+ mapgen_edge_min = ccmin - numcmin * csize_n;
+ 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;
+
+ m_mapgen_edges_calculated = true;
}
bool MapgenParams::saoPosOverLimit(const v3f &p)
{
- if (!m_sao_limit_calculated) {
+ if (!m_mapgen_edges_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 ||
@@ -1099,3 +1100,11 @@ bool MapgenParams::saoPosOverLimit(const v3f &p)
p.Z < m_sao_limit_min ||
p.Z > m_sao_limit_max;
}
+
+
+s32 MapgenParams::getSpawnRangeMax()
+{
+ calcMapgenEdges();
+
+ return MYMIN(-mapgen_edge_min, mapgen_edge_max);
+}