Page 1 of 1

LuaSurface.find_entities_filtered: deconstruction request

Posted: Sat Sep 23, 2017 7:16 pm
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.

Re: LuaSurface.find_entities_filtered: deconstruction request

Posted: Sat Sep 23, 2017 9:05 pm
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

Re: LuaSurface.find_entities_filtered: deconstruction request

Posted: Tue Sep 01, 2020 8:09 am
by Bilka
See viewtopic.php?p=491368#p491368, has been implemented. Currently undocumented (fixed for next version), parameter is a to_be_deconstructed bool.