TL;DR
Add an easy to use API to allow modded structures to read and write wire signals with a performance, which is comparable to vanilla wire signal handling and won't mess up blueprints.What ?
When reading the threads for the individual mods, it becomes apparent that wire connections leaves something to be desired. I will summaries the current problems in/for mods as the following:- Way too CPU hungry when reading wire signals or writing signals to a wire
- Not running each tick even if it makes sense (due to CPU time)
- Output is a constant combinator, meaning it has a limited amount of signal slots (crashes on overflow)
- Modded combinators crashes when writing wire signal, which overflows 32 bit signed ints (but vanilla doesn't?, not very important as the high number was my faulty wiring)
- Wires are attached to invisible entities on top of the main entity, which often breaks blueprints (also claimed to be a source of slowdowns)
Possible solution
Add a wireAttachmentTile class.
This class is on creation attached to the building entity. It has the tile it attach to (X,Y), graphical offsets in that tile (either with a default or default in documentation) and if it is input or output. When creating a new instance of wireAttachmentTile, the modder is responsible to store the handle/reference/pointer as member data in the building for later access. This removes the need for invisible wire attachment entities and if the API will ensure the wire attachments (including attached wires) will just work with blueprints, then it will be a lot easier to make working wire attachments.
All read/write wire signal functions should be member functions of wireAttachmentTile. This would need to be optimized for performance. Naturally it should be able to read and write arrays of signal <name,value> pairs. However sometimes you don't need the array. What if your modded combinator has "if coal > 0"? A read function to read the int value of just one signal could be useful, particularly if it performs better. Getting a reduced list by requesting all signals higher or lower than an argument could also be useful, again particularly if it performs better (like only positive signals). Reading a list of signals where the list is given as argument(s) also comes to mind if it helps performance.
Writing to a wire could be split into the following functions:
- clear
- write list of <name,value> signal pairs
- write one <name,value> pair
- copy signals from an input given as argument
- write output to wire
To make this API modder friendly and flexible, it would be preferable if read/write functions can take an argument for accessing green/red/both wires (default both). Also for input/output state, the ability to set one as input and one as output could be interesting as it would allow one tile combinators. The ability for the modder to change input/output state of a wire connector should be considered (like flip input/output on a one tile combinator, possibly from GUI). However it's not interesting to support both input and output on the same wire. Some modded combinators does that at the moment and they quickly becomes really annoying to work with.
This is my proposed ideas on how to deal with what I consider the biggest problem in the game. My lack of knowledge of the internal workings of signals makes it hard for me to tell if it's the best solution from a performance point of view, but from a modder coding point of view, this approach seems to be easy to deal with, hence reducing the risk of half working mods, or mods, which aren't blueprint compatible.
The only other recurring issue for making new combinators/entities is making a GUI, but that's a whole different issue, one I think could be solved with examples rather than API changes. Releasing the GUI code for the vanilla combinators would likely do wonders for people making their first GUI, particularly because it allows copying and then have a working GUI to modify to fit the needs.