Browse Source

Raise max mapgen limit constant to align with mapblock size

sfan5 2 years ago
parent
commit
a9bccb964f

+ 1 - 1
builtin/game/chat.lua

@@ -524,7 +524,7 @@ end
 
 -- Teleports player <name> to <p> if possible
 local function teleport_to_pos(name, p)
-	local lm = 31000
+	local lm = 31007 -- equals MAX_MAP_GENERATION_LIMIT in C++
 	if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm
 			or p.z < -lm or p.z > lm then
 		return false, S("Cannot teleport out of map bounds!")

+ 1 - 1
builtin/settingtypes.txt

@@ -1459,7 +1459,7 @@ max_block_generate_distance (Max block generate distance) int 10
 #    Limit of map generation, in nodes, in all 6 directions from (0, 0, 0).
 #    Only mapchunks completely within the mapgen limit are generated.
 #    Value is stored per-world.
-mapgen_limit (Map generation limit) int 31000 0 31000
+mapgen_limit (Map generation limit) int 31007 0 31007
 
 #    Global map generation attributes.
 #    In Mapgen v6 the 'decorations' flag controls all decorations except trees

+ 2 - 2
minetest.conf.example

@@ -1767,8 +1767,8 @@
 #    Limit of map generation, in nodes, in all 6 directions from (0, 0, 0).
 #    Only mapchunks completely within the mapgen limit are generated.
 #    Value is stored per-world.
-#    type: int min: 0 max: 31000
-# mapgen_limit = 31000
+#    type: int min: 0 max: 31007
+# mapgen_limit = 31007
 
 #    Global map generation attributes.
 #    In Mapgen v6 the 'decorations' flag controls all decorations except trees

+ 1 - 1
src/constants.h

@@ -64,7 +64,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 // I really don't want to make every algorithm to check if it's going near
 // the limit or not, so this is lower.
 // This is the maximum value the setting map_generation_limit can be
-#define MAX_MAP_GENERATION_LIMIT (31000)
+#define MAX_MAP_GENERATION_LIMIT (31007)
 
 // Size of node in floating-point units
 // The original idea behind this is to disallow plain casts between

+ 1 - 1
src/defaultsettings.cpp

@@ -435,7 +435,7 @@ void set_default_settings()
 	// Mapgen
 	settings->setDefault("mg_name", "v7");
 	settings->setDefault("water_level", "1");
-	settings->setDefault("mapgen_limit", "31000");
+	settings->setDefault("mapgen_limit", "31007");
 	settings->setDefault("chunksize", "5");
 	settings->setDefault("fixed_map_seed", "");
 	settings->setDefault("max_block_generate_distance", "10");

+ 1 - 8
src/map.cpp

@@ -1444,11 +1444,7 @@ MapSector *ServerMap::createSector(v2s16 p2d)
 	/*
 		Do not create over max mapgen limit
 	*/
-	const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
-	if (p2d.X < -max_limit_bp ||
-			p2d.X >  max_limit_bp ||
-			p2d.Y < -max_limit_bp ||
-			p2d.Y >  max_limit_bp)
+	if (blockpos_over_max_limit(v3s16(p2d.X, 0, p2d.Y)))
 		throw InvalidPositionException("createSector(): pos. over max mapgen limit");
 
 	/*
@@ -1457,9 +1453,6 @@ MapSector *ServerMap::createSector(v2s16 p2d)
 
 	sector = new MapSector(this, p2d, m_gamedef);
 
-	// Sector position on map in nodes
-	//v2s16 nodepos2d = p2d * MAP_BLOCKSIZE;
-
 	/*
 		Insert to container
 	*/

+ 1 - 1
src/mapblock.h

@@ -601,7 +601,7 @@ typedef std::vector<MapBlock*> MapBlockVect;
 
 inline bool objectpos_over_limit(v3f p)
 {
-	const float max_limit_bs = MAX_MAP_GENERATION_LIMIT * BS;
+	const float max_limit_bs = (MAX_MAP_GENERATION_LIMIT + 0.5f) * BS;
 	return p.X < -max_limit_bs ||
 		p.X >  max_limit_bs ||
 		p.Y < -max_limit_bs ||

+ 1 - 0
src/unittest/CMakeLists.txt

@@ -11,6 +11,7 @@ set (UNITTEST_SRCS
 	${CMAKE_CURRENT_SOURCE_DIR}/test_filepath.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/test_inventory.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/test_irrptr.cpp
+	${CMAKE_CURRENT_SOURCE_DIR}/test_map.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/test_map_settings_manager.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/test_mapnode.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/test_modchannels.cpp

+ 68 - 0
src/unittest/test_map.cpp

@@ -0,0 +1,68 @@
+/*
+Minetest
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "test.h"
+
+#include <cstdio>
+#include "mapblock.h"
+
+class TestMap : public TestBase
+{
+public:
+	TestMap() { TestManager::registerTestModule(this); }
+	const char *getName() { return "TestMap"; }
+
+	void runTests(IGameDef *gamedef);
+
+	void testMaxMapgenLimit();
+};
+
+static TestMap g_test_instance;
+
+void TestMap::runTests(IGameDef *gamedef)
+{
+	TEST(testMaxMapgenLimit);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+void TestMap::testMaxMapgenLimit()
+{
+	// limit must end on a mapblock boundary
+	UASSERTEQ(int, MAX_MAP_GENERATION_LIMIT % MAP_BLOCKSIZE, MAP_BLOCKSIZE - 1);
+
+	// objectpos_over_limit should do exactly this except the last node
+	// actually spans from LIMIT-0.5 to LIMIT+0.5
+	float limit_times_bs = MAX_MAP_GENERATION_LIMIT * BS;
+	UASSERT(objectpos_over_limit(v3f(limit_times_bs-BS/2)) == false);
+	UASSERT(objectpos_over_limit(v3f(limit_times_bs)) == false);
+	UASSERT(objectpos_over_limit(v3f(limit_times_bs+BS/2)) == false);
+	UASSERT(objectpos_over_limit(v3f(limit_times_bs+BS)) == true);
+
+	UASSERT(objectpos_over_limit(v3f(-limit_times_bs+BS/2)) == false);
+	UASSERT(objectpos_over_limit(v3f(-limit_times_bs)) == false);
+	UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS/2)) == false);
+	UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS)) == true);
+
+	// blockpos_over_max_limit
+	s16 limit_block = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
+	UASSERT(blockpos_over_max_limit(v3s16(limit_block)) == false);
+	UASSERT(blockpos_over_max_limit(v3s16(limit_block+1)) == true);
+	UASSERT(blockpos_over_max_limit(v3s16(-limit_block)) == false);
+	UASSERT(blockpos_over_max_limit(v3s16(-limit_block-1)) == true);
+}