From 6693f103a19ff1a082bdff6dda70d99c0403e196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Thu, 2 Apr 2015 00:28:16 +0200 Subject: [PATCH] Fix, debug, cleanup. --- mapgen.lua | 125 ----------------------------------------------------- sed.lua | 38 +++++++++------- 2 files changed, 23 insertions(+), 140 deletions(-) delete mode 100644 mapgen.lua diff --git a/mapgen.lua b/mapgen.lua deleted file mode 100644 index baab9ba..0000000 --- a/mapgen.lua +++ /dev/null @@ -1,125 +0,0 @@ --- --- layer generator --- - - -minetest.register_on_generated(function(minp, maxp, seed) - stone_ctx= minetest.get_content_id("default:stone") - air_ctx= minetest.get_content_id("air") - local timebefore=os.clock(); - local manipulator, emin, emax = minetest.get_mapgen_object("voxelmanip") - local nodes = manipulator:get_data() - local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} - local side_length = (maxp.x - minp.x) + 1 - local map_lengths_xyz = {x=side_length, y=side_length, z=side_length} - - -- sort out unused layers - -- generate noises - avl={} - for i,d in ipairs(rocks.layers) do - -- h je normaalna vyyska horného konca vrstvy - if (d.height+d.gain)>=minp.y then -- ak je to mimo zdola tak ju vyhodime - -- urobime sum pre vrstvu - local np=rocks.noiseparams_layers - np.seed=d.seed - np.scale=d.gain - np.offset=d.height - d.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z}) - -- contene_id kamenov - d.rock.ctx=d.rock.ctx or minetest.get_content_id(d.rock.node) - -- veiny - local veinstodo={} - for veinname,vd in pairs(d.veins) do - -- todo: do not generate noise for blocks outside the layer - veinstodo[veinname]=vd - end - for veinname,vd in pairs(veinstodo) do - -- noise pre vein - np=vd.np - vd.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get3dMap_flat(minp) - vd.prng=PseudoRandom(np.seed) - vd.sum=0 - for i,ore in pairs(vd.ores) do - -- contntid pre rudu - ore.ctx=ore.ctx or minetest.get_content_id(ore.node) - -- sum sanci pre vein - vd.sum=vd.sum+ore.chance - end - end - table.insert(avl,d) -- pridame vrstvu - if (d.height-d.gain)>maxp.y then break end -- ak je mimo zhora tak uz dalsie nehladaj - else - --print(" no higher "..d.height.." than "..minp.y) - end - end - - -- - print("[rocks] gen2 "..os.clock()-timebefore.." #layers="..#avl.." minp.y="..minp.y.." maxp.y="..maxp.y) - for lh,ld in ipairs(avl) do - print(" "..lh.."->"..ld.name.." top="..ld.height) - for vn,vd in pairs(ld.veins) do - print(" "..vn.."->"..#vd.ores) - end - end - - local noise2d_ix = 1 - local noise3d_ix = 1 - - for z=minp.z,maxp.z,1 do - for y=minp.y,maxp.y,1 do - for x=minp.x,maxp.x,1 do - local p_pos = area:index(x, y, z) - local layer,vein - local rock - - --* select layer - for lh,ld in ipairs(avl) do - if (yvd.treshold then - vein=vd - --rock not changed - break - end - end - end - - if vein then - --* select ore - local chance=vein.prng:next(0,vein.sum) - for i,ore in pairs(vein.ores) do - chance=chance-ore.chance - if chance<=0 then - rock=ore - break - end - end - end - - --* place rocks - if (rock) and(nodes[p_pos]==stone_ctx) then - nodes[p_pos] = rock.ctx - end - - noise3d_ix =noise3d_ix+1 - noise2d_ix = noise2d_ix+1 - end - noise2d_ix = noise2d_ix-side_length - end - end - manipulator:set_data(nodes) - --manipulator:calc_lighting() - --manipulator:set_lighting({day=15,night=15}) - --manipulator:update_liquids() - manipulator:write_to_map() - print("[rocks] gen0 "..os.clock()-timebefore) -end) - diff --git a/sed.lua b/sed.lua index b4ad718..b3bd564 100644 --- a/sed.lua +++ b/sed.lua @@ -8,20 +8,20 @@ local sed={ spread = {x=80, y=80, z=80}, octaves = 0, persist = 0 }, bot={ - offset = -22, scale = 20, seed=1, + offset = -22, scale = 10, seed=1, spread = {x=80, y=80, z=80}, octaves = 2, persist = 0.7 }, primary={ name="rocks:mudstone" }, localized={}, seedseq=2, - stats={ count=0, total=0 } + stats={ count=0, total=0, node={}, totalnodes=0 } } -- Mudstone Sed soft Ocean, beach, river, glaciers minetest.register_node( "rocks:mudstone", { description = S("Mudstone"), tiles = { "rocks_Mudstone.png" }, - groups = {cracky=3, stone=1, crumbly=4}, + groups = {cracky=1, crumbly=1}, is_ground_content = true, sounds = default.node_sound_dirt_defaults(), }) @@ -30,7 +30,7 @@ minetest.register_node( "rocks:limestone", { description = S("Limestone"), tiles = { "rocks_Limestone.png" }, is_ground_content = true, sounds = default.node_sound_stone_defaults(), - groups = {cracky=CcMed, stone=1}, + groups = {cracky=2}, }) @@ -42,6 +42,7 @@ local reg=function(name,param) secondary=(param.secondary), seed=seedseq, } + sed.stats.node[name]=0 sed.seedseq=sed.seedseq+1 end rocks.register_sedimentary=reg @@ -53,11 +54,11 @@ rocks.register_sedimentary=reg --Conglomerate Weak Localized continental, folded -->Limestone Medium Localized continental, folded; primary oceanic, hills -->Coal - Large beds, twice as common in swamps - --reg("rocks:breccia", { spread=35, height=30, treshold=0.85 }) - reg("default:clay",{ spread=40, height=30, treshold=0.70 }) - --reg("rocks:conglomerate", { spread=35, height=30, treshold=0.85 }) - reg("rocks:limestone", { spread=40, height=30, treshold=0.80 }) - reg("default:stone_with_coal", { spread=10, height=6, treshold=0.70 }) + reg("rocks:limestone", { spread=64, height=32, treshold=0.56 }) + --reg("rocks:breccia", { spread=64, height=32, treshold=0.6 }) + --reg("rocks:conglomerate", { spread=64, height=32, treshold=0.6 }) + reg("default:clay",{ spread=24, height=16, treshold=0.63 }) + reg("default:stone_with_coal", { spread=48, height=14, treshold=0.45 }) minetest.register_on_generated(function(minp, maxp, seed) if ( (sed.top.offset+sed.top.scale)>minp.y ) @@ -85,7 +86,8 @@ minetest.register_on_generated(function(minp, maxp, seed) { noise=minetest.get_perlin_map(np,map_lengths_xyz):get3dMap_flat(minp), treshold=loc.treshold, - ctx= minetest.get_content_id(name) + ctx= minetest.get_content_id(name), + ndn=name }) end local noise2d_ix = 1 @@ -98,19 +100,21 @@ minetest.register_on_generated(function(minp, maxp, seed) if (y>bottom[noise2d_ix]) and ((nodes[pos]==stone_ctx) or (nodes[pos]==dirt_ctx)) then - nodes[pos] = sed.primary.ctx + sed.stats.totalnodes=sed.stats.totalnodes+1 + if nodes[pos]==stone_ctx then nodes[pos] = air_ctx end --sed.primary.ctx for k,loc in pairs(localized) do - if (loc.noise[noise3d_ix]>loc.treshold) then + if ( loc.noise[noise3d_ix] > loc.treshold) then nodes[pos]=loc.ctx - break + sed.stats.node[loc.ndn]=sed.stats.node[loc.ndn]+1 end end end noise2d_ix=noise2d_ix+1 noise3d_ix=noise3d_ix+1 end - noise2d_ix = noise2d_ix-side_length + noise2d_ix=noise2d_ix-side_length end + noise2d_ix=noise2d_ix+side_length end manipulator:set_data(nodes) --manipulator:calc_lighting() @@ -120,11 +124,15 @@ minetest.register_on_generated(function(minp, maxp, seed) print("[rocks] sedimentary gen2 "..os.clock()-timebefore) sed.stats.count=sed.stats.count+1 sed.stats.total=sed.stats.total+(os.clock()-timebefore) + sed.stats.side=side_length end end) minetest.register_on_shutdown(function() - print("[rocks](sed) on_shutdown: generated total "..sed.stats.count.." chunks in "..sed.stats.total.." seconds ("..(sed.stats.total/sed.stats.count).." seconds per chunk)") + print("[rocks](sed) on_shutdown: generated total "..sed.stats.count.." chunks in "..sed.stats.total.." seconds ("..(sed.stats.total/sed.stats.count).." seconds per "..sed.stats.side.."^3 chunk)") + for name,total in pairs(sed.stats.node) do + print("[rocks](sed) "..name..": "..total.." nodes placed ("..(total*100)/(sed.stats.count*sed.stats.totalnodes).." %)") + end end) -- ~ Tomas Brod \ No newline at end of file