Use VM for ungen check and reading chunk below. Read/calculate from 16 nodes below to set up stabillity table

This commit is contained in:
paramat 2014-10-17 09:14:33 +01:00
parent 99b7e22517
commit 811becd960
2 changed files with 48 additions and 34 deletions

View File

@ -1,4 +1,4 @@
overgen 0.1.3 by paramat
overgen 0.2.0 by paramat
For latest stable Minetest back to 0.4.8
Depends default
Licenses: code WTFPL

View File

@ -1,18 +1,19 @@
-- overgen 0.1.3 by paramat
-- overgen 0.2.0 by paramat
-- For latest stable Minetest and back to 0.4.8
-- Depends default
-- License: code WTFPL
-- Speed increase: use LVM for 'ungen' check and scanning chunk below
-- use VM for ungen check and scanning chunk below
-- scan to 16 nodes below to initialise stability table
-- Parameters
local YMIN = 6000 -- Approximate realm base, atmosphere top
local YMAX = 8000
local TCEN = 7016 -- Terrain centre, average solid surface level
local WATY = 7016 -- Water surface y
local TSCA = 128 -- Terrain scale, approximate average height of hills
local STOT = 0.04 -- Stone threshold, controls epth of stone below surface
local YMIN = -2000 -- Approximate realm base
local YMAX = 1000 -- Approximate atmosphere top
local TCEN = 1 -- Terrain centre, average solid surface level
local WATY = 1 -- Water surface y
local TSCA = 192 -- Terrain scale, approximate average height of hills
local STOT = 0.03 -- Stone threshold, controls depth of stone below surface
local STABLE = 2 -- Minimum number of stacked stone nodes in column required to support sand
-- 3D noise for terrain
@ -20,15 +21,17 @@ local STABLE = 2 -- Minimum number of stacked stone nodes in column required to
local np_terrain = {
offset = 0,
scale = 1,
spread = {x=256, y=192, z=256}, -- largest scale in nodes
spread = {x=384, y=192, z=384}, -- largest scale in nodes
seed = 5900033,
octaves = 5, -- number of levels of detail
persist = 0.67 -- roughness / crazyness, 0.4 = smooth, 0.6 = MT standard
persist = 0.63 -- roughness / crazyness, 0.4 = smooth, 0.6 = MT standard
}
-- Stuff
overgen = {}
minetest.register_on_mapgen_init(function(mgparams)
minetest.set_mapgen_params({mgname="singlenode", water_level=1})
end)
-- Nodes
@ -48,7 +51,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
return
end
local t1 = os.clock()
local t0 = os.clock()
local x1 = maxp.x
local y1 = maxp.y
local z1 = maxp.z
@ -71,28 +75,33 @@ minetest.register_on_generated(function(minp, maxp, seed)
local c_ovgstone = minetest.get_content_id("overgen:stone")
local sidelen = x1 - x0 + 1
local chulens = {x=sidelen, y=sidelen+2, z=sidelen}
local minpos = {x=x0, y=y0-1, z=z0}
local vvii = sidelen + 32
local chulens = {x=sidelen, y=sidelen+17, z=sidelen}
local minpos = {x=x0, y=y0-16, z=z0}
local nvals_terrain = minetest.get_perlin_map(np_terrain, chulens):get3dMap_flat(minpos)
local viu = area:index(x0, y0-1, z0)
local ungen = data[viu] == c_ignore
local ungen = data[viu] == c_ignore -- ungenerated mapchunk below
local ni = 1
local stable = {}
local under = {}
for z = z0, z1 do
for y = y0 - 1, y1 + 1 do
for z = z0, z1 do -- for each vertical plane
for x = x0, x1 do -- set initial values of stability table to zero
local si = x - x0 + 1 -- stability table index
stable[si] = 0
end
for y = y0 - 16, y1 + 1 do -- for each horizontal row
local vi = area:index(x0, y, z)
for x = x0, x1 do
for x = x0, x1 do -- for each node
local si = x - x0 + 1
local grad = (TCEN - y) / TSCA
local density = nvals_terrain[ni] + grad
if y == y0 - 1 then -- node layer below chunk
if y < y0 then -- node layers below mapchunk
if ungen then
if density >= 0 then -- if node solid
stable[si] = STABLE
else
if density >= STOT then -- if node stone
stable[si] = stable[si] + 1
elseif density < 0 then -- air or water
stable[si] = 0
end
else
@ -100,35 +109,38 @@ minetest.register_on_generated(function(minp, maxp, seed)
if nodid == c_air
or nodid == c_water then
stable[si] = 0
else
stable[si] = STABLE
elseif nodid == c_ovgstone then
stable[si] = stable[si] + 1
end
end
elseif y >= y0 and y <= y1 then
elseif y >= y0 and y <= y1 then -- mapchunk
if density >= STOT then
data[vi] = c_ovgstone
stable[si] = stable[si] + 1
under[si] = 0
elseif density >= 0 and density < STOT and stable[si] >= STABLE then
elseif density >= 0 and density < STOT
and stable[si] >= STABLE then
data[vi] = c_sand
under[si] = 1
elseif y <= WATY then
data[vi] = c_water
stable[si] = 0
under[si] = 0
else -- air, possible above surface node
else -- air, possibly above surface
data[vi] = c_air
if under[si] == 1 then -- if air above surface node
local viu = area:index(x, y-1, z) -- index of 'under' node
local viu = vi - vvii -- index of 'under' node
data[viu] = c_desand -- replace node below with surface node
end
stable[si] = 0
under[si] = 0
end
elseif y == y1 + 1 then -- plane of nodes above chunk
if density < 0 and under[si] == 1 and y >= WATY + 1 then -- if air above surface
local viu = area:index(x, y-1, z)
data[viu] = c_desand -- replace node below with surface node
elseif y == y1 + 1 then -- layer of nodes above mapchunk
if density < 0 and y > WATY then -- air, possibly above surface
if under[si] == 1 then -- if air above surface node
local viu = vi - vvii -- index of 'under' node
data[viu] = c_desand -- replace node below with surface node
end
end
end
ni = ni + 1 -- increment perlinmap noise index
@ -141,6 +153,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
vm:set_lighting({day=0, night=0})
vm:calc_lighting()
vm:write_to_map(data)
local chugent = math.ceil((os.clock() - t1) * 1000)
--vm:update_liquids()
local chugent = math.ceil((os.clock() - t0) * 1000)
print ("[overgen] "..chugent.." ms")
end)