finding ghosts in LuaLogisticNetwork

Things that we aren't going to implement
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

finding ghosts in LuaLogisticNetwork

Post by Optera »

Issue:
Currently finding ghosts within a specific LuaLogisticNetwork is slow and cumbersome in lua.
We have to iterate through every cell in the network to get the area and search on the surface for ghosts.

The main problem with this approach is that overlapping cells scan the same area multiple times resulting in terrible performance.
Now while each mod trying to fetch ghosts could calculate the complete network polygon and break it up into rectangles for find_entities itself, performance would be a lot better if that was a function of LuaLogisticNetwork.
Request:
Extend LuaLogisticNetwork with a find_ghosts function returning all ghosts, tile ghosts and requester proxies within any however shaped logistic network.

Alternatively extend LuaLogisticNetwork with get_coverage returning a polygon and find_entities/find_entities_filtered to consume such a polygon as scan area.
I'm not sure if introducing a polygon data model makes sense, but once introduced it could be used for other things like collision boxes on curved rails.
Boodals
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun Feb 11, 2018 7:10 pm
Contact:

Re: finding ghosts in LuaLogisticNetwork

Post by Boodals »

A better way to do this is to listen to the various entity created events, check if it's a ghost, and put it into a global array. Then loop through them, and use that API function that tells you what logistics cell it's in (if any).
If something doesn't raise an event then you're out of luck though.
Last edited by Boodals on Tue Jul 02, 2019 2:31 pm, edited 1 time in total.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14318
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: finding ghosts in LuaLogisticNetwork

Post by Rseding91 »

What you describe is literally what the game does to dispatch robots to build ghosts. That's why it's limited to only a few per tick at most that it sends robots to work on.
If you want to get ahold of me I'm almost always on Discord.
posila
Factorio Staff
Factorio Staff
Posts: 5357
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: finding ghosts in LuaLogisticNetwork

Post by posila »

Rseding91 wrote: Tue Jul 02, 2019 11:10 am ... literally ...
That's not what the game does at all. It's the other way around. The game has list(s) of ghosts and searches for logistic network that could service them (since single ghost could be within construction range of multiple networks)
Rseding91
Factorio Staff
Factorio Staff
Posts: 14318
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: finding ghosts in LuaLogisticNetwork

Post by Rseding91 »

posila wrote: Tue Jul 02, 2019 1:05 pm
Rseding91 wrote: Tue Jul 02, 2019 11:10 am ... literally ...
That's not what the game does at all. It's the other way around. The game has list(s) of ghosts and searches for logistic network that could service them (since single ghost could be within construction range of multiple networks)
It does both. When a roboport is built it searches.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: finding ghosts in LuaLogisticNetwork

Post by Optera »

Boodals wrote: Tue Jul 02, 2019 10:12 am A better way to do this is to listen to the various entity created events, check if it's a ghost, and put it into a global array. Then loop through them, and use that API function that tells you what logistics cell it's in (if any).
If something doesn't raise an event then you're out of luck though.
Not raising events is a big problem with ghosts and logistics networks.
- building or destroying request proxies doesn't raise events
- changes to logistic networks, from roboports running out of power also doesn't raise events

Another problem is lack of connection between entity and covering logistics_network.
While LuaEntity has logistic_cell and logistic_network those properties are nil for almost all entities including ghost and tile-ghost.

If there was a reliable way to get proxies, caching ghosts could improve performance by swapping finding ghosts on a surface to finding networks on ghost positions entity.surface.find_logistic_network_by_position(entity.position, entity.force) for each ghost.
Post Reply

Return to “Won't implement”