1
0
mirror of git://repo.or.cz/rocks.git synced 2024-12-28 03:40:33 +01:00

Deduplication, param cleanup. Veins.

This commit is contained in:
Tomáš Brada 2015-07-05 14:28:58 +02:00
parent f9d6fbdcea
commit 16a9a079d9
4 changed files with 53 additions and 21 deletions

View File

@ -15,7 +15,7 @@ l.OnInit={}
l.ToResolve={}
local includes={
"pipes","veins"
"utils","pipes","veins"
}
minetest.register_on_generated(function(minp,maxp,seed)
@ -23,9 +23,12 @@ minetest.register_on_generated(function(minp,maxp,seed)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local pr=PseudoRandom(seed)
local data=vm:get_data()
local mgc={minp=minp,maxp=maxp,pr=pr,data=data,area=area}
for i=1, #l.OnGenerate do
l.OnGenerate[i](minp,maxp,pr,vm,area)
l.OnGenerate[i](mgc)
end
vm:set_data(data)
vm:write_to_map()
end)

View File

@ -44,24 +44,26 @@ end
depositgen.l.ToResolve.air={name="air"}
local function generate(minp,maxp,pr,vm,area)
local function generate(mgc)
local t1 = os.clock()
local data = vm:get_data()
local data = mgc.data
local area = mgc.area
local pr=mgc.pr
local minp,maxp=mgc.minp,mgc.maxp
local chunksizer = maxp.x - minp.x + 1
local chunksize = chunksizer + 1
local pmapsize = {x = chunksize, y = chunksize, z = chunksize}
local minpxz = {x = minp.x, y = minp.z}
for _,descr in pairs(regs) do
--local orepr=PseudoRandom(pr:next())
local numpipes_raw=(chunksize/descr.scarcity)
local numpipes = math.floor(numpipes_raw + (pr:next(0,99)/100))
for vc=1, numpipes do
local pointA=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
local pointB=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
local pointC=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
local pointA=l.rndvector(mgc)
local pointB=l.rndvector(mgc)
local pointC=l.rndvector(mgc)
local step=(1.8)/(vector.distance(pointA,pointB)+vector.distance(pointB,pointC))
for t=0, 1, step do
@ -107,7 +109,6 @@ local function generate(minp,maxp,pr,vm,area)
end --</apipe>
vm:set_data(data)
l.print("pipes "..math.ceil((os.clock() - t1) * 1000).." ms ")
end

16
depositgen/utils.lua Normal file
View File

@ -0,0 +1,16 @@
function depositgen.l.SpawnCluster(mgc,pos,wherein,size,content,density)
for y=pos.y-size, pos.y+size do
for x=pos.x-size, pos.x+size do
for z=pos.z-size, pos.z+size do
if mgc.pr:next(0,density)==0 then
di=mgc.area:index(x,y,z)
if mgc.data[di]==wherein then
mgc.data[di]=content
end
end
end end end
end
function depositgen.l.rndvector(mgc)
local chunksizer = mgc.maxp.x - mgc.minp.x + 1
return vector.new(mgc.pr:next(0,chunksizer)+mgc.minp.x,mgc.pr:next(0,chunksizer)+mgc.minp.y,mgc.pr:next(0,chunksizer)+mgc.minp.z)
end

View File

@ -35,34 +35,34 @@ local sample_vein_def={
scarcity=80,
content="default:dirt",
scatter={
--{ scarcity=7, density=4, content="default:mese", size=2 }
{ scarcity=7, density=4, content="default:mese", size=2 }
}
}
depositgen.register_vein(sample_vein_def)
end
local function generate(minp,maxp,pr,vm,area)
local function generate(mgc)
local t1 = os.clock()
local data = vm:get_data()
local data = mgc.data
local area = mgc.area
local pr=mgc.pr
local chunksizer = maxp.x - minp.x + 1
local chunksizer = mgc.maxp.x - mgc.minp.x + 1
local chunksize = chunksizer + 1
local pmapsize = {x = chunksize, y = chunksize, z = chunksize}
local minpxz = {x = minp.x, y = minp.z}
local minpxz = {x = mgc.minp.x, y = mgc.minp.z}
for _,descr in pairs(regs) do
local num = math.floor( (chunksize/descr.scarcity) + (pr:next(0,99)/100) )
for vc=1, num do
local A=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
local B=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
local C=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
local D=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
local A=l.rndvector(mgc)
local B=l.rndvector(mgc)
local C=l.rndvector(mgc)
local D=l.rndvector(mgc)
local l1=vector.distance(A,C)+vector.distance(C,B)
local l2=vector.distance(A,D)+vector.distance(D,B)
local step=2/math.max(l1,l2)
local scarcity=6
local ocn=pr:next(0,scarcity)+(scarcity/2)
for t=0, 1, step do
local P=vector.multiply(A,(1-t)^2)
P=vector.add(P, vector.multiply(B,t*t) )
@ -79,10 +79,22 @@ local function generate(minp,maxp,pr,vm,area)
--</brush>
end
end
--<ores>
local cluster=descr.scatter[1]
for xxx=1, 5 do
local t=pr:next(0,100)/100
local u=pr:next(0,100)/100
local P=vector.multiply(A,(1-t)^2)
P=vector.add(P, vector.multiply(B,t*t) )
local Q=vector.add(P, vector.multiply(D,2*t*(1-t)) )
P=vector.add(P, vector.multiply(C,2*t*(1-t)) )
local R=vector.add(vector.multiply(P,(1-u)), vector.multiply(Q,u) )
l.SpawnCluster(mgc,vector.round(R),l.ToResolve.air.id,cluster.size,cluster.content.id,cluster.density)
end
--</ores>
end
end
vm:set_data(data)
print("vein "..math.ceil((os.clock() - t1) * 1000).." ms ")
end