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.
find_entities(_filtered) by entity position
Re: find_entities(_filtered) by entity position
+1
I need this too
I need this too
Last edited by Linver on Wed Mar 18, 2020 2:48 pm, edited 1 time in total.
Re: find_entities(_filtered) by entity position
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.
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.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: find_entities(_filtered) by entity position
+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.
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: find_entities(_filtered) by entity position
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
https://lua-api.factorio.com/latest/Lua ... ind_entity does that.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.
If you want to get ahold of me I'm almost always on Discord.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: find_entities(_filtered) by entity position
No it doesn't. That's exactly the problem i described above. It finds any entity whichs collision box collides with the given position.Rseding91 wrote: Wed Mar 18, 2020 3:08 pmhttps://lua-api.factorio.com/latest/Lua ... ind_entity does that.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.
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: find_entities(_filtered) by entity position
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:Rseding91 wrote: Wed Mar 18, 2020 3:08 pmhttps://lua-api.factorio.com/latest/Lua ... ind_entity does that.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.
- 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.