aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapgen')
-rw-r--r--src/mapgen/mapgen.cpp31
-rw-r--r--src/mapgen/mapgen.h6
2 files changed, 20 insertions, 17 deletions
diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp
index 0639f149f..ce281e2c1 100644
--- a/src/mapgen/mapgen.cpp
+++ b/src/mapgen/mapgen.cpp
@@ -1063,9 +1063,20 @@ void MapgenParams::writeParams(Settings *settings) const
}
-// Calculate exact edges of the outermost mapchunks that are within the
-// set 'mapgen_limit'.
-void MapgenParams::calcMapgenEdges()
+s32 MapgenParams::getSpawnRangeMax()
+{
+ if (!m_mapgen_edges_calculated) {
+ std::pair<s16, s16> edges = get_mapgen_edges(mapgen_limit, chunksize);
+ mapgen_edge_min = edges.first;
+ mapgen_edge_max = edges.second;
+ m_mapgen_edges_calculated = true;
+ }
+
+ return MYMIN(-mapgen_edge_min, mapgen_edge_max);
+}
+
+
+std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize)
{
// Central chunk offset, in blocks
s16 ccoff_b = -chunksize / 2;
@@ -1089,17 +1100,5 @@ 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
- mapgen_edge_min = ccmin - numcmin * csize_n;
- mapgen_edge_max = ccmax + numcmax * csize_n;
-
- m_mapgen_edges_calculated = true;
-}
-
-
-s32 MapgenParams::getSpawnRangeMax()
-{
- if (!m_mapgen_edges_calculated)
- calcMapgenEdges();
-
- return MYMIN(-mapgen_edge_min, mapgen_edge_max);
+ return std::pair<s16, s16>(ccmin - numcmin * csize_n, ccmax + numcmax * csize_n);
}
diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h
index ef5de6029..b61608039 100644
--- a/src/mapgen/mapgen.h
+++ b/src/mapgen/mapgen.h
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodedef.h"
#include "util/string.h"
#include "util/container.h"
+#include <utility>
#define MAPGEN_DEFAULT MAPGEN_V7
#define MAPGEN_DEFAULT_NAME "v7"
@@ -139,7 +140,6 @@ struct MapgenParams {
s32 getSpawnRangeMax();
private:
- void calcMapgenEdges();
bool m_mapgen_edges_calculated = false;
};
@@ -329,3 +329,7 @@ protected:
s16 dungeon_ymin;
s16 dungeon_ymax;
};
+
+// Calculate exact edges of the outermost mapchunks that are within the set
+// mapgen_limit. Returns the minimum and maximum edges in nodes in that order.
+std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize);