From bcc185f83fc007bcf85c884a90c0eac09c30109c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 9 May 2017 16:30:30 +0200 Subject: [PATCH] Lua mapgen optimizations, hopefully prevent OOM --- mods/MAPGEN/mcl_mapgen_core/init.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index de06107da3..9432d7a636 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -810,6 +810,11 @@ else minetest.set_mapgen_setting("mg_flags", "caves,nodungeons,decorations,light", true) end +-- Perlin noise objects +local perlin + +-- Generate clay and structures +-- TODO: Try to use more efficient structure generating code minetest.register_on_generated(function(minp, maxp, seed) if maxp.y >= 2 and minp.y <= 0 then -- Generate clay @@ -850,7 +855,7 @@ minetest.register_on_generated(function(minp, maxp, seed) end if maxp.y >= 3 and minp.y <= 64 then -- Generate desert temples - local perlin1 = minetest.get_perlin(329, 3, 0.6, 100) + perlin = perlin or minetest.get_perlin(329, 3, 0.6, 100) -- Assume X and Z lengths are equal local divlen = 5 local divs = (maxp.x-minp.x)/divlen+1; @@ -861,7 +866,7 @@ minetest.register_on_generated(function(minp, maxp, seed) local x1 = minp.x + math.floor((divx+1)*divlen) local z1 = minp.z + math.floor((divz+1)*divlen) -- Determine amount from perlin noise - local amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 9) + local amount = math.floor(perlin:get2d({x=x0, y=z0}) * 9) -- Find random positions based on this random local pr = PseudoRandom(seed+1) for i=0, amount do @@ -903,11 +908,13 @@ end) local BEDROCK_MIN = mcl_vars.mg_bedrock_overworld_min local BEDROCK_MAX = mcl_vars.mg_bedrock_overworld_max --- Below the bedrock, generate air/void +-- Buffer for LuaVoxelManip +local lvm_buffer = {} +-- Below the bedrock, generate air/void minetest.register_on_generated(function(minp, maxp) local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - local data = vm:get_data() + local data = vm:get_data(lvm_buffer) local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) local lvm_used = false