UPS-friendly Selector combinator


Adds a Selector combinator that can select from the inputs sorted by largest/smallest, count inputs, output a random input, calculate stack sizes, and, if the Janky quality mod is installed, transfer quality between network signals.

Content
8 months ago
1.1
522
Circuit network
Owner:
Matrix_V
Source:
https://github.com/JimViebke/selector...
Homepage:
N/A
License:
MIT
Created:
9 months ago
Latest Version:
0.1.2 (8 months ago)
Factorio version:
1.1
Downloaded by:
522 users

Based on the upcoming combinator introduced in FFF #384, this is an expanded and UPS-optimized rewrite of Pigophone's deprecated Selector Combinator mod, with added support for Quality transfer (as implemented in Soul-Burn's Janky quality mod). Feature requests, bug reports, and feedback welcome!

Features

  • Select input: Output the nth smallest or largest signal from among the inputs. Set the index to 0 to use this as a min/max combinator.
  • Count inputs: Output the number of input signals, the same as a decider combinator with each != 0, output 1.
  • Random input: Output a randomly selected input, updating every N ticks.
  • Stack size: Output the stack size of each input type.
  • Quality transfer: Output all of the target signals as the quality of the selection signal. Optional, requires Janky quality.

Compatibility

  • Works with Janky quality.
  • Partially works with Picker Dollies (a selector can be adjusted within wire reach of where it was placed).
  • Partially works with Reconnect Cut Wires (pasted entities reconnect to a selector, but not the other way around).
  • Should work with any modded items, stack sizes, or signals.
  • Should work in new or existing saves.
  • Untested in multiplayer (feedback welcome).
  • Technically compatible with the original selector mod, but not recommended because the items/recipes/entities are difficult to distinguish.
  • No known incompatibilities.

Performance

This mod has been written with performance in mind. If you are experiencing UPS issues from this mod, please post a save file and describe your use case.

Average update times for 100 selectors with 10 input signals each, on an i7-4790k running a 1kspm factory:

  • Select input: 2.15 ms
  • Count inputs: 1.86 ms
  • Random input: 2.43 ms (1-tick interval) 0.12 ms (60-tick interval)
  • Stack size: 1.95 ms
  • Quality transfer: (not yet optimized or measured)

Known issues / todo:

  • As with all modded combinators, mousing over a selector will not show you its outputs. You can view these by connecting the output to another entity such as an electric pole, and mouse over that.
  • Blueprints mostly work, but may lose selector settings in some cases.
  • Blueprints can not paste settings onto existing selectors.
  • Quality transfer mode does not have a unique sprite (help wanted!).
  • Before removing signals from a save (ie, by removing or changing another mod), make sure that a selector is not configured with or receiving those signals (it might otherwise prevent the save from loading).

Minor issues / todo:

  • A selector's open GUI does not refresh when settings are pasted onto the selector. Clicking the selector fixes this.
  • Selectors consume electricity, but work without it.
  • Undo restores a selector but not its settings.
  • Whenever this mod updates, if Random input mode has an interval greater than 1, it clears its output until its next interval.

Credits

  • Pigophone for the original selector combinator mod.
  • Dylan (4812571) for writing ~90% of this mod.
  • tamj0rd2 for code improvements and cleanup.

Performance notes for the interested

  • Fewer inputs are faster than more inputs, even for simple modes like Count inputs (Factorio has to send circuit signals to Lua).
  • A hardcoded index is faster than a signal index, because the signal has to be separated from the other inputs.
  • A zero index is faster than a non-zero index, because the selector can scan for the largest or smallest signal (min/max) instead of sorting the inputs.
  • Inspired by vanilla combinators, stable inputs are faster than changing inputs. Factorio optimizes by only updating combinators whose inputs have changed, and otherwise leaving outputs unmodified. Since mods don't have this ability, selectors optimize by manually detecting cases where the inputs haven't changed and update logic can be skipped, similarly leaving the output signals unmodified (not counting Random input mode). This has no effect on behavior, only update times.
  • No inputs are even faster than stable inputs. If you only need a selector's output periodically, you can use a clock or gate to pulse the inputs.
  • Quality transfer mode hasn't been optimized yet.
  • This mod is currently ~0-3.5x faster than the original mod, depending on use case.