LuaSurface.find_entities_filtered: deconstruction request
-
- Manual Inserter
- Posts: 3
- Joined: Sat Aug 12, 2017 10:20 pm
- Contact:
LuaSurface.find_entities_filtered: deconstruction request
Request: add a deconstruction_requested filter to LuaSurface.find_entities_filtered. This doesn't add any capabilities that are strictly new, but it'd have a big performance advantage over getting all the entities and filtering from the Lua side. This is important for Bluebuild, which currently ships broken - it looks for deconstruction-requested entities within reach, but limits the search to 40 entities because otherwise it'd tank the framerate with reach-extending mods or when in a forest, and if there are 40 entities nearby that are *not* marked for deconstruction then it'll fail to notice entities which are.
Re: LuaSurface.find_entities_filtered: deconstruction request
You could run the checking over multiple ticks if you'd like,jimrandomh wrote:Request: add a deconstruction_requested filter to LuaSurface.find_entities_filtered. This doesn't add any capabilities that are strictly new, but it'd have a big performance advantage over getting all the entities and filtering from the Lua side. This is important for Bluebuild, which currently ships broken - it looks for deconstruction-requested entities within reach, but limits the search to 40 entities because otherwise it'd tank the framerate with reach-extending mods or when in a forest, and if there are 40 entities nearby that are *not* marked for deconstruction then it'll fail to notice entities which are.
Would work with something like this
Code: Select all
function on_tick(player)
if game.tick % 60 == 0 then
local entities = {}
for k = 1, 60 do entities[k] = {} end
for k, entity in pairs (surface.find_entities{Here, there, player.this and that}) do
index = k % 60
table.insert(entities[index], entity)
end
global.entities[player.name] = entities
end
if not global.entities then return end
if not global.entities[player.name] then return end
for k, entity in pairs (global.entities[player.name]) do
check_entity(entity)
end
end
Re: LuaSurface.find_entities_filtered: deconstruction request
See viewtopic.php?p=491368#p491368, has been implemented. Currently undocumented (fixed for next version), parameter is a to_be_deconstructed bool.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.