Skip to content
Permalink
Browse files
Fix //rotate, improve queue (order now preserved), typos fixed (quene…
… -> queue).
  • Loading branch information
Uberi committed May 31, 2013
1 parent f952ee4 commit 0664cde287d2c0c8b3cc8bd0e8bf468e5921b1a7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 54 deletions.
@@ -1,17 +1,17 @@
worldedit = worldedit or {}

worldedit.queue = {}
worldedit.lower = 1
worldedit.higher = 0

worldedit.ENABLE_QUEUE = true --enable the WorldEdit block queue
worldedit.MAXIMUM_TIME = 0.08 --maximum time each step alloted for WorldEdit operations

minetest.register_globalstep(function(dtime)
local i = 1
local elapsed = 0
local env = minetest.env
while i <= #worldedit.queue and elapsed <= worldedit.MAXIMUM_TIME do
local idx = (#worldedit.queue + 1) - i
local entry = worldedit.queue[idx] --we use the last entry, so we don't spend days moving stuff in the table because we removed the first entry
while worldedit.lower <= worldedit.higher and elapsed <= worldedit.MAXIMUM_TIME do
local entry = worldedit.queue[worldedit.lower]
if entry.t == "set_node" then
env:set_node(entry.pos, entry.node)
elapsed = elapsed + 0.0002
@@ -36,11 +36,18 @@ minetest.register_globalstep(function(dtime)
else
print("Unknown queue event type: " .. entry.t)
end
table.remove(worldedit.queue, idx)
i = i + 1
worldedit.queue[worldedit.lower] = nil
worldedit.lower = worldedit.lower + 1
end
end)

do
worldedit.enqueue = function(value)
worldedit.higher = worldedit.higher + 1
worldedit.queue[worldedit.higher] = value
end
end

function table.copy(t, seen)
seen = seen or {}
if t == nil then return nil end
@@ -58,39 +65,39 @@ function table.copy(t, seen)
return nt
end

local quene_setnode = function(self, pos_, node_)
table.insert(worldedit.queue, {pos=table.copy(pos_), node=table.copy(node_), t="set_node"})
local queue_setnode = function(self, pos_, node_)
worldedit.enqueue({pos=table.copy(pos_), node=table.copy(node_), t="set_node"})
end

local quene_removenode = function(self, pos_)
table.insert(worldedit.queue, {pos=table.copy(pos_), t="remove_node"})
local queue_removenode = function(self, pos_)
worldedit.enqueue({pos=table.copy(pos_), t="remove_node"})
end

local quene_placenode = function(self, pos_, node_)
table.insert(worldedit.queue, {pos=table.copy(pos_), node=table.copy(node_), t="place_node"})
local queue_placenode = function(self, pos_, node_)
worldedit.enqueue({pos=table.copy(pos_), node=table.copy(node_), t="place_node"})
end

local quene_dignode = function(self, pos_)
table.insert(worldedit.queue, {pos=table.copy(pos_), t="dig_node"})
local queue_dignode = function(self, pos_)
worldedit.enqueue({pos=table.copy(pos_), t="dig_node"})
end

local quene_addentity = function(self, pos_, name_)
table.insert(worldedit.queue, {pos=table.copy(pos_), name=name_.."", t="add_entity"})
local queue_addentity = function(self, pos_, name_)
worldedit.enqueue({pos=table.copy(pos_), name=name_.."", t="add_entity"})
end

local quene_additem = function(self, pos_, item_)
table.insert(worldedit.queue, {pos=table.copy(pos_), item=item_.."", t="add_item"})
local queue_additem = function(self, pos_, item_)
worldedit.enqueue({pos=table.copy(pos_), item=item_.."", t="add_item"})
end

local quene_setmeta = function(self, pos_, table_)
table.insert(worldedit.queue, {pos=table.copy(pos_), table=table.copy(table_), t="meta_from_table"})
local queue_setmeta = function(self, pos_, table_)
worldedit.enqueue({pos=table.copy(pos_), table=table.copy(table_), t="meta_from_table"})
end

local aliasmeta = {
-- the other functions are left out because they are not used in worldedit
to_table = function(self) return minetest.env:get_meta(self._pos):to_table() end,
set_string = function(self, name_, value_) minetest.env:get_meta(self._pos):set_string(name_, value_) end,
from_table = function(self, tbl) quene_setmeta(nil, self._pos, tbl) end,
from_table = function(self, tbl) queue_setmeta(nil, self._pos, tbl) end,
}

local get_meta_alias = function(self, pos)
@@ -99,20 +106,20 @@ local get_meta_alias = function(self, pos)
return am
end

worldedit.quene_aliasenv = {
worldedit.queue_aliasenv = {
-- ALL functions that are not just piped to the real minetest.env function must copy the arguments, not just reference them
set_node = quene_setnode,
add_node = quene_setnode,
remove_node = quene_removenode,
set_node = queue_setnode,
add_node = queue_setnode,
remove_node = queue_removenode,
get_node = function(self, pos) return minetest.env:get_node(pos) end,
get_node_or_nil = function(self, pos) return minetest.env:get_node_or_nil(pos) end,
get_node_light = function(self, pos, timeofday) return minetest.env:get_node_light(pos, timeofday) end,
place_node = quene_placenode,
dig_node = quene_dignode,
place_node = queue_placenode,
dig_node = queue_dignode,
punch_node = function(self, pos) return minetest.env:punch_node(pos) end,
get_meta = get_meta_alias,
get_node_timer = function(self, pos) return minetest.env:get_node_timer(pos) end,
add_entity = quene_addentity,
add_item = quene_additem,
add_entity = queue_addentity,
add_item = queue_additem,
}

@@ -185,7 +185,7 @@ minetest.register_chatcommand("/set", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end

local count = worldedit.set(pos1, pos2, param, tenv)
@@ -220,7 +220,7 @@ minetest.register_chatcommand("/replace", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.replace(pos1, pos2, searchnode, replacenode, tenv)
worldedit.player_notify(name, count .. " nodes replaced")
@@ -254,7 +254,7 @@ minetest.register_chatcommand("/replaceinverse", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode, tenv)
worldedit.player_notify(name, count .. " nodes replaced")
@@ -284,7 +284,7 @@ minetest.register_chatcommand("/hollowsphere", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename, tenv)
worldedit.player_notify(name, count .. " nodes added")
@@ -314,7 +314,7 @@ minetest.register_chatcommand("/sphere", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.sphere(pos, tonumber(radius), nodename, tenv)
worldedit.player_notify(name, count .. " nodes added")
@@ -344,7 +344,7 @@ minetest.register_chatcommand("/hollowdome", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.hollow_dome(pos, tonumber(radius), nodename, tenv)
worldedit.player_notify(name, count .. " nodes added")
@@ -374,7 +374,7 @@ minetest.register_chatcommand("/dome", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.dome(pos, tonumber(radius), nodename, tenv)
worldedit.player_notify(name, count .. " nodes added")
@@ -408,7 +408,7 @@ minetest.register_chatcommand("/hollowcylinder", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename, tenv)
worldedit.player_notify(name, count .. " nodes added")
@@ -442,7 +442,7 @@ minetest.register_chatcommand("/cylinder", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename, tenv)
worldedit.player_notify(name, count .. " nodes added")
@@ -472,7 +472,7 @@ minetest.register_chatcommand("/pyramid", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.pyramid(pos, tonumber(size), nodename, tenv)
worldedit.player_notify(name, count .. " nodes added")
@@ -502,7 +502,7 @@ minetest.register_chatcommand("/spiral", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), nodename, tenv)
worldedit.player_notify(name, count .. " nodes added")
@@ -532,7 +532,7 @@ minetest.register_chatcommand("/copy", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
worldedit.player_notify(name, count .. " nodes copied")
@@ -560,8 +560,11 @@ minetest.register_chatcommand("/move", {
amount = amount * sign
end

--Do NOT use the queue here, it'll mess it up

This comment has been minimized.

Copy link
@sfan5

sfan5 Jun 19, 2013

Collaborator

This is here for a reason...

This comment has been minimized.

Copy link
@Uberi

Uberi Jun 19, 2013

Author Owner

Well, it seems to work fine now that the queue goes in the forward order, I haven't encountered any issues with moving some really large structures so I assume it's fixed now :)

When it consumed the queue backwards, it caused all these strange striping issues, IIRC.

local count = worldedit.move(pos1, pos2, axis, tonumber(amount))
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.move(pos1, pos2, axis, tonumber(amount), tenv)

pos1[axis] = pos1[axis] + amount
pos2[axis] = pos2[axis] + amount
@@ -594,7 +597,7 @@ minetest.register_chatcommand("/stack", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)
worldedit.player_notify(name, count .. " nodes stacked")
@@ -630,7 +633,7 @@ minetest.register_chatcommand("/transpose", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, tenv)

@@ -665,7 +668,7 @@ minetest.register_chatcommand("/flip", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.flip(pos1, pos2, param, tenv)
worldedit.player_notify(name, count .. " nodes flipped")
@@ -698,7 +701,7 @@ minetest.register_chatcommand("/rotate", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle, tenv)

@@ -735,7 +738,7 @@ minetest.register_chatcommand("/orient", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.orient(pos1, pos2, angle, tenv)

@@ -756,7 +759,7 @@ minetest.register_chatcommand("/fixlight", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.fixlight(pos1, pos2, tenv)
worldedit.player_notify(name, count .. " nodes updated")
@@ -776,7 +779,7 @@ minetest.register_chatcommand("/hide", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.hide(pos1, pos2, tenv)
worldedit.player_notify(name, count .. " nodes hidden")
@@ -801,7 +804,7 @@ minetest.register_chatcommand("/suppress", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.suppress(pos1, pos2, param, tenv)
worldedit.player_notify(name, count .. " nodes suppressed")
@@ -826,7 +829,7 @@ minetest.register_chatcommand("/highlight", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.highlight(pos1, pos2, param, tenv)
worldedit.player_notify(name, count .. " nodes highlighted")
@@ -846,7 +849,7 @@ minetest.register_chatcommand("/restore", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.restore(pos1, pos2, tenv)
worldedit.player_notify(name, count .. " nodes restored")
@@ -970,7 +973,7 @@ minetest.register_chatcommand("/load", {

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
tenv = worldedit.queue_aliasenv
end
local count = worldedit.deserialize(pos1, value, tenv)

0 comments on commit 0664cde

Please sign in to comment.