Page 1 of 1
find_entities(_filtered) by entity position
Posted: Sun Mar 08, 2020 3:54 pm
by Optera
Currently find_entities(_filtered) checks if the bounding box of the entity is within the search area.
When we want to know if the entity position is within an area we have to first find_entities{area} then check again if the resulting entities positions are within the area as well.
It would be much faster if we had a way to directly find only entities whose positions are within an area. Checking positions against bounding boxes is faster than the current find_entities, so for quite a few of my other mods where I only care where the entity position is, that would also be a welcome performance boost.
Re: find_entities(_filtered) by entity position
Posted: Fri Mar 13, 2020 9:02 am
by Linver
+1
I need this too
Re: find_entities(_filtered) by entity position
Posted: Sat Mar 14, 2020 4:27 pm
by Rseding91
The game engine is only able to search by bounding box and then it would just do the same check you're doing now: see if the position is inside the original search bounding box.
I'm not 100% against the idea of re-working the find functions to better support expanding and adding in things like this but right now it's kind of a mess that has had random features tacked onto it over time and I don't want to tack on another at the moment.
Re: find_entities(_filtered) by entity position
Posted: Sun Mar 15, 2020 8:22 am
by eradicator
+1
I got shot into the foot by this too the other day. I needed to know if there exists a LuaEntity with LuaEntity.position == target_position, but then i noticed that "Find a specific entity at a specific position." (find_entity) means any entity which has the target position inside it's bounding box and had to add another check.
Re: find_entities(_filtered) by entity position
Posted: Wed Mar 18, 2020 2:50 pm
by Linver
Is very easy find cases when is needed to know if an entity exist in a position, for example I use a list of entities that I process slowly on tick to reduce the volume of operation in the same instant. When this list of entities is overpopulated, will be helpful know if that entity exist in the last know position, and I think this will be less expensive that ask to find an entity in bounding box of 1x1 near that position.
Re: find_entities(_filtered) by entity position
Posted: Wed Mar 18, 2020 3:08 pm
by Rseding91
Linver wrote: Wed Mar 18, 2020 2:50 pm
Is very easy find cases when is needed to know if an entity exist in a position, for example I use a list of entities that I process slowly on tick to reduce the volume of operation in the same instant. When this list of entities is overpopulated, will be helpful know if that entity exist in the last know position, and I think this will be less expensive that ask to find an entity in bounding box of 1x1 near that position.
https://lua-api.factorio.com/latest/Lua ... ind_entity does that.
Re: find_entities(_filtered) by entity position
Posted: Wed Mar 18, 2020 4:35 pm
by eradicator
Rseding91 wrote: Wed Mar 18, 2020 3:08 pm
Linver wrote: Wed Mar 18, 2020 2:50 pm
Is very easy find cases when is needed to know if an entity exist in a position, for example I use a list of entities that I process slowly on tick to reduce the volume of operation in the same instant. When this list of entities is overpopulated, will be helpful know if that entity exist in the last know position, and I think this will be less expensive that ask to find an entity in bounding box of 1x1 near that position.
https://lua-api.factorio.com/latest/Lua ... ind_entity does that.
No it doesn't. That's exactly the problem i described above. It finds any entity whichs collision box collides with the given position.
Re: find_entities(_filtered) by entity position
Posted: Wed Mar 18, 2020 5:40 pm
by Linver
Rseding91 wrote: Wed Mar 18, 2020 3:08 pm
Linver wrote: Wed Mar 18, 2020 2:50 pm
Is very easy find cases when is needed to know if an entity exist in a position, for example I use a list of entities that I process slowly on tick to reduce the volume of operation in the same instant. When this list of entities is overpopulated, will be helpful know if that entity exist in the last know position, and I think this will be less expensive that ask to find an entity in bounding box of 1x1 near that position.
https://lua-api.factorio.com/latest/Lua ... ind_entity does that.
Eh eh, the situation is slightly different... that function give a back a
LuaEntity given a entity-prototype-name and a position, in my case I have to check the position for a
Prototype/EnemySpawner, for use this function I have to save the name of the entity prototype in first step. I will explane the difference with two sentence:
- Give me the entity instance of the specific X entity prototype in the specific position (find_entity case)
- Give me the entities instances of subclass Y in the specific position
PS: I'm noticing now that I don't know how predict the result of find_entity in the case that exist two identical entities one over another.