1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Add minetest.get_mapgen_edges (#12999)

This commit is contained in:
Jude Melton-Houghton 2022-12-03 10:40:46 -05:00 committed by GitHub
parent e84d259ec7
commit b3ffc4b327
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 17 deletions

View file

@ -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);
}

View file

@ -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);