Would this be possible?
-
- Long Handed Inserter
- Posts: 52
- Joined: Sun Jun 14, 2020 9:41 pm
- Contact:
Would this be possible?
I wanted to write a mod that would allow red and green wire channels to be treated separately. Basically it would allow you to do things such as pairwise operations on red/green wires. For example an arithmetic combinator could do [Each(red wire) / Each(green wire)] (pairwise division). I wanted to know if it's even possible before I dive into it
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Would this be possible?
Combinator behavior is hardcoded. You'd have to write everything from scratch or do some black magic with invisible combinators to "fake" the behavior you want (similar to how https://mods.factorio.com/mod/circuitissimo does it).
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: Would this be possible?
And no, you can't even fake it. There is no way to build a circuit for red / green that isn't iterative (and that then takes many ticks). And reading the signals in LUA and performing the math there simply doesn't scale.
Re: Would this be possible?
Note there are tricks you can do to perform some of these:
Addition is done by connecting multiple wires (possibly isolating signals via +0 or *1)
Subtraction via multiply by -1 and addition.
Squaring is straightforward via (each * each).
Multiplication can be done as ((A + B)² - A² - B²) / 2; make sure to insert appropriate delay combinators to keep signals in sync.
I'm don't know a good one for division. Since you can't have fractional signals, (A * 1/B) won't work. Something like (A * 65536 / B) / 65536 should work, but cuts into your range. If you know the maximum value you expect for B, you could tune the constant to that.
Addition is done by connecting multiple wires (possibly isolating signals via +0 or *1)
Subtraction via multiply by -1 and addition.
Squaring is straightforward via (each * each).
Multiplication can be done as ((A + B)² - A² - B²) / 2; make sure to insert appropriate delay combinators to keep signals in sync.
I'm don't know a good one for division. Since you can't have fractional signals, (A * 1/B) won't work. Something like (A * 65536 / B) / 65536 should work, but cuts into your range. If you know the maximum value you expect for B, you could tune the constant to that.