Skip to content

Commit

Permalink
Add Block Queue
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Apr 28, 2013
1 parent 71b6004 commit 5e5c1dc
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 84 deletions.
3 changes: 2 additions & 1 deletion worldedit/init.lua
Expand Up @@ -11,4 +11,5 @@ loadmodule(path .. "/primitives.lua")
loadmodule(path .. "/visualization.lua")
loadmodule(path .. "/serialization.lua")
loadmodule(path .. "/code.lua")
loadmodule(path .. "/compatibility.lua")
loadmodule(path .. "/compatibility.lua")
loadmodule(path .. "/queue.lua")
54 changes: 27 additions & 27 deletions worldedit/manipulations.lua
Expand Up @@ -23,9 +23,9 @@ worldedit.volume = function(pos1, pos2)
end

--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
worldedit.set = function(pos1, pos2, nodename)
worldedit.set = function(pos1, pos2, nodename, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env
if env == nil then env = minetest.env end

local node = {name=nodename}
local pos = {x=pos1.x, y=0, z=0}
Expand All @@ -45,9 +45,9 @@ worldedit.set = function(pos1, pos2, nodename)
end

--replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
worldedit.replace = function(pos1, pos2, searchnode, replacenode)
worldedit.replace = function(pos1, pos2, searchnode, replacenode, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env
if env == nil then env = minetest.env end

if minetest.registered_nodes[searchnode] == nil then
searchnode = "default:" .. searchnode
Expand Down Expand Up @@ -75,9 +75,9 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
end

--replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env
if env == nil then env = minetest.env end

if minetest.registered_nodes[searchnode] == nil then
searchnode = "default:" .. searchnode
Expand Down Expand Up @@ -106,9 +106,9 @@ worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
end

--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
worldedit.copy = function(pos1, pos2, axis, amount)
worldedit.copy = function(pos1, pos2, axis, amount, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env
if env == nil then env = minetest.env end

if amount < 0 then
local pos = {x=pos1.x, y=0, z=0}
Expand Down Expand Up @@ -155,9 +155,9 @@ worldedit.copy = function(pos1, pos2, axis, amount)
end

--moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes moved
worldedit.move = function(pos1, pos2, axis, amount)
worldedit.move = function(pos1, pos2, axis, amount, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env
if env == nil then env = minetest.env end

if amount < 0 then
local pos = {x=pos1.x, y=0, z=0}
Expand Down Expand Up @@ -206,7 +206,7 @@ worldedit.move = function(pos1, pos2, axis, amount)
end

--duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times, returning the number of nodes stacked
worldedit.stack = function(pos1, pos2, axis, count)
worldedit.stack = function(pos1, pos2, axis, count, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local length = pos2[axis] - pos1[axis] + 1
if count < 0 then
Expand All @@ -217,13 +217,13 @@ worldedit.stack = function(pos1, pos2, axis, count)
local copy = worldedit.copy
for i = 1, count do
amount = amount + length
copy(pos1, pos2, axis, amount)
copy(pos1, pos2, axis, amount, env)
end
return worldedit.volume(pos1, pos2)
end

--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new position 1, and the new position 2
worldedit.transpose = function(pos1, pos2, axis1, axis2)
worldedit.transpose = function(pos1, pos2, axis1, axis2, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)

local compare
Expand All @@ -245,7 +245,7 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
newpos2[axis2] = pos1[axis2] + extent1

local pos = {x=pos1.x, y=0, z=0}
local env = minetest.env
if env == nil then env = minetest.env end
while pos.x <= pos2.x do
pos.y = pos1.y
while pos.y <= pos2.y do
Expand Down Expand Up @@ -275,13 +275,13 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
end

--flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z"), returning the number of nodes flipped
worldedit.flip = function(pos1, pos2, axis)
worldedit.flip = function(pos1, pos2, axis, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)

local pos = {x=pos1.x, y=0, z=0}
local start = pos1[axis] + pos2[axis]
pos2[axis] = pos1[axis] + math.floor((pos2[axis] - pos1[axis]) / 2)
local env = minetest.env
if env == nil then env = minetest.env end
while pos.x <= pos2.x do
pos.y = pos1.y
while pos.y <= pos2.y do
Expand All @@ -308,7 +308,7 @@ worldedit.flip = function(pos1, pos2, axis)
end

--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around axis `axis` (90 degree increment), returning the number of nodes rotated
worldedit.rotate = function(pos1, pos2, axis, angle)
worldedit.rotate = function(pos1, pos2, axis, angle, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)

local axis1, axis2
Expand All @@ -323,23 +323,23 @@ worldedit.rotate = function(pos1, pos2, axis, angle)

local count
if angle == 90 then
worldedit.flip(pos1, pos2, axis1)
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
worldedit.flip(pos1, pos2, axis1, env)
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
elseif angle == 180 then
worldedit.flip(pos1, pos2, axis1)
count = worldedit.flip(pos1, pos2, axis2)
worldedit.flip(pos1, pos2, axis1, env)
count = worldedit.flip(pos1, pos2, axis2, env)
elseif angle == 270 then
worldedit.flip(pos1, pos2, axis2)
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
worldedit.flip(pos1, pos2, axis2, env)
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
end
return count, pos1, pos2
end

--rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis, returning the number of nodes oriented
worldedit.orient = function(pos1, pos2, angle)
worldedit.orient = function(pos1, pos2, angle, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local nodes = minetest.registered_nodes
local env = minetest.env
if env == nil then env = minetest.env end
local wallmounted = {
[90]={[0]=0, [1]=1, [2]=5, [3]=4, [4]=2, [5]=3},
[180]={[0]=0, [1]=1, [2]=3, [3]=2, [4]=5, [5]=4},
Expand Down Expand Up @@ -392,9 +392,9 @@ worldedit.orient = function(pos1, pos2, angle)
end

--fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated
worldedit.fixlight = function(pos1, pos2)
worldedit.fixlight = function(pos1, pos2, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env
if env == nil then env = minetest.env end
local count = 0

local pos = {x=pos1.x, y=0, z=0}
Expand Down
41 changes: 21 additions & 20 deletions worldedit/primitives.lua
@@ -1,13 +1,13 @@
worldedit = worldedit or {}

--adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.hollow_sphere = function(pos, radius, nodename)
worldedit.hollow_sphere = function(pos, radius, nodename, env)
local node = {name=nodename}
local pos1 = {x=0, y=0, z=0}
local min_radius = radius * (radius - 1)
local max_radius = radius * (radius + 1)
local count = 0
local env = minetest.env
if env == nil then env = minetest.env end
for x = -radius, radius do
pos1.x = pos.x + x
for y = -radius, radius do
Expand All @@ -25,12 +25,12 @@ worldedit.hollow_sphere = function(pos, radius, nodename)
end

--adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.sphere = function(pos, radius, nodename)
worldedit.sphere = function(pos, radius, nodename, env)
local node = {name=nodename}
local pos1 = {x=0, y=0, z=0}
local max_radius = radius * (radius + 1)
local count = 0
local env = minetest.env
if env == nil then env = minetest.env end
for x = -radius, radius do
pos1.x = pos.x + x
for y = -radius, radius do
Expand All @@ -48,13 +48,13 @@ worldedit.sphere = function(pos, radius, nodename)
end

--adds a hollow dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
worldedit.hollow_dome = function(pos, radius, nodename, env) --wip: use bresenham sphere for maximum speed
local node = {name=nodename}
local pos1 = {x=0, y=0, z=0}
local min_radius = radius * (radius - 1)
local max_radius = radius * (radius + 1)
local count = 0
local env = minetest.env
if env == nil then env = minetest.env end
for x = -radius, radius do
pos1.x = pos.x + x
for y = 0, radius do
Expand All @@ -72,12 +72,12 @@ worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sph
end

--adds a dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
worldedit.dome = function(pos, radius, nodename, env) --wip: use bresenham sphere for maximum speed
local node = {name=nodename}
local pos1 = {x=0, y=0, z=0}
local max_radius = radius * (radius + 1)
local count = 0
local env = minetest.env
if env == nil then env = minetest.env end
for x = -radius, radius do
pos1.x = pos.x + x
for y = 0, radius do
Expand All @@ -95,7 +95,7 @@ worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for
end

--adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename, env)
local other1, other2
if axis == "x" then
other1, other2 = "y", "z"
Expand All @@ -105,7 +105,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
other1, other2 = "x", "y"
end

local env = minetest.env
if env == nil then env = minetest.env end
local currentpos = {x=pos.x, y=pos.y, z=pos.z}
local node = {name=nodename}
local count = 0
Expand Down Expand Up @@ -156,7 +156,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
end

--adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.cylinder = function(pos, axis, length, radius, nodename)
worldedit.cylinder = function(pos, axis, length, radius, nodename, env)
local other1, other2
if axis == "x" then
other1, other2 = "y", "z"
Expand All @@ -166,7 +166,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
other1, other2 = "x", "y"
end

local env = minetest.env
if env == nil then env = minetest.env end
local currentpos = {x=pos.x, y=pos.y, z=pos.z}
local node = {name=nodename}
local count = 0
Expand Down Expand Up @@ -215,14 +215,14 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
end

--adds a pyramid at `pos` with height `height`, composed of `nodename`, returning the number of nodes added
worldedit.pyramid = function(pos, height, nodename)
worldedit.pyramid = function(pos, height, nodename, env)
local pos1x, pos1y, pos1z = pos.x - height, pos.y, pos.z - height
local pos2x, pos2y, pos2z = pos.x + height, pos.y + height, pos.z + height
local pos = {x=0, y=pos1y, z=0}

local count = 0
local node = {name=nodename}
local env = minetest.env
if env == nil then env = minetest.env end
while pos.y <= pos2y do --each vertical level of the pyramid
pos.x = pos1x
while pos.x <= pos2x do
Expand All @@ -244,7 +244,7 @@ worldedit.pyramid = function(pos, height, nodename)
end

--adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added
worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean this up
worldedit.spiral = function(pos, width, height, spacer, nodename, env) --wip: clean this up
-- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua
av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end
local function sindex(z, x) -- returns the value at (x, z) in a spiral that starts at 1 and goes outwards
Expand All @@ -262,6 +262,7 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
end
return ret
end
if env == nil then env = minetest.env end
-- connect the joined parts
local spiral = spiralt(width)
height = tonumber(height)
Expand All @@ -279,25 +280,25 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
if lp.x~=np.x then
if lp.x<np.x then
for i=lp.x+1,np.x do
minetest.env:add_node({x=i, y=np.y, z=np.z}, node)
env:add_node({x=i, y=np.y, z=np.z}, node)
count = count + 1
end
else
for i=np.x,lp.x-1 do
minetest.env:add_node({x=i, y=np.y, z=np.z}, node)
env:add_node({x=i, y=np.y, z=np.z}, node)
count = count + 1
end
end
end
if lp.z~=np.z then
if lp.z<np.z then
for i=lp.z+1,np.z do
minetest.env:add_node({x=np.x, y=np.y, z=i}, node)
env:add_node({x=np.x, y=np.y, z=i}, node)
count = count + 1
end
else
for i=np.z,lp.z-1 do
minetest.env:add_node({x=np.x, y=np.y, z=i}, node)
env:add_node({x=np.x, y=np.y, z=i}, node)
count = count + 1
end
end
Expand All @@ -307,4 +308,4 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
end
end
return count
end
end

0 comments on commit 5e5c1dc

Please sign in to comment.