diff options
author | Anthony Zhang <azhang9@gmail.com> | 2013-05-30 20:38:56 -0400 |
---|---|---|
committer | Anthony Zhang <azhang9@gmail.com> | 2013-05-30 20:38:56 -0400 |
commit | 0664cde287d2c0c8b3cc8bd0e8bf468e5921b1a7 (patch) | |
tree | c7703c5f24e7bd5860ca8fc745b4981b2e4e511b /worldedit | |
parent | f952ee47401efc2202eb8a1cdfa84ec0d8bd04e2 (diff) |
Fix //rotate, improve queue (order now preserved), typos fixed (quene -> queue).
Diffstat (limited to 'worldedit')
-rw-r--r-- | worldedit/queue.lua | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/worldedit/queue.lua b/worldedit/queue.lua index 8264ebf..cf80cf7 100644 --- a/worldedit/queue.lua +++ b/worldedit/queue.lua @@ -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, } |