Please add signal changed event filter

Things that we aren't going to implement
Post Reply
mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Please add signal changed event filter

Post by mrvn »

TL;DR
For the EventFilter class add a new child SignalChangedEventFilter that can be used to receive events when the signals of an entity change.
What ?
Add a new EventFilter:

filter SignalChangedEventFilter

filter :: string | The condition to filter on. "signal-changed"
mode :: string | How to combine this with the previous filter. Must be "or" or "and". Defaults to "or". When evaluating the filters, "and" has higher precedence than "or".
invert :: boolean | Inverts the condition. Default is false.

Other attributes may be specified depending on filter:

entity :: int | ID of entity to watch for signal changes

The entity must be one that wakes up when a signal connected to it changes. Like an arithmetic combinator. But it would be nice to have this for lamps too if not for any entity with a circuit connection. When the entity wakes up due to a change in circuit signals the event fires.


Additionally it might be nice to have a dedicated SignalFilter entity. This would be an extended decider combinator. Instead of having just one DeciderCombinatorParameters it should have a list. Each condition is evaluated and the outputs are summed. The SignalChangedEvent is triggered when the output changes. For example:

Iron Plate >= 1000 ===> 1x Iron Plate
Copper Plate >= 2000 ===> 1x Copper Plate

The SignalChangedEvent would fire whenever Iron Plates pass the 1000 units threshold or Copper Plates pass the 2000 units threshold going either way. The SignalChangedEvent could include the list of output signals of the conditons to make it even easier for LUA scripts. So the script would only see the Iron Plate and Copper Plate event and only if they are 1 in this case.

Note: the SignalChangedEvent would not fire when Iron Plates go from 1363 to 1364 since the output has copy_count_from_input=false. The Iron Plate output signal would remain at 1 so no change. This would allow to really reduce the number of SignalChangedEvents for most cases.
Why ?
There are many mods that want to react to circuit signals. Doing this efficiently is hard since signals must be scanned in on_tick and the script is flooded with all the signals on the circuit network. If more than a handful of entities are used that want to react to circuit signals then one has to add extra logic so only one or a few are scanned each tick. Examples for this are the LTN Train Stops that need to schedule trains when enough items collect in buffer chests or enough are used up. The SignalChangedEvent would make it possible for the LTN Train Stop to "wake up" when the input signals change and only scan the circuit networks for each stop when needed.

Often the decision when to act comes down to a simple list of conditions like in the above example and any other signals can be ignored. The additional SignalFilter entity would make this exceptionally efficient causing SignalChangedEvents only when truly needed. Without it the user has to add additional combinators to reduce the noise of the signal input for the watched entities. The SignalFilter entity would be nice to have but isn't essential to this suggestion.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Please add signal changed event filter

Post by DaveMcW »

Related, simpler, but still useful request: viewtopic.php?f=28&t=98542

mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Please add signal changed event filter

Post by mrvn »

DaveMcW wrote:
Sat Sep 18, 2021 5:57 pm
Related, simpler, but still useful request: viewtopic.php?f=28&t=98542
Too simple I think. That request still means the LUA script has to check every entity, it just saves time by not having to create the LUA signals table and going through it all. But I think just testing the changed flag every tick would be prohibitive for something like LTN stops.

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

Re: Please add signal changed event filter

Post by Rseding91 »

Sorry but this isn't going to happen. The filters don't work that way: they only exclude a given mod from getting the events if the filter fails. They do not add new events.

We do not have any events when signals change on an entity because it would fire too many events and cause performance issues even when mods wouldn't be listening to the events.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Won't implement”