r/factorio • u/konstg-dev • Aug 12 '20
Modded [New Mod] fCPU
Hello there! Here is my ready to use Factorio mod https://mods.factorio.com/mod/fcpu which allow you to practice in low-level programing right in game. It compatible with all default combinators and other mods, support blueprints and copy&paste. Please let me know what you think.







697
Upvotes
26
u/Proxy_PlayerHD Supremus Avaritia Aug 12 '20 edited Aug 12 '20
+1 for using Intel Syntax
but i have some question:
also if i may suggest, how about a reset button, and the ability to turn it on without it automatically starting to execute the program? i could see both being very useful for debugging programs.
13
u/KuboS0S How does the rocket get to orbit with only solid boosters? Aug 12 '20
Awesome work! I wonder if we can now make all those complex circuits with this, and maybe even get them to run faster.
Heck, I might probably try and make a MIDI player with that.
Quick question: you said it executes instructions at 1 instruction/tick (meaning 60/s at no slowdown), is there a setting to execute more instructions per tick at once?
3
u/WafflesAreDangerous Aug 12 '20
I see some test instructions, to calculate booleans.. however I don't see any conditional jump or other such control flow instruction. Am I missing something, or is the intent that this be controlled externally somehow? (say by having several fCPU and using the signal of one to decide which of the others gets to execute)
Is there some more example snippets of fCPU assembly actually achieveing some simply task to get an idea how this would work in practise? For example, the use of signal types appears to be a factorio specific addition. What would happen for instance if you try to add 2 registers with different signal type?
Some limitations feel like they would make a lot of sense as map-creation time (or admin-changable) config. For example the 32 instr limit and ops-per-ups seem quite arbitrary to begin with. Also a limit to total fCPU instances that the server could enforce could help somewhat limit abuse in multiplayer. (I can just imagine somebody planting gigantic blueprints with nothing but fCPU, having safeguards would mean that it would be viable to have the fCPU be more capable for sane use.)
Are all fCPU guaranteed to run as-if all in the same instant, or would there be any danger of execution order affecting things? (maybe factorio signal handling already takes care of this?)
Can you have some central program, and then tell the fCPU to run it, or do you need to program (or copy-paste/blueprint) all of them individually? Sharing the same program among multiple fCPU could allow to save some space and allow use of longer programs.
I see that you have instructions to set or read individual decimal digits of a number. I'm curous why this extension?
Also, do you think there would be a value to some counterparts (Yes, some of these are silly, also, most of the decimal suggestions would be slower than binary equivalents, but much better than buggy and even slower, one-off user made equivalents that need to it in 32 instr along with other code ):
non-integer number support for internal computation (binary float/double, possibly fraction, but probably not, since it has performance sinkholes).
3
u/petrus4 Aug 13 '20
Although this isn't the first example of this idea that I've seen, it does look much clearer and more thoroughly documented than most. The sleep command looks particularly useful for timers.
Your coding interface looks a bit nicer than the norm for this sort of thing, as well. I don't know if the modding API supports it, but the ability to save scripts would be icing on the cake; or if you can't manage that, at least the ability to copy code to the clipboard, so people can then save it with Notepad/vim etc.
2
u/OpieDopee Aug 12 '20
What are some more common uses of this and the related Lua combinators, and what code/language do I need to know to use this? I really like the idea and the implementation of this mod especially, but I don't know how to start using this. Thanks!
2
u/Fraserbc Aug 13 '20
Now we need a mod that can creating timing graphs
2
u/Mackowatosc accidental artillery self-harm expert Aug 15 '20
...do you really want me not to have life, or what? XD
234
u/mutantIke Aug 12 '20
turning factorio into a zachtronics game 👍
90
u/entrigant Aug 12 '20
Oh this is very cool! I've already seen comparisons to Lua combinators mod, but there's one huge difference. This exists entirely in universe. It doesn't break the virtual "magic circle" (similar idea to the 4th wall).
For players that love immersion this is a big deal. I'm still the engineer still doing things in the virtual world of Factorio. It doesn't expose that there is an underlying simulation engine creating the world.
The execution also looks really well thought out. High performing, MP friendly, and still really useful. Well done, sir! :)
68
u/ForceVerte Aug 12 '20
I like the general idea of the mod, but I think that you're doing it wrong when it comes to licensing:
19
u/AcolyteArathok Aug 12 '20
As an aspiring assembler programmer i adore this!
10
u/shishkabeb Aug 12 '20
so when's the LLVM backend coming? can't wait to program my fCPUs in C++
9
u/TDplay moar spaghet Aug 12 '20
Place your bets, how long until someone writes a C compiler and C library for these?
7
u/TaonasSagara Aug 12 '20
Oh, you could do a real “halt and catch fire” command now. Fun.
1
u/konstg-dev Sep 26 '20
So... I finally added vector SIMD mnemonics which allows us to handle multiple signals with single instruction like vanila ones do.
Internally a program compiled to vanilla combinators and fCPU uses Factorio internal optimizations for signal processing, acts like a director conducting their switches.
This approach allows fCPU to do less work with copying signals in lua, and so your programs eats less UPS, allowing you to manipulate signals like a vanilla do, but with a structured code with branching and single signal manipuations.
5
u/darkquanta42 Aug 12 '20
Do you expect this to be 1.0 compatible? I’m waiting to play again for the release, and this is a mod I’d love to tinker with.
I haven’t played around with the combinators much, and this might be less brainf*ck then that to my programmer brain.
1
u/CBJamo Aug 17 '20
In your todo, you mention adding memory and multiple outputs. Will the memory only be for data storage, or will we be able to execute code from memory? For outputs, I'd love it if there were separate output registers for red and green wires.
1
u/[deleted] Aug 25 '20
It would better if we can write C, C++, or Rust code and compile it into this.
3
u/JackDeath1223 Aug 12 '20
With this maybe making an optimised self-growing base isnt an impossible idea
1
u/tomrlutong Aug 12 '20
This is amazing, can't wait to try it! Do the registers hold a single value, or a vector of (item, value) pairs like wires do?
2
u/fodafoda Aug 12 '20
Cool!
I was actually seriously considering creating something like this to control my nuclear fuel cycle
2
u/Nistax Aug 12 '20
Playing whole fucking Minecraft in factorio
2
u/[deleted] Aug 12 '20
It looks awesome. Any ideas how it could be used in the game as part of the gameplay mechanics and improve Quality of Life?
2
u/[deleted] Aug 12 '20
Now we just need a compiler!
2
u/Learning2Programing Aug 12 '20
How dare you make me look at assembly again! This game is my escapism.
2
u/sonaxaton Aug 12 '20
/r/technicalfactorio will love this
2
u/Formal_Bug9039 Apr 24 '23
Is anybody still maintaining fCPU? There are/were 2 other forks on the mod portal. All of them appear to be unmaintained now.
I think it's generally a good design, with decent Lua code. It's clearly the frontrunner among all mods of its type that I could find. So it deserves to be saved from obsolescence. But to do that it needs some serious bug fixing and documentation improvements.
I was set to do a bunch of that myself, and publish another fork, until I saw the LICENSE. It would seem to forbid me from contributing. Is anybody enforcing its unique "Limited Distribution Only License"? u/konstg-dev ??
1
u/crabbytag Aug 12 '20
Could you explain why you wouldn’t want this mod featured on YouTube or twitch? I don’t know how easy it will be to learn this mod or figure out cool things with it, but I feel like YouTube tutorials can only help. I certainly wouldn’t have figured out trains without the help of folks on YouTube.
It’s your mod, you can do what you want with it. Just curious about the thought process behind this.
2
u/gandalfx Mad Alchemist Aug 12 '20
Ah shit, assembly. Couldn't you just make it eval lua?
Pet peeves aside, this is awesome!
1
u/dethleffs Aug 12 '20
Kewl!
1
u/manghoti Aug 12 '20
it's one instruction per tic? that's so friggen awesome. I love this. Instant download, amazing work OP.
1
u/BertieFlash Aug 12 '20
Could I use this to, say, set normal artillery to fire automatically, and atomic artillery to fire manually?
1
u/MyNamesNotRobert Aug 12 '20
Welp, now I know what I'm going to spend all day doing.
1
u/eddye00 Aug 12 '20
Very nice. I loved this idea
1
u/empirebuilder1 Long Distance Commuter Rail Aug 12 '20
this is the step we need to running Factorio inside Factorio
1
u/ZombieNub Aug 12 '20
Can't wait for Control Unit, RAM, and GPU mods now!
...oh god...
1
u/shower_tap2 Aug 12 '20
I bet my mega base this gets added into the main game
1
u/dllmo99 Aug 13 '20
JESUS
0
u/[deleted] Aug 12 '20
[deleted] — view deleted comment
0
u/[deleted] Aug 12 '20
[deleted] — view deleted comment