find_entities(_filtered) by entity position

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2919
Joined: Sat Jun 11, 2016 6:41 am
Contact:

find_entities(_filtered) by entity position

Post 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.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: find_entities(_filtered) by entity position

Post by Linver »

+1

I need this too
Last edited by Linver on Wed Mar 18, 2020 2:48 pm, edited 1 time in total.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: find_entities(_filtered) by entity position

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: find_entities(_filtered) by entity position

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: find_entities(_filtered) by entity position

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: find_entities(_filtered) by entity position

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: find_entities(_filtered) by entity position

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: find_entities(_filtered) by entity position

Post 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.

Post Reply

Return to “Modding interface requests”