1
0
mirror of git://repo.or.cz/rocks.git synced 2025-01-04 07:10:28 +01:00
rocks/depositgen/pipes.lua

115 lines
3.2 KiB
Lua
Raw Normal View History

2015-06-30 13:48:02 +02:00
-- experimental pipe generator
2015-07-02 15:47:17 +02:00
local l=depositgen.l
local print=l.print
2015-06-30 13:48:02 +02:00
-- the public table of registered pipes
depositgen.pipes={}
local regs=depositgen.pipes
depositgen.register_pipe= function(descr)
local pipe={
ymin=(descr.ymin or -10000),
ymax=(descr.ymax or 200),
scarcity=descr.scarcity,
2015-07-02 15:47:17 +02:00
width=descr.width-1,
2015-06-30 13:48:02 +02:00
content={ name=descr.content },
scatter={}
}
table.insert(depositgen.l.ToResolve,pipe.content)
for _,sc in pairs(descr.scatter) do
local psc={
scarcity=sc.scarcity,
2015-07-02 15:47:17 +02:00
size=(sc.size or pipe.width),
2015-06-30 13:48:02 +02:00
density=sc.density,
content={ name=sc.content }
}
table.insert(depositgen.l.ToResolve,psc.content)
table.insert(pipe.scatter,psc)
end
return table.insert(regs,pipe)
end
2015-07-03 20:47:40 +02:00
do
local sample_pipe_def={
2015-06-30 13:48:02 +02:00
ymin=-200, ymax=-6,
scarcity=80,
2015-07-02 16:01:27 +02:00
width=4,
content="default:glass",
2015-06-30 13:48:02 +02:00
scatter={
2015-07-02 16:01:27 +02:00
{ scarcity=7, density=4, content="default:mese", size=2 }
2015-06-30 13:48:02 +02:00
}
2015-07-03 20:47:40 +02:00
}
--depositgen.register_pipe(sample_pipe_def)
end
2015-05-10 13:59:05 +02:00
2015-07-02 16:01:27 +02:00
depositgen.l.ToResolve.air={name="air"}
2015-07-02 15:47:17 +02:00
local function generate(minp,maxp,pr,vm,area)
2015-05-10 13:59:05 +02:00
local t1 = os.clock()
2015-07-02 15:47:17 +02:00
2015-05-10 13:59:05 +02:00
local data = vm:get_data()
2015-05-10 16:05:48 +02:00
local chunksizer = maxp.x - minp.x + 1
local chunksize = chunksizer + 1
2015-05-10 13:59:05 +02:00
local pmapsize = {x = chunksize, y = chunksize, z = chunksize}
local minpxz = {x = minp.x, y = minp.z}
2015-07-02 15:47:17 +02:00
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))
2015-05-10 13:59:05 +02:00
2015-07-02 15:47:17 +02:00
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 step=(1.8)/(vector.distance(pointA,pointB)+vector.distance(pointB,pointC))
for t=0, 1, step do
local p=vector.multiply(pointA,(1-t)^2)
2015-07-03 20:47:40 +02:00
local di
2015-07-02 15:47:17 +02:00
p=vector.add(p, vector.multiply(pointB,2*t*(1-t)) )
p=vector.add(p, vector.multiply(pointC,t*t) )
p=vector.round(p)
local radiusp=math.floor(descr.width/2)
local radiusn=-descr.width+radiusp
--<scatter>
for _,ore in pairs(descr.scatter) do
if pr:next(0,ore.scarcity)==0 then
local ocx=pr:next(radiusn,radiusp)
local ocy=pr:next(radiusn,radiusp)
local ocz=pr:next(radiusn,radiusp)
for y=ocy-ore.size, ocy+ore.size do
for x=ocx-ore.size, ocx+ore.size do
for z=ocz-ore.size, ocz+ore.size do
if pr:next(0,ore.density)==0 then
di=area:index(p.x+x,p.y+y,p.z+z)
2015-07-02 16:01:27 +02:00
if data[di]==depositgen.l.ToResolve.air.id then
data[di]=ore.content.id
end
2015-07-02 15:47:17 +02:00
end
end end end
end
end
--</scatter>
--<brush>
for y= radiusn, radiusp do
for x= radiusn, radiusp do
for z= radiusn, radiusp do
di=area:index(p.x+x,p.y+y,p.z+z)
2015-07-02 16:01:27 +02:00
if data[di]==depositgen.l.ToResolve.air.id then
data[di]=descr.content.id
end
2015-07-02 15:47:17 +02:00
end end end
--</brush>
--brush(data,area,p,descr.radius,content,descr.scatter,orepr)
end
2015-05-10 13:59:05 +02:00
end
2015-07-02 15:47:17 +02:00
end --</apipe>
2015-05-10 13:59:05 +02:00
vm:set_data(data)
2015-07-02 15:47:17 +02:00
l.print("pipes "..math.ceil((os.clock() - t1) * 1000).." ms ")
2015-06-30 13:48:02 +02:00
end
table.insert(depositgen.l.OnGenerate,generate)