diff --git a/init.lua b/init.lua index fd01b2e..9745d51 100644 --- a/init.lua +++ b/init.lua @@ -28,9 +28,17 @@ rocks.register_layer=function(name,params) assert(params) assert(params.gain) assert(params.height) + local maxheight + for ln,ld in pairs(rocks.layers) do + if (not ld.maxheight) or (ld.maxheight>params.height) then ld.maxheight=params.height end + if (not maxheight) or (maxheight>ld.height) then maxheight=ld.height end + end rocks.layers[name]= { gain=params.gain, height=params.height, + maxheight=maxheight, + limit=params.limit, + seed=params.seed, sum=0, rocks={} } @@ -51,7 +59,7 @@ end -- test layer -- -rocks.register_layer("test",{ gain=10, height=70 }) +rocks.register_layer("test",{ gain=40, height=70, limit=2, seed=1 }) rocks.register_rock("test","rocks:black_granite",1) rocks.register_rock("test","rocks:brown_granite",1) rocks.register_rock("test","rocks:pink_granite",1) @@ -61,19 +69,26 @@ rocks.register_rock("test","rocks:white_granite",1) -- layer generator -- -local noise_layer=nil -local noise_rock=nil -local noise_vein=nil -local noise_ore=nil -local stonectx=nil - -local function get_layer(y,noise) - return bln +local function mkheightmap(x,z,miny,maxy) + local hm={} + for ln,ld in pairs(rocks.layers) do + if not ld.noise then + ld.noise=minetest.get_perlin(ld.seed, rocks.rock_octaves, rocks.rock_presist, rocks.rock_scale) + end + if (ld.height-ld.gainminy)) then + local noise=ld.noise:get2d({x=x,y=z}) + if math.abs(noise)curlh) then - curlh=-31000 - curln=nil - for ln,ld in pairs(rocks.layers) do - if (ld.height>curlh)and(y+noise>ld.height) then - curln=ln - curlh=ld.height - end + -- select layer + local layer + for ln,ld in pairs(layers) do + if (y>ld.nd)and ((not layer)or(ld.ndmaxrnoise then maxrnoise=rnoise end - if rnoiselayer.sum then rnoise=layer.sum end - -- select current rock - local rofs=0 - local rockix=nil - for rn,rd in pairs(layer.rocks) do - if (rnoise>rofs) and (rnoise<=rofs+rd.amount) then - rockix=rn + rock=layer.rocks[1] -- todo... + -- place rocks + if not rock.ctx then + rock.ctx=minetest.get_content_id(rock.block) end - rofs=rofs+rd.amount - end - -- place rocks local p_pos = area:index(x, y, z) - if rockix and ((nodes[p_pos]==stonectx)or true) then - local cr=layer.rocks[rockix].block - local ctx=layer.rocks[rockix].blockctx - layer.rocks[rockix].placed=layer.rocks[rockix].placed+1 - if not ctx then - ctx= minetest.get_content_id(cr) - layer.rocks[rockix].blockctx= ctx - end - nodes[p_pos] = ctx - end + nodes[p_pos] = rock.ctx end - end + end end end end print("[rocks] manipulator flush") @@ -147,7 +130,7 @@ minetest.register_on_generated(function(minp, maxp, seed) -- manipulator:calc_lighting() -- manipulator:update_liquids() manipulator:write_to_map() - print("[rocks] gen "..os.difftime(os.clock(),timebefore).." perlin: "..minrnoise..".."..maxrnoise) + print("[rocks] gen "..os.difftime(os.clock(),timebefore)) end)