1
0
mirror of git://repo.or.cz/rocks.git synced 2024-11-16 07:20:40 +01:00

2d noisemap generated by faster bulk function.

This commit is contained in:
Tomáš Brada 2014-12-29 16:14:15 +01:00
parent 7a07b8ca2f
commit 49cd3736b2

View File

@ -14,11 +14,15 @@ rocks.layers = {}
rocks.veins = {} rocks.veins = {}
rocks.ores = {} rocks.ores = {}
rocks.layer_scale=300 rocks.noiseparams_layers = {
rocks.layer_presist=0.7 offset = 0,
rocks.layer_octaves=3 scale = 1,
spread = {x=300, y=300, z=300},
octaves = 3,
persist = 0.63
}
rocks.register_layer=function(name,params) rocks.register_layer=function(name,params,rock)
assert(name) assert(name)
assert(params) assert(params)
assert(params.gain) assert(params.gain)
@ -34,8 +38,8 @@ rocks.register_layer=function(name,params)
maxheight=maxheight, maxheight=maxheight,
limit=params.limit, limit=params.limit,
seed=params.seed, seed=params.seed,
sum=0, rock={ block=rock },
rocks={} veins={}
} }
print("[rocks] register layer "..name) print("[rocks] register layer "..name)
end end
@ -54,17 +58,13 @@ end
-- test layer -- test layer
-- --
rocks.register_layer("test1",{ gain=40, height=70, limit=2, seed=1 }) rocks.register_layer("test1",{ gain=40, height=70, limit=2, seed=1 },"rocks:black_granite")
rocks.register_rock("test1","rocks:black_granite",1)
rocks.register_rock("test1","air",1) -- uhlie ako vrstva je kokotina.
rocks.register_layer("test2",{ gain=5, height=70, limit=2, seed=5 })
rocks.register_rock("test2","default:stone_with_coal",1) rocks.register_layer("test3",{ gain=40, height=65, limit=2, seed=3 },"rocks:pink_granite")
rocks.register_layer("test3",{ gain=40, height=65, limit=2, seed=3 })
rocks.register_rock("test3","rocks:pink_granite",1) rocks.register_layer("test4",{ gain=40, height=90, limit=2, seed=4 },"rocks:white_granite")
rocks.register_rock("test3","air",1)
rocks.register_layer("test4",{ gain=40, height=90, limit=2, seed=4 })
rocks.register_rock("test4","rocks:white_granite",1)
rocks.register_rock("test4","air",1)
for ln,ld in pairs(rocks.layers) do for ln,ld in pairs(rocks.layers) do
@ -75,21 +75,29 @@ end
-- layer generator -- layer generator
-- --
local function mkheightmap(layers,x,z,miny,maxy) local function mknoises(layers,minp,maxp)
local hm={} local nm={}
for ln,ld in pairs(rocks.layers) do for ln,ld in pairs(rocks.layers) do
if not ld.noise then if (ld.height-ld.gain<maxp.y)and((not ld.maxheight)or(ld.maxheight+ld.gain>minp.y)) then
print("[rocks] initialize perlin noise for layer "..ln) local np=rocks.noiseparams_layers
ld.noise=minetest.get_perlin(ld.seed, rocks.layer_octaves, rocks.layer_presist, rocks.layer_scale) np.seed=ld.seed
local side_length = maxp.x - minp.x + 1
ld.nmap=minetest.get_perlin_map(np,{x=side_length, y=side_length, z=side_length}):get2dMap({x=minp.x, y=minp.z})
table.insert(nm,ld)
end end
if (ld.height-ld.gain<maxy)and((not ld.maxheight)or(ld.maxheight+ld.gain>miny)) then end
local noise=ld.noise:get2d({x=x,y=z}) return nm
end
local function mkheightmap(layers,x,z,minp,maxp)
local hm={}
for ln,ld in pairs(layers) do
local noise=ld.nmap[z-minp.z+1][x-minp.x+1]
if math.abs(noise)<ld.limit then if math.abs(noise)<ld.limit then
ld.nh = (noise*ld.gain)+ld.height ld.nh = (noise*ld.gain)+ld.height
-- if (ld.nh<maxy)and(ld.nh>miny) -- if (ld.nh<maxy)and(ld.nh>miny)
table.insert(hm,ld) table.insert(hm,ld)
end end
end
end end
return hm return hm
end end
@ -107,15 +115,16 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nodes = manipulator:get_data() local nodes = manipulator:get_data()
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
-- initialize noises and sort out unused layers -- initialize noises and sort out unused layers
local avllayers=rocks.layers -- impl mknoises(rocks.layers,minp,maxp) local availlayers=mknoises(rocks.layers,minp,maxp)
-- --
for x=minp.x,maxp.x,1 do for x=minp.x,maxp.x,1 do
for z=minp.z,maxp.z,1 do for z=minp.z,maxp.z,1 do
--initialize layers hmap --* initialize layers hmap
local layers=mkheightmap(avllayers,x,z,minp.y,maxp.y) local layers=mkheightmap(availlayers,x,z,minp,maxp)
if (minp.x>0)and(minp.x<200) then layers=nil end --< debug if (minp.x>0)and(minp.x<200) then layers=nil end --< debug
if layers then for y=minp.y,maxp.y,1 do if layers then for y=minp.y,maxp.y,1 do
-- select layer
--* select layer
local layer local layer
for ln,ld in pairs(layers) do for ln,ld in pairs(layers) do
if (ld)and if (ld)and
@ -125,17 +134,22 @@ minetest.register_on_generated(function(minp, maxp, seed)
layer=ld layer=ld
end end
end end
-- select vein
--* select vein
local vein=nil
if layer then if layer then
-- layer=todo... iterate vein's noises and select one above it's treshold -- vein=todo... iterate vein's noises and select one above it's treshold
end end
-- select rock
--* select rock
local rock=nil local rock=nil
if layer then if vein then
rock=layer.rocks[1] -- todo... rock=nil -- todo... --> based on pseudorandom, no pattern, just random
--> based on pseudorandom, no pattern, just random elseif layer then
rock=layer.rock -- not in vein > select base rock
end end
-- place rocks
--* place rocks
if rock then if rock then
if not rock.ctx then if not rock.ctx then
rock.ctx=minetest.get_content_id(rock.block) rock.ctx=minetest.get_content_id(rock.block)
@ -143,6 +157,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
local p_pos = area:index(x, y, z) local p_pos = area:index(x, y, z)
nodes[p_pos] = rock.ctx nodes[p_pos] = rock.ctx
end end
end end end end
end end
end end