Skip to content

Commit

Permalink
Block queue doesn't lag anymore on slow operations like digging and p…
Browse files Browse the repository at this point in the history
…lacing nodes, better and more efficient //fixlight.
  • Loading branch information
Uberi committed May 30, 2013
1 parent a1dcc43 commit f952ee4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
18 changes: 7 additions & 11 deletions worldedit/manipulations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -397,19 +397,15 @@ worldedit.fixlight = function(pos1, pos2, env)
if env == nil then env = minetest.env end
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
pos.y = pos1.y
while pos.y <= pos2.y do
pos.z = pos1.z
while pos.z <= pos2.z do
if env:get_node(pos).name == "air" then
env:dig_node(pos)
count = count + 1
end
pos.z = pos.z + 1
pos.z = pos1.z
while pos.z <= pos2.z do
if env:get_node(pos).name == "air" then
env:dig_node(pos)
count = count + 1
end
pos.y = pos.y + 1
pos.z = pos.z + 1
end
pos.x = pos.x + 1
end
Expand Down
50 changes: 30 additions & 20 deletions worldedit/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,39 @@ worldedit = worldedit or {}

worldedit.queue = {}

worldedit.ENABLE_QUEUE = true
worldedit.BLOCKS_PER_GLOBALSTEP = 512
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)
i = 1
while i <= #worldedit.queue and i <= worldedit.BLOCKS_PER_GLOBALSTEP do
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
if worldedit.queue[idx].t == "set_node" then
minetest.env:set_node(worldedit.queue[idx].pos, worldedit.queue[idx].node)
elseif worldedit.queue[idx].t == "remove_node" then
minetest.env:remove_node(worldedit.queue[idx].pos)
elseif worldedit.queue[idx].t == "place_node" then
minetest.env:place_node(worldedit.queue[idx].pos, worldedit.queue[idx].node)
elseif worldedit.queue[idx].t == "dig_node" then
minetest.env:dig_node(worldedit.queue[idx].pos)
elseif worldedit.queue[idx].t == "add_entity" then
minetest.env:add_entity(worldedit.queue[idx].pos, worldedit.queue[idx].name)
elseif worldedit.queue[idx].t == "add_item" then
minetest.env:add_item(worldedit.queue[idx].pos, worldedit.queue[idx].item)
elseif worldedit.queue[idx].t == "meta_from_table" then
minetest.env:get_meta(worldedit.queue[idx].pos):from_table(worldedit.queue[idx].table)
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
if entry.t == "set_node" then
env:set_node(entry.pos, entry.node)
elapsed = elapsed + 0.0002
elseif entry.t == "remove_node" then
env:remove_node(entry.pos)
elapsed = elapsed + 0.0002
elseif entry.t == "place_node" then
env:place_node(entry.pos, entry.node)
elapsed = elapsed + 0.001
elseif entry.t == "dig_node" then
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
print("Unknown queue event type: " .. worldedit.queue[idx].t)
print("Unknown queue event type: " .. entry.t)
end
table.remove(worldedit.queue, idx)
i = i + 1
Expand Down

0 comments on commit f952ee4

Please sign in to comment.