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

Block queue doesn't lag anymore on slow operations like digging and placing nodes, better and more efficient //fixlight.

This commit is contained in:
Anthony Zhang 2013-05-30 19:05:45 -04:00
parent a1dcc43210
commit f952ee4740
2 changed files with 37 additions and 31 deletions

View File

@ -397,19 +397,15 @@ worldedit.fixlight = function(pos1, pos2, env)
if env == nil then env = minetest.env end if env == nil then env = minetest.env end
local count = 0 local count = 0
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=pos2.y, z=0}
while pos.x <= pos2.x do while pos.x <= pos2.x do
pos.y = pos1.y pos.z = pos1.z
while pos.y <= pos2.y do while pos.z <= pos2.z do
pos.z = pos1.z if env:get_node(pos).name == "air" then
while pos.z <= pos2.z do env:dig_node(pos)
if env:get_node(pos).name == "air" then count = count + 1
env:dig_node(pos)
count = count + 1
end
pos.z = pos.z + 1
end end
pos.y = pos.y + 1 pos.z = pos.z + 1
end end
pos.x = pos.x + 1 pos.x = pos.x + 1
end end

View File

@ -2,29 +2,39 @@ worldedit = worldedit or {}
worldedit.queue = {} worldedit.queue = {}
worldedit.ENABLE_QUEUE = true worldedit.ENABLE_QUEUE = true --enable the WorldEdit block queue
worldedit.BLOCKS_PER_GLOBALSTEP = 512 worldedit.MAXIMUM_TIME = 0.08 --maximum time each step alloted for WorldEdit operations
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
i = 1 local i = 1
while i <= #worldedit.queue and i <= worldedit.BLOCKS_PER_GLOBALSTEP do local elapsed = 0
idx = (#worldedit.queue + 1) - i -- we use the last entry, so we don't spend days moving stuff in the table because we removed the first entry local env = minetest.env
if worldedit.queue[idx].t == "set_node" then while i <= #worldedit.queue and elapsed <= worldedit.MAXIMUM_TIME do
minetest.env:set_node(worldedit.queue[idx].pos, worldedit.queue[idx].node) local idx = (#worldedit.queue + 1) - i
elseif worldedit.queue[idx].t == "remove_node" then 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
minetest.env:remove_node(worldedit.queue[idx].pos) if entry.t == "set_node" then
elseif worldedit.queue[idx].t == "place_node" then env:set_node(entry.pos, entry.node)
minetest.env:place_node(worldedit.queue[idx].pos, worldedit.queue[idx].node) elapsed = elapsed + 0.0002
elseif worldedit.queue[idx].t == "dig_node" then elseif entry.t == "remove_node" then
minetest.env:dig_node(worldedit.queue[idx].pos) env:remove_node(entry.pos)
elseif worldedit.queue[idx].t == "add_entity" then elapsed = elapsed + 0.0002
minetest.env:add_entity(worldedit.queue[idx].pos, worldedit.queue[idx].name) elseif entry.t == "place_node" then
elseif worldedit.queue[idx].t == "add_item" then env:place_node(entry.pos, entry.node)
minetest.env:add_item(worldedit.queue[idx].pos, worldedit.queue[idx].item) elapsed = elapsed + 0.001
elseif worldedit.queue[idx].t == "meta_from_table" then elseif entry.t == "dig_node" then
minetest.env:get_meta(worldedit.queue[idx].pos):from_table(worldedit.queue[idx].table) env:dig_node(entry.pos)
elapsed = elapsed + 0.001
elseif entry.t == "add_entity" then
env:add_entity(entry.pos, entry.name)
elapsed = elapsed + 0.005
elseif entry.t == "add_item" then
env:add_item(entry.pos, entry.item)
elapsed = elapsed + 0.005
elseif entry.t == "meta_from_table" then
env:get_meta(entry.pos):from_table(entry.table)
elapsed = elapsed + 0.0002
else else
print("Unknown queue event type: " .. worldedit.queue[idx].t) print("Unknown queue event type: " .. entry.t)
end end
table.remove(worldedit.queue, idx) table.remove(worldedit.queue, idx)
i = i + 1 i = i + 1