]> git.lizzy.rs Git - worldedit.git/commitdiff
Faster moving using vmanips (in some cases)
authorsfan5 <sfan5@live.de>
Sun, 8 Sep 2019 19:05:30 +0000 (21:05 +0200)
committersfan5 <sfan5@live.de>
Sun, 8 Sep 2019 20:14:07 +0000 (22:14 +0200)
worldedit/manipulations.lua

index 406dc28faa4e1631ec468966e2963893d52f24c3..1858611e4294f06bf2d76d1da9c364f4745de1a1 100644 (file)
@@ -257,16 +257,32 @@ end
 function worldedit.move(pos1, pos2, axis, amount)\r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
 \r
+       local dim = vector.add(vector.subtract(pos2, pos1), 1)\r
+       if math.abs(amount) < dim[axis] then\r
+               -- Source and destination region are overlapping\r
+               -- FIXME: I can't be bothered, so just defer to the legacy code for now.\r
+               return worldedit.legacy_move(pos1, pos2, axis, amount)\r
+       end\r
+\r
+       -- Copy stuff to new location\r
+       local off = {x=0, y=0, z=0}\r
+       off[axis] = amount\r
+       worldedit.copy2(pos1, pos2, off)\r
+       -- Nuke old area\r
+       worldedit.set(pos1, pos2, "air")\r
+\r
+       return worldedit.volume(pos1, pos2)\r
+end\r
+\r
+-- This function is not offical part of the API and may be removed at any time.\r
+function worldedit.legacy_move(pos1, pos2, axis, amount)\r
+       local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+\r
        worldedit.keep_loaded(pos1, pos2)\r
 \r
-       --- TODO: Move slice by slice using schematic method in the move axis\r
-       -- and transfer metadata in separate loop (and if the amount is\r
-       -- greater than the length in the axis, copy whole thing at a time and\r
-       -- erase original after, using schematic method).\r
        local get_node, get_meta, set_node, remove_node = minetest.get_node,\r
                        minetest.get_meta, minetest.set_node, minetest.remove_node\r
        -- Copy things backwards when negative to avoid corruption.\r
-       --- FIXME: Lots of code duplication here.\r
        if amount < 0 then\r
                local pos = {}\r
                pos.x = pos1.x\r