From 6084db9335c9c6576b00a4c169d29b83289f9282 Mon Sep 17 00:00:00 2001 From: Cy Date: Wed, 9 Jul 2014 23:34:27 -0700 Subject: [PATCH 1/2] Slight optimization to //set Just noticed I box the one type version in a list, to avoid testing whether it's the one type version, but have to test for that to decide whether to box it or not. Should shave like a whole 3ms from each //set command. --- worldedit/manipulations.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index ee73a2d..a80de8f 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -25,8 +25,11 @@ end --sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled worldedit.set = function(pos1, pos2, nodenames) + local oneNode if type(nodenames) == 'string' then - nodenames = {nodenames} + oneNode = true + else + oneNode = false end local pos1, pos2 = worldedit.sort_pos(pos1, pos2) @@ -48,10 +51,10 @@ worldedit.set = function(pos1, pos2, nodenames) for i,v in ipairs(nodenames) do node_ids[i] = minetest.get_content_id(nodenames[i]) end - if #node_ids == 1 then --only one type of node - local id = node_ids[1] + if oneNode then --only one type of node + local id = node_ids for i in area:iterp(pos1, pos2) do nodes[i] = id end --fill area with node - else --several tpyes of nodes specified + else --several types of nodes specified local id_count, rand = #node_ids, math.random for i in area:iterp(pos1, pos2) do nodes[i] = node_ids[rand(id_count)] end --fill randomly with all types of specified nodes end From f5b67c5bc2de047ec322c5e284bafe00becc84b1 Mon Sep 17 00:00:00 2001 From: Cy Date: Wed, 9 Jul 2014 23:50:41 -0700 Subject: [PATCH 2/2] CPS-ifying stack Continuation Passing Style lets me use minetest.after, so the server gets a chance to not hang in between every stack iteration. Could even set minetest.after(1000,nextone) if you want to see it extend once every second. --- worldedit/manipulations.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index a80de8f..2fa9a1e 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -420,13 +420,19 @@ worldedit.stack = function(pos1, pos2, axis, count) if count < 0 then count = -count length = -length - end - local amount = 0 - local copy = worldedit.copy - for i = 1, count do - amount = amount + length - copy(pos1, pos2, axis, amount) - end + end + local amount = 0 + local copy = worldedit.copy + local i = 1 + function nextone() + if i <= count then + i = i + 1 + amount = amount + length + copy(pos1, pos2, axis, amount) + minetest.after(0,nextone) + end + end + nextone() return worldedit.volume(pos1, pos2) * count end