1
0
mirror of git://repo.or.cz/rocks.git synced 2024-12-29 12:20:35 +01:00
rocks/depositgen/veins.lua

102 lines
2.7 KiB
Lua
Raw Permalink Normal View History

-- experimental fast vein generator
2015-07-03 21:00:38 +02:00
local l=depositgen.l
local print=l.print
2015-06-07 11:04:27 +02:00
2015-07-03 21:00:38 +02:00
-- the public table of registered veins
depositgen.veins={}
local regs=depositgen.veins
2015-06-07 11:04:27 +02:00
2015-07-03 21:00:38 +02:00
depositgen.register_vein= function(descr)
local vein={
ymin=(descr.ymin or -10000),
ymax=(descr.ymax or 200),
scarcity=descr.scarcity,
content={ name=descr.content },
scatter={}
}
table.insert(depositgen.l.ToResolve,vein.content)
for _,sc in pairs(descr.scatter) do
local psc={
scarcity=sc.scarcity,
size=(sc.size or vein.width),
density=sc.density,
content={ name=sc.content }
}
table.insert(depositgen.l.ToResolve,psc.content)
table.insert(vein.scatter,psc)
end
return table.insert(regs,vein)
end
do
local sample_vein_def={
ymin=-200, ymax=-6,
scarcity=80,
content="default:dirt",
scatter={
2015-07-05 14:28:58 +02:00
{ scarcity=7, density=4, content="default:mese", size=2 }
2015-07-03 21:00:38 +02:00
}
}
depositgen.register_vein(sample_vein_def)
end
2015-07-05 14:28:58 +02:00
local function generate(mgc)
local t1 = os.clock()
2015-07-05 14:28:58 +02:00
local data = mgc.data
local area = mgc.area
local pr=mgc.pr
2015-07-05 14:28:58 +02:00
local chunksizer = mgc.maxp.x - mgc.minp.x + 1
local chunksize = chunksizer + 1
local pmapsize = {x = chunksize, y = chunksize, z = chunksize}
2015-07-05 14:28:58 +02:00
local minpxz = {x = mgc.minp.x, y = mgc.minp.z}
2015-07-03 21:26:19 +02:00
for _,descr in pairs(regs) do
local num = math.floor( (chunksize/descr.scarcity) + (pr:next(0,99)/100) )
for vc=1, num do
2015-07-05 14:28:58 +02:00
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)
2015-07-03 21:26:19 +02:00
local step=2/math.max(l1,l2)
for t=0, 1, step do
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 step2=1/vector.distance(P,Q)
for u=0, 1, step2 do
local R=vector.add(vector.multiply(P,(1-u)), vector.multiply(Q,u) )
2015-07-03 21:26:19 +02:00
--<brush>
local di=area:indexp(vector.round(R))
2015-07-03 21:26:19 +02:00
if data[di] then
data[di]=descr.content.id
end
2015-07-03 21:26:19 +02:00
--</brush>
end
end
2015-07-05 14:28:58 +02:00
--<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>
2015-07-03 21:26:19 +02:00
end
end
2015-07-03 21:26:19 +02:00
print("vein "..math.ceil((os.clock() - t1) * 1000).." ms ")
end
table.insert(depositgen.l.OnGenerate,generate)