Page 1 of 1

find_entities_filtered searching for multiple names at once

Posted: Mon Apr 30, 2018 2:51 pm
by keyboardhack
Currently i have a mod that has to search the whole map for 8 different entities which each has a different name. Currently this is done by calling find_entities_filtered 8 different times with a different name each time. On large maps this takes more than 16ms. The goal of this interface request is to add an interface that can reduce this lag by only calling a single function to get the entities.

Currently the commands look like this:

Code: Select all

surface.find_entities_filtered({name = name1})
surface.find_entities_filtered({name = name2})
surface.find_entities_filtered({name = name3})
...
surface.find_entities_filtered({name = name8})
I would like to add another way of calling the function so it can take multiple names at once.

Code: Select all

surface.find_entities_filtered({name = {name1, name2, name3,..., name8}})

Re: find_entities_filtered searching for multiple names at once

Posted: Tue May 01, 2018 12:31 am
by Nexela
surface.find_entities_filtered {name = {"A", "b"}, type = {"C", "D"}

yada yada for
name :: string (optional)
type :: string (optional)
ghost_name :: string (optional)
ghost_type :: string (optional)
force :: string or LuaForce (optional)

All of those!

Re: find_entities_filtered searching for multiple names at once

Posted: Tue May 01, 2018 1:33 am
by eradicator
Nexela wrote:surface.find_entities_filtered {name = {"A", "b"}, type = {"C", "D"}

yada yada for
name :: string (optional)
type :: string (optional)
ghost_name :: string (optional)
ghost_type :: string (optional)
force :: string or LuaForce (optional)

All of those!
Interesting. Does that pair or mix? I.e. will it find an A of type D, or only A's of type C?

Re: find_entities_filtered searching for multiple names at once

Posted: Tue May 01, 2018 7:21 am
by Rseding91
Ok.

Re: find_entities_filtered searching for multiple names at once

Posted: Wed May 02, 2018 12:02 am
by eradicator
Rseding91 wrote:Ok.
Do we get both pair and mix modes? Paired sounds more useful for OP.

Re: find_entities_filtered searching for multiple names at once

Posted: Wed May 02, 2018 7:24 am
by Rseding91
eradicator wrote:
Rseding91 wrote:Ok.
Do we get both pair and mix modes? Paired sounds more useful for OP.
What?

Re: find_entities_filtered searching for multiple names at once

Posted: Wed May 02, 2018 8:35 am
by eradicator
Rseding91 wrote:
eradicator wrote:
Rseding91 wrote:Ok.
Do we get both pair and mix modes? Paired sounds more useful for OP.
What?
for something like

Code: Select all

surface.find_entities_filtered {name = {"house", "boat"}, type = {"assembling-machine", "car"}
Will it return car types named "house" or only car types named "boat" and assembling-machine types called "house"? I.e. if multiple lists of filters are specified, is the result the cartesian product of all the filters or not? Becaues for "searching multiple things with one api call" it would be better if it was not a cartesian product. Ofc that only works if all lists are the same length.

Re: find_entities_filtered searching for multiple names at once

Posted: Wed May 02, 2018 8:49 am
by Klonan
eradicator wrote:
Rseding91 wrote:
eradicator wrote:
Rseding91 wrote:Ok.
Do we get both pair and mix modes? Paired sounds more useful for OP.
What?
for something like

Code: Select all

surface.find_entities_filtered {name = {"house", "boat"}, type = {"assembling-machine", "car"}
Will it return car types named "house" or only car types named "boat" and assembling-machine types called "house"? I.e. if multiple lists of filters are specified, is the result the cartesian product of all the filters or not? Becaues for "searching multiple things with one api call" it would be better if it was not a cartesian product. Ofc that only works if all lists are the same length.
It is implemented as an array of filters, so you do

Code: Select all

surface.find_entities_filtered{
  name = {"car", "tank"},
  force = {"enemy", "player"}
}

Re: find_entities_filtered searching for multiple names at once

Posted: Wed May 02, 2018 9:05 am
by eradicator
Oh, so like...

Code: Select all

--Like this?
surface.find_entities_filtered{
 {name = 'car', force = 'enemy'},
 {name='tank', area = area_var},
  type='car',
 --etc
 }
--Or that?
surface.find_entities_filtered{
 {name = 'car', type='car', force = 'enemy'},
 {name='tank', type='car', area = area_var},
 --etc
}
I.e. is are common filter properties per table or can they be specified outside?

Re: find_entities_filtered searching for multiple names at once

Posted: Wed May 02, 2018 11:46 am
by Optera
The API description should be expanded with an example of this multi filter search.

Re: find_entities_filtered searching for multiple names at once

Posted: Wed May 02, 2018 6:53 pm
by Rseding91
The filters work identical to before except now each section that supports an array is all or-ed inside that one filter.

Re: find_entities_filtered searching for multiple names at once

Posted: Wed May 02, 2018 11:36 pm
by Nexela
Optera wrote:The API description should be expanded with an example of this multi filter search.
It was :P

name = string or array of strings