]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Raise max mapgen limit constant to align with mapblock size
authorsfan5 <sfan5@live.de>
Fri, 17 Dec 2021 16:21:14 +0000 (17:21 +0100)
committersfan5 <sfan5@live.de>
Sun, 30 Jan 2022 12:49:26 +0000 (13:49 +0100)
builtin/game/chat.lua
builtin/settingtypes.txt
minetest.conf.example
src/constants.h
src/defaultsettings.cpp
src/map.cpp
src/mapblock.h
src/unittest/CMakeLists.txt
src/unittest/test_map.cpp [new file with mode: 0644]

index 0f5739d5c0b28efb8f4d2676cbfd6d7c307b6bc2..b73e32876429ff96db7998dc27d9e119899cf47e 100644 (file)
@@ -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!")
index 9f01c67cf3b833278ac5ee6a2bbc6cae2ce2bbfc..42b45aa0021e640ec17d7a71488105d912925bf3 100644 (file)
@@ -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
index dd51fe259d99253b2e461db4cb67d03bd628a19f..7f4b5d9466d0ab64c510a94d319eb9992833cb74 100644 (file)
 #    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
index ed858912d2b9de601ba824104767b4e038804688..b9d4f8d70f2dae1d55ad46a7db291336755cf7ff 100644 (file)
@@ -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
index 9e4bb14b5e8aa7505776a2cf880838dc9bd7547f..600fc65f359b298164141a48e87f66e710957824 100644 (file)
@@ -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");
index 77031e17dfa4f885f5e301ccd69b924336b1912b..a11bbb96a27e50130885c318aca9c469ae6f2b07 100644 (file)
@@ -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
        */
index e729fdb1cc2eacf8300406b58845b275ac6feb9c..a86db7b70fd1115511055c9a4d9549d949910eee 100644 (file)
@@ -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 ||
index ce7921b559e2531ef12b594ad3cdd54898db237b..9364363644c1150f3f1e8ad47d8a1f951b38e55a 100644 (file)
@@ -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 (file)
index 0000000..82e55e1
--- /dev/null
@@ -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);
+}