From e81927ece8f42843e82c4da54caefc6de32dd9eb Mon Sep 17 00:00:00 2001 From: Mat Date: Mon, 28 Jul 2014 01:06:32 +0100 Subject: [PATCH] Faster mapgen: use voxelmanip for ungen check, scanning chunk below --- README.txt | 4 ++-- functions.lua | 12 ++++++------ init.lua | 46 +++++++++++++++++++++++----------------------- nodes.lua | 8 ++++++-- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/README.txt b/README.txt index 313e15d..ea82649 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -fracture 0.1.6 by paramat +fracture 0.1.7 by paramat For latest stable Minetest back to 0.4.8 Depends default -Licenses: code WTFPL \ No newline at end of file +Licenses: code WTFPL diff --git a/functions.lua b/functions.lua index 79f369e..554011c 100644 --- a/functions.lua +++ b/functions.lua @@ -130,12 +130,12 @@ if SINGLENODE then minetest.set_mapgen_params({mgname="singlenode", water_level=-32000}) end) - -- Spawn player + -- Spawn player. Dependant on chunk size = 5 mapblocks function spawnplayer(player) local DENOFF = -0.4 local TSTONE = 0.02 - local SCAT = 8 -- Player scatter from world centre in chunks (80 nodes). + local PSCA = 8 -- Player scatter from world centre in chunks (80 nodes). local xsp local ysp local zsp @@ -157,9 +157,9 @@ if SINGLENODE then } for chunk = 1, 64 do print ("[fracture] searching for spawn "..chunk) - local x0 = 80 * math.random(-SCAT, SCAT) - 32 - local z0 = 80 * math.random(-SCAT, SCAT) - 32 - local y0 = 80 * math.random(-SCAT, SCAT) - 32 + local x0 = 80 * math.random(-PSCA, PSCA) - 32 + local z0 = 80 * math.random(-PSCA, PSCA) - 32 + local y0 = 80 * math.random(-PSCA, PSCA) - 32 local x1 = x0 + 79 local z1 = z0 + 79 local y1 = y0 + 79 @@ -262,4 +262,4 @@ minetest.register_abm({ vm:write_to_map() vm:update_map() end, -}) \ No newline at end of file +}) diff --git a/init.lua b/init.lua index 115a709..b049376 100644 --- a/init.lua +++ b/init.lua @@ -1,8 +1,10 @@ --- fracture 0.1.6 by paramat +-- fracture 0.1.7 by paramat -- For latest stable Minetest and back to 0.4.8 -- Depends default -- License: code WTFPL +-- use LVM for 'ungen' check, scanning chunk below + -- Parameters local YMIN = -33000 -- Set to -33000 when using singlenode option @@ -122,7 +124,8 @@ minetest.register_on_generated(function(minp, maxp, seed) local c_grass5 = minetest.get_content_id("default:grass_5") local c_dryshrub = minetest.get_content_id("default:dry_shrub") - local sidelen = x1 - x0 + 1 + local sidelen = x1 - x0 + 1 -- mapchunk side length + local facearea = sidelen ^ 2 -- mapchunk face area local chulens = {x=sidelen, y=sidelen+2, z=sidelen} local minposxyz = {x=x0, y=y0-1, z=z0} @@ -132,10 +135,8 @@ minetest.register_on_generated(function(minp, maxp, seed) local nvals_biome = minetest.get_perlin_map(np_biome, chulens):get3dMap_flat(minposxyz) local nvals_cloud = minetest.get_perlin_map(np_cloud, chulens):get3dMap_flat(minposxyz) - local ungen = false - if minetest.get_node({x=x0, y=y0-1, z=z0}).name == "ignore" then - ungen = true - end + local viu = area:index(x0, y0-1, z0) -- ungenerated chunk below? + local ungen = data[viu] == c_ignore local nixyz = 1 local stable = {} @@ -178,20 +179,20 @@ minetest.register_on_generated(function(minp, maxp, seed) stable[si] = 0 end else - local nodename = minetest.get_node({x=x,y=y,z=z}).name - if nodename == "fracture:stone" - or nodename == "fracture:desertstone" - or nodename == "fracture:dirt" - or nodename == "fracture:grass" - or nodename == "fracture:dirtsnow" - or nodename == "default:snowblock" - or nodename == "default:desert_sand" - or nodename == "default:stone_with_diamond" - or nodename == "default:stone_with_mese" - or nodename == "default:stone_with_gold" - or nodename == "default:stone_with_copper" - or nodename == "default:stone_with_iron" - or nodename == "default:stone_with_coal" then + local nodid = data[vi] + if nodid == c_stone + or nodid == c_destone + or nodid == c_dirt + or nodid == c_grass + or nodid == c_dirtsnow + or nodid == c_snowblock + or nodid == c_desand + or nodid == c_stodiam + or nodid == c_stomese + or nodid == c_stogold + or nodid == c_stocopp + or nodid == c_stoiron + or nodid == c_stocoal then stable[si] = 2 else stable[si] = 0 @@ -270,8 +271,7 @@ minetest.register_on_generated(function(minp, maxp, seed) local xrq = 16 * math.floor((x - x0) / 16) local zrq = 16 * math.floor((z - z0) / 16) local yrq = 40 - --local yrq = 79 - local qixyz = zrq * 6400 + yrq * 80 + xrq + 1 + local qixyz = zrq * facearea + yrq * sidelen + xrq + 1 if math.abs(nvals_cloud[qixyz]) < 0.05 then data[vi] = c_cloud end @@ -306,4 +306,4 @@ minetest.register_on_generated(function(minp, maxp, seed) vm:write_to_map(data) local chugent = math.ceil((os.clock() - t1) * 1000) print ("[fracture] "..chugent.." ms") -end) \ No newline at end of file +end) diff --git a/nodes.lua b/nodes.lua index b6816b8..b05333c 100644 --- a/nodes.lua +++ b/nodes.lua @@ -1,6 +1,7 @@ minetest.register_node("fracture:stone", { description = "FR Stone", tiles = {"default_stone.png"}, + is_ground_content = false, groups = {cracky=3}, drop = "default:cobble", sounds = default.node_sound_stone_defaults(), @@ -9,6 +10,7 @@ minetest.register_node("fracture:stone", { minetest.register_node("fracture:desertstone", { description = "FR Desert Stone", tiles = {"default_desert_stone.png"}, + is_ground_content = false, groups = {cracky=3}, drop = "default:desert_stone", sounds = default.node_sound_stone_defaults(), @@ -31,7 +33,7 @@ minetest.register_node("fracture:dirt", { minetest.register_node("fracture:dirtsnow", { description = "Dirt with Snow", tiles = {"default_snow.png", "default_dirt.png", "default_snow.png"}, - is_ground_content = true, + is_ground_content = false, groups = {crumbly=3,soil=1}, drop = "default:dirt", sounds = default.node_sound_dirt_defaults({ @@ -87,6 +89,7 @@ minetest.register_node("fracture:appling", { wield_image = "default_sapling.png", paramtype = "light", walkable = false, + is_ground_content = false, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} @@ -114,6 +117,7 @@ minetest.register_node("fracture:pineling", { wield_image = "fracture_pineling.png", paramtype = "light", walkable = false, + is_ground_content = false, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} @@ -179,4 +183,4 @@ minetest.register_craft({ recipe = { {"fracture:pinetree"}, } -}) \ No newline at end of file +})