1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-12-25 02:00:39 +01:00

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.
This commit is contained in:
Cy 2014-07-09 23:34:27 -07:00
parent b70fd16da4
commit 6084db9335

View File

@ -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