mirror of
git://repo.or.cz/rocks.git
synced 2024-11-16 07:20:40 +01:00
Fixed wrong noisemap indexing.
This commit is contained in:
parent
153d6113ce
commit
d2b4bd6332
|
@ -9,8 +9,8 @@ local CcSoft=3
|
||||||
|
|
||||||
-- Claystone Sed soft in mudstone
|
-- Claystone Sed soft in mudstone
|
||||||
rocks.register_vein("clay",{
|
rocks.register_vein("clay",{
|
||||||
spread = {x=10, y=10, z=10},
|
spread = {x=30, y=10, z=30},
|
||||||
treshold=0.75,
|
treshold=0.2, -- clay should be plenty
|
||||||
seed = 9,
|
seed = 9,
|
||||||
hmin=-8, hmax=nil,
|
hmin=-8, hmax=nil,
|
||||||
layers={ "mudstone" },
|
layers={ "mudstone" },
|
||||||
|
|
58
mapgen.lua
58
mapgen.lua
|
@ -27,7 +27,26 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
d.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z})
|
d.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z})
|
||||||
-- contene_id kamenov
|
-- contene_id kamenov
|
||||||
d.rock.ctx=d.rock.ctx or minetest.get_content_id(d.rock.node)
|
d.rock.ctx=d.rock.ctx or minetest.get_content_id(d.rock.node)
|
||||||
table.insert(avl,d) -- pridame ju
|
-- 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=nil
|
||||||
|
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
|
if (d.height-d.gain)>maxp.y then break end -- ak je mimo zhora tak uz dalsie nehladaj
|
||||||
else
|
else
|
||||||
--print(" no higher "..d.height.." than "..minp.y)
|
--print(" no higher "..d.height.." than "..minp.y)
|
||||||
|
@ -35,43 +54,66 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
print("[rocks] afterinit "..os.clock()-timebefore.." #layers="..#avl)
|
print("[rocks] gen2 "..os.clock()-timebefore.." #layers="..#avl.." minp.y="..minp.y.." maxp.y"..maxp.y)
|
||||||
for lh,ld in ipairs(avl) do
|
for lh,ld in ipairs(avl) do
|
||||||
print(" "..lh.."->"..ld.name)
|
print(" "..lh.."->"..ld.name.." top="..ld.height)
|
||||||
|
for vn,vd in pairs(ld.veins) do
|
||||||
|
print(" "..vn.."->"..#vd.ores)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local noise2d_ix = 1
|
local noise2d_ix = 1
|
||||||
local noise3d_ix = 1
|
local noise3d_ix = 1
|
||||||
|
|
||||||
for x=minp.x,maxp.x,1 do
|
|
||||||
for z=minp.z,maxp.z,1 do
|
for z=minp.z,maxp.z,1 do
|
||||||
for y=minp.y,maxp.y,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 p_pos = area:index(x, y, z)
|
||||||
local layer,rock
|
local layer,vein
|
||||||
|
local rock
|
||||||
|
|
||||||
--* select layer
|
--* select layer
|
||||||
for lh,ld in ipairs(avl) do
|
for lh,ld in ipairs(avl) do
|
||||||
if y<ld.nmap[noise2d_ix] then
|
if (y<ld.nmap[noise2d_ix])and(ld.nmap[noise2d_ix]<ld.limit) then
|
||||||
layer=ld
|
layer=ld
|
||||||
rock=layer.rock
|
rock=layer.rock
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if layer then
|
||||||
|
--* select vein
|
||||||
|
for veinname,vd in pairs(layer.veins) do
|
||||||
|
if vd.nmap[noise3d_ix]>vd.treshold then
|
||||||
|
vein=vd
|
||||||
|
--rock not changed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if vein then
|
||||||
|
--* select ore
|
||||||
|
for i,ore in pairs(vein.ores) do
|
||||||
|
rock=ore
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--* place rocks
|
--* place rocks
|
||||||
if (rock) and(nodes[p_pos]==stone_ctx) then
|
if (rock) and(nodes[p_pos]==stone_ctx) then
|
||||||
nodes[p_pos] = rock.ctx
|
nodes[p_pos] = rock.ctx
|
||||||
end
|
end
|
||||||
|
|
||||||
noise3d_ix =noise3d_ix+1
|
noise3d_ix =noise3d_ix+1
|
||||||
end
|
|
||||||
noise2d_ix = noise2d_ix+1
|
noise2d_ix = noise2d_ix+1
|
||||||
end
|
end
|
||||||
|
noise2d_ix = noise2d_ix-side_length
|
||||||
|
end
|
||||||
end
|
end
|
||||||
manipulator:set_data(nodes)
|
manipulator:set_data(nodes)
|
||||||
manipulator:calc_lighting()
|
manipulator:calc_lighting()
|
||||||
manipulator:update_liquids()
|
manipulator:update_liquids()
|
||||||
manipulator:write_to_map()
|
manipulator:write_to_map()
|
||||||
print("[rocks] gen "..os.clock()-timebefore)
|
print("[rocks] gen0 "..os.clock()-timebefore)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
11
register.lua
11
register.lua
|
@ -10,6 +10,7 @@ rocks.ores = {}
|
||||||
rocks.register_layer=function(name,params,rock)
|
rocks.register_layer=function(name,params,rock)
|
||||||
assert(name)
|
assert(name)
|
||||||
assert(params)
|
assert(params)
|
||||||
|
assert(rock)
|
||||||
assert(params.gain)
|
assert(params.gain)
|
||||||
assert(params.height)
|
assert(params.height)
|
||||||
local maxheight
|
local maxheight
|
||||||
|
@ -18,8 +19,8 @@ rocks.register_layer=function(name,params,rock)
|
||||||
gain=params.gain,
|
gain=params.gain,
|
||||||
height=params.height,
|
height=params.height,
|
||||||
maxheight=maxheight,
|
maxheight=maxheight,
|
||||||
limit=params.limit,
|
limit=((params.limit or 2)*params.gain)+params.height,
|
||||||
seed=params.seed,
|
seed=params.seed or 0,
|
||||||
rock={ node=rock },
|
rock={ node=rock },
|
||||||
veins={},
|
veins={},
|
||||||
name=name
|
name=name
|
||||||
|
@ -35,7 +36,7 @@ rocks.register_vein=function(name,params)
|
||||||
rocks.veins[name]={
|
rocks.veins[name]={
|
||||||
np={
|
np={
|
||||||
offset=0, scale=1, octaves=1, presist=0.8,
|
offset=0, scale=1, octaves=1, presist=0.8,
|
||||||
spread={x=params.spread.y, y=params.spread.z, z=params.spread.x},
|
spread={x=params.spread.x, y=params.spread.y, z=params.spread.z},
|
||||||
-- swapped, becouse we generate by horizontal layers
|
-- swapped, becouse we generate by horizontal layers
|
||||||
seed=params.seed
|
seed=params.seed
|
||||||
},
|
},
|
||||||
|
@ -44,8 +45,8 @@ rocks.register_vein=function(name,params)
|
||||||
layers=params.layers,
|
layers=params.layers,
|
||||||
ores={}
|
ores={}
|
||||||
}
|
}
|
||||||
for ln,ld in pairs(rocks.layers_name) do
|
for i,layername in pairs(params.layers) do
|
||||||
ld.veins[name]=rocks.veins[name]
|
rocks.layers_name[layername].veins[name]=rocks.veins[name]
|
||||||
end
|
end
|
||||||
print("[rocks] vein "..name)
|
print("[rocks] vein "..name)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user