Checking for enviroment.
[rocks.git] / rocks / veins.lua
blobc7ec2b6026b982a712e4eef2f21feb3c207808ce
1 -- experimental fast vein generator
3 rocks.veins={}
5 table.insert(rocks.veins,{
6 scarcity=80,
8 })
11 rocksl.genvein=function(minp,maxp,pr,vm,area)
12 local t1 = os.clock()
13 local data = vm:get_data()
15 local chunksizer = maxp.x - minp.x + 1
16 local chunksize = chunksizer + 1
17 local pmapsize = {x = chunksize, y = chunksize, z = chunksize}
18 local minpxz = {x = minp.x, y = minp.z}
19 local c_sample=minetest.get_content_id("default:stone")
20 local c_sample_ore=minetest.get_content_id("default:mese")
23 local A=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
24 local B=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
25 local C=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
26 local D=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z)
27 local l1=vector.distance(A,C)+vector.distance(C,B)
28 local l2=vector.distance(A,D)+vector.distance(D,B)
29 local step=1.4/math.max(l1,l2)
30 print("step="..step.." l1="..l1.." l2="..l2)
31 local scarcity=6
32 local ocn=pr:next(0,scarcity)+(scarcity/2)
33 for t=0, 1, step do
34 local P=vector.multiply(A,(1-t)^2)
35 P=vector.add(P, vector.multiply(B,t*t) )
36 local Q=vector.add(P, vector.multiply(D,2*t*(1-t)) )
37 P=vector.add(P, vector.multiply(C,2*t*(1-t)) )
38 local step2=1/vector.distance(P,Q)
39 for u=0, 1, step2 do
40 local R=vector.add(vector.multiply(P,(1-u)), vector.multiply(Q,u) )
41 local di=area:indexp(vector.round(R))
42 if ocn<1 then
43 data[di]=c_sample_ore
44 ocn=pr:next(0,scarcity)+(scarcity/2)
45 else
46 data[di]=c_sample
47 ocn=ocn-1
48 end
49 end
50 end
52 vm:set_data(data)
53 minetest.log("action", "rocks/genvein/ "..math.ceil((os.clock() - t1) * 1000).." ms ")
54 end