aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/constants.h2
-rw-r--r--src/defaultsettings.cpp2
-rw-r--r--src/map.cpp9
-rw-r--r--src/mapblock.h2
-rw-r--r--src/unittest/CMakeLists.txt1
-rw-r--r--src/unittest/test_map.cpp68
6 files changed, 73 insertions, 11 deletions
diff --git a/src/constants.h b/src/constants.h
index ed858912d..b9d4f8d70 100644
--- a/src/constants.h
+++ b/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
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 9e4bb14b5..600fc65f3 100644
--- a/src/defaultsettings.cpp
+++ b/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");
diff --git a/src/map.cpp b/src/map.cpp
index 77031e17d..a11bbb96a 100644
--- a/src/map.cpp
+++ b/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
*/
diff --git a/src/mapblock.h b/src/mapblock.h
index e729fdb1c..a86db7b70 100644
--- a/src/mapblock.h
+++ b/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 ||
diff --git a/src/unittest/CMakeLists.txt b/src/unittest/CMakeLists.txt
index ce7921b55..936436364 100644
--- a/src/unittest/CMakeLists.txt
+++ b/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
diff --git a/src/unittest/test_map.cpp b/src/unittest/test_map.cpp
new file mode 100644
index 000000000..82e55e1aa
--- /dev/null
+++ b/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);
+}