mirror of
git://repo.or.cz/rocks.git
synced 2025-01-01 14:00:30 +01:00
Sedimentary layer rewrite.
This commit is contained in:
parent
7665588a0e
commit
12f7c99e9f
33
init.lua
33
init.lua
@ -7,36 +7,17 @@ if (minetest.get_modpath("intllib")) then
|
||||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
rocks={}
|
||||
|
||||
local modpath=minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
dofile(modpath.."/register.lua")
|
||||
print("[rocks] begin")
|
||||
|
||||
rocks.noiseparams_layers = {
|
||||
offset = 0,
|
||||
scale = 1,
|
||||
spread = {x=80, y=80, z=80},
|
||||
octaves = 2,
|
||||
persist = 0.7
|
||||
}
|
||||
|
||||
dofile(modpath.."/mapgen.lua")
|
||||
--dofile(modpath.."/testing.lua")
|
||||
|
||||
print("[rocks] core loaded.")
|
||||
|
||||
dofile(modpath.."/geologicaLayers.lua")
|
||||
dofile(modpath.."/geologicaStrata.lua")
|
||||
dofile(modpath.."/geologicaVeins.lua")
|
||||
dofile(modpath.."/sed.lua")
|
||||
|
||||
minetest.register_on_mapgen_init(function(mapgen_params)
|
||||
|
||||
for i,d in pairs(rocks.layers_name) do table.insert(rocks.layers,d) end
|
||||
table.sort(rocks.layers,function(a,b)
|
||||
return a.height<b.height
|
||||
end)
|
||||
|
||||
-- todo: disable caves and ores
|
||||
|
||||
print("[rocks] mapgen initalized ("..#rocks.layers.." layers)")
|
||||
|
||||
print("[rocks] mapgen initalized ")
|
||||
end)
|
||||
|
||||
print("[rocks] done")
|
61
register.lua
61
register.lua
@ -1,61 +0,0 @@
|
||||
-- global table and register_* functions
|
||||
|
||||
rocks = {}
|
||||
|
||||
rocks.layers = {}
|
||||
rocks.layers_name = {}
|
||||
rocks.veins = {}
|
||||
rocks.ores = {}
|
||||
|
||||
rocks.register_layer=function(name,params,rock)
|
||||
assert(name)
|
||||
assert(params)
|
||||
assert(rock)
|
||||
assert(params.gain)
|
||||
assert(params.height)
|
||||
local maxheight
|
||||
|
||||
local ld= {
|
||||
gain=params.gain,
|
||||
height=params.height,
|
||||
maxheight=maxheight,
|
||||
limit=(params.limit*params.gain)+params.height,
|
||||
seed=params.seed or 0,
|
||||
rock={ node=rock },
|
||||
veins={},
|
||||
name=name
|
||||
}
|
||||
rocks.layers_name[name]= ld
|
||||
print("[rocks] layer "..ld.name.." height="..ld.height.." limit="..ld.limit)
|
||||
end
|
||||
|
||||
rocks.register_vein=function(name,params)
|
||||
assert(name)
|
||||
assert(params)
|
||||
assert(not rocks.veins[name])
|
||||
rocks.veins[name]={
|
||||
np={
|
||||
offset=0, scale=1, octaves=1, presist=0.8,
|
||||
spread={x=params.spread.x, y=params.spread.y, z=params.spread.z},
|
||||
-- swapped, becouse we generate by horizontal layers
|
||||
seed=params.seed
|
||||
},
|
||||
treshold=params.treshold,
|
||||
hmin=params.hmin, hmax=params.hmax,
|
||||
layers=params.layers,
|
||||
ores={}
|
||||
}
|
||||
for i,layername in pairs(params.layers) do
|
||||
rocks.layers_name[layername].veins[name]=rocks.veins[name]
|
||||
print("[rocks] vein "..name.." in "..layername)
|
||||
end
|
||||
end
|
||||
|
||||
rocks.register_ore=function( vein, node, params )
|
||||
-- params= {treshold=0, chance=1 }
|
||||
ore={ node=node }
|
||||
ore.treshold=(params.treshold or rocks.veins[vein].treshold)
|
||||
ore.chance= (params.chance or 1)
|
||||
table.insert(rocks.veins[vein].ores, ore)
|
||||
print("[rocks] ore "..node.." in "..vein.." chance="..ore.chance.." treshold="..ore.treshold)
|
||||
end
|
130
sed.lua
Normal file
130
sed.lua
Normal file
@ -0,0 +1,130 @@
|
||||
--
|
||||
-- Sedimentary Layer
|
||||
--
|
||||
|
||||
local sed={
|
||||
top={
|
||||
offset = 20, scale = 0,
|
||||
spread = {x=80, y=80, z=80},
|
||||
octaves = 0, persist = 0 },
|
||||
bot={
|
||||
offset = -22, scale = 20, 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 }
|
||||
}
|
||||
|
||||
-- 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},
|
||||
is_ground_content = true, sounds = default.node_sound_dirt_defaults(),
|
||||
})
|
||||
|
||||
-- more rock defs
|
||||
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},
|
||||
})
|
||||
|
||||
|
||||
local reg=function(name,param)
|
||||
sed.localized[name]={
|
||||
spread=(param.spread or 20),
|
||||
height=(param.height or 15),
|
||||
treshold=(param.treshold or 0.85),
|
||||
secondary=(param.secondary),
|
||||
seed=seedseq,
|
||||
}
|
||||
sed.seedseq=sed.seedseq+1
|
||||
end
|
||||
rocks.register_sedimentary=reg
|
||||
|
||||
-- Sedimentary rock hardness and distribution
|
||||
-- Rock Hard Distribution
|
||||
--Breccia Weak Localized continental, folded
|
||||
-->Claystone Weak Localized continental, folded, oceanic
|
||||
--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 })
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
if ( (sed.top.offset+sed.top.scale)>minp.y )
|
||||
and ( (sed.bot.offset-sed.bot.scale)<maxp.y )
|
||||
then
|
||||
stone_ctx= minetest.get_content_id("default:stone")
|
||||
air_ctx= minetest.get_content_id("air")
|
||||
dirt_ctx= minetest.get_content_id("default:dirt")
|
||||
sed.primary.ctx= minetest.get_content_id(sed.primary.name)
|
||||
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}
|
||||
-- noises:
|
||||
local bottom=minetest.get_perlin_map(sed.bot,map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z})
|
||||
local localized={}
|
||||
for name,loc in pairs(sed.localized) do
|
||||
--defaults and overrides
|
||||
local np={ offset = 0, scale = 1, octaves = 1, persist = 0.7,
|
||||
spread = {x=loc.spread, y=loc.height, z=loc.spread} }
|
||||
--get noise and content ids
|
||||
table.insert(localized,
|
||||
{
|
||||
noise=minetest.get_perlin_map(np,map_lengths_xyz):get3dMap_flat(minp),
|
||||
treshold=loc.treshold,
|
||||
ctx= minetest.get_content_id(name)
|
||||
})
|
||||
end
|
||||
local noise2d_ix = 1
|
||||
local noise3d_ix = 1
|
||||
print("[rocks] sedimentary gen1 "..os.clock()-timebefore)
|
||||
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 pos = area:index(x, y, z)
|
||||
if (y>bottom[noise2d_ix])
|
||||
and ((nodes[pos]==stone_ctx) or (nodes[pos]==dirt_ctx))
|
||||
then
|
||||
nodes[pos] = sed.primary.ctx
|
||||
for k,loc in pairs(localized) do
|
||||
if (loc.noise[noise3d_ix]>loc.treshold) then
|
||||
nodes[pos]=loc.ctx
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
noise2d_ix=noise2d_ix+1
|
||||
noise3d_ix=noise3d_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] sedimentary gen2 "..os.clock()-timebefore)
|
||||
sed.stats.count=sed.stats.count+1
|
||||
sed.stats.total=sed.stats.total+(os.clock()-timebefore)
|
||||
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)")
|
||||
end)
|
||||
|
||||
-- ~ Tomas Brod
|
Loading…
Reference in New Issue
Block a user