LuaSurface.find_entities_filtered: deconstruction request

Post Reply
jimrandomh
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Aug 12, 2017 10:20 pm
Contact:

LuaSurface.find_entities_filtered: deconstruction request

Post by jimrandomh »

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.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: LuaSurface.find_entities_filtered: deconstruction request

Post by Klonan »

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.
You could run the checking over multiple ticks if you'd like,
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

Bilka
Factorio Staff
Factorio Staff
Posts: 3129
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: LuaSurface.find_entities_filtered: deconstruction request

Post by Bilka »

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.

Post Reply

Return to “Implemented mod requests”