improve flood_fill
api function.
make `flood_fill` able to be interrupted if its callback returns false; the meaning that was previously indicated by this return value is now indicated by nil instead. update code that uses this function to account for this change.
This commit is contained in:
parent
00829dbce9
commit
3459e94de8
2 changed files with 14 additions and 10 deletions
|
@ -58,7 +58,9 @@ function blockgame.flood_fill (start, step, max_range)
|
|||
local matches = {}
|
||||
local rejected = {}
|
||||
|
||||
while #queue > 0 do
|
||||
local cancel = false
|
||||
|
||||
while #queue > 0 and not cancel do
|
||||
local current = table.remove(queue, 1)
|
||||
local pos = current.pos
|
||||
local range = current.range
|
||||
|
@ -66,14 +68,18 @@ function blockgame.flood_fill (start, step, max_range)
|
|||
local hash = minetest.hash_node_position(pos)
|
||||
|
||||
if not visited[hash] and range <= max_range and step(pos, range) then
|
||||
table.insert(matches, pos)
|
||||
local step_result = step(pos, range)
|
||||
|
||||
local neighbors = blockgame.vector.get_neighbors(pos)
|
||||
for _, p in pairs(neighbors) do
|
||||
table.insert(queue, { pos = p, range = range + 1 })
|
||||
end
|
||||
else
|
||||
table.insert(rejected, pos)
|
||||
if step_result then
|
||||
table.insert(matches, pos)
|
||||
|
||||
local neighbors = blockgame.vector.get_neighbors(pos)
|
||||
for _, p in pairs(neighbors) do
|
||||
table.insert(queue, { pos = p, range = range + 1 })
|
||||
end
|
||||
elseif step_result == nil then
|
||||
table.insert(rejected, pos)
|
||||
else cancel = true end
|
||||
end
|
||||
|
||||
visited[hash] = true
|
||||
|
|
|
@ -70,8 +70,6 @@ blockgame.register_increasing_abm({
|
|||
score = score + math.floor(decompose_node_scores[name] / distance)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end, 4)
|
||||
|
||||
return data.value + score
|
||||
|
|
Loading…
Reference in a new issue