Allow setting chunksize in core.set_mapgen_params
authorkwolekr <kwolekr@minetest.net>
Sun, 4 Oct 2015 21:26:08 +0000 (17:26 -0400)
committerkwolekr <kwolekr@minetest.net>
Sun, 4 Oct 2015 21:26:08 +0000 (17:26 -0400)
src/emerge.cpp
src/emerge.h
src/script/lua_api/l_mapgen.cpp

index bb2590641419cc3bf1ce5a30e86d8ad560dc7e83..92edd2007b03121531d6d8b36c7e0d0e5c6e0d90 100644 (file)
@@ -256,6 +256,12 @@ void EmergeManager::stopThreads()
 }
 
 
+bool EmergeManager::isRunning()
+{
+       return m_threads_active;
+}
+
+
 bool EmergeManager::enqueueBlockEmerge(
        u16 peer_id,
        v3s16 blockpos,
index b72b2a2c35fee3e148e8e53a3fde5db86d6b5c78..47ff218b85a25bc8928db6fbbb2ba4c4ebea1ad9 100644 (file)
@@ -115,6 +115,7 @@ public:
 
        void startThreads();
        void stopThreads();
+       bool isRunning();
 
        bool enqueueBlockEmerge(
                u16 peer_id,
index 44af7892f76689cfb1403b2b0027932bc9bf87ad..cfa216a3d20a226cedd5d57349cf264f01a9c8b5 100644 (file)
@@ -619,7 +619,11 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
        if (!lua_istable(L, 1))
                return 0;
 
-       MapgenParams *params = &getServer(L)->getEmergeManager()->params;
+       EmergeManager *emerge = getServer(L)->getEmergeManager();
+       if (emerge->isRunning())
+               throw LuaError("Cannot set parameters while mapgen is running");
+
+       MapgenParams *params = &emerge->params;
        u32 flags = 0, flagmask = 0;
 
        lua_getfield(L, 1, "mgname");
@@ -637,6 +641,10 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
        if (lua_isnumber(L, -1))
                params->water_level = lua_tointeger(L, -1);
 
+       lua_getfield(L, 1, "chunksize");
+       if (lua_isnumber(L, -1))
+               params->chunksize = lua_tointeger(L, -1);
+
        warn_if_field_exists(L, 1, "flagmask",
                "Deprecated: flags field now includes unset flags.");
        lua_getfield(L, 1, "flagmask");