diff options
-rw-r--r-- | builtin/game/chat.lua | 2 | ||||
-rw-r--r-- | builtin/settingtypes.txt | 2 | ||||
-rw-r--r-- | minetest.conf.example | 4 | ||||
-rw-r--r-- | src/constants.h | 2 | ||||
-rw-r--r-- | src/defaultsettings.cpp | 2 | ||||
-rw-r--r-- | src/map.cpp | 9 | ||||
-rw-r--r-- | src/mapblock.h | 2 | ||||
-rw-r--r-- | src/unittest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/unittest/test_map.cpp | 68 |
9 files changed, 77 insertions, 15 deletions
diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua index 0f5739d5c..b73e32876 100644 --- a/builtin/game/chat.lua +++ b/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!") diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 9f01c67cf..42b45aa00 100644 --- a/builtin/settingtypes.txt +++ b/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 diff --git a/minetest.conf.example b/minetest.conf.example index dd51fe259..7f4b5d946 100644 --- a/minetest.conf.example +++ b/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 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); +} |