Explosions: Reduce repeated code

This commit is contained in:
Wuzzy 2020-04-30 21:08:42 +02:00
parent 772ea01aff
commit 679e2b1b70

@ -55,6 +55,7 @@ local function compute_sphere_rays(radius)
local rays = {} local rays = {}
local sphere = {} local sphere = {}
for i=1, 2 do
for y = -radius, radius do for y = -radius, radius do
for z = -radius, radius do for z = -radius, radius do
for x = -radius, 0, 1 do for x = -radius, 0, 1 do
@ -67,20 +68,9 @@ local function compute_sphere_rays(radius)
end end
end end
end end
for y = -radius, radius do
for z = -radius, radius do
for x = radius, 0, -1 do
local d = x * x + y * y + z * z
if d <= radius * radius then
local pos = { x = x, y = y, z = z }
sphere[minetest.hash_node_position(pos)] = pos
break
end
end
end
end end
for i=1,2 do
for x = -radius, radius do for x = -radius, radius do
for z = -radius, radius do for z = -radius, radius do
for y = -radius, 0, 1 do for y = -radius, 0, 1 do
@ -93,20 +83,9 @@ local function compute_sphere_rays(radius)
end end
end end
end end
for x = -radius, radius do
for z = -radius, radius do
for y = radius, 0, -1 do
local d = x * x + y * y + z * z
if d <= radius * radius then
local pos = { x = x, y = y, z = z }
sphere[minetest.hash_node_position(pos)] = pos
break
end
end
end
end end
for i=1,2 do
for x = -radius, radius do for x = -radius, radius do
for y = -radius, radius do for y = -radius, radius do
for z = -radius, 0, 1 do for z = -radius, 0, 1 do
@ -119,18 +98,6 @@ local function compute_sphere_rays(radius)
end end
end end
end end
for x = -radius, radius do
for y = -radius, radius do
for z = radius, 0, -1 do
local d = x * x + y * y + z * z
if d <= radius * radius then
local pos = { x = x, y = y, z = z }
sphere[minetest.hash_node_position(pos)] = pos
break
end
end
end
end end
for _, pos in pairs(sphere) do for _, pos in pairs(sphere) do