Page 1 of 1

Factorio in web assembly

Posted: Mon Nov 14, 2022 9:06 pm
by Blay
TL;DR
Compile factorio to web assembly and host it on factorio.com.
What ?
I suggest, that the devs should compile factorio to web assembly and host it on factorio.com for users, that bought the game (web assembly allows you to run an native app in a normal internet browser). That process should be straightforward
(It took me 6 hours to compile simple "Hello, world!")
, because factorio is written in c++ and uses sdl2, and there's a tool called emscripten, that you can check out, for compiling c++ into web assembly (there's also a lot of tutorials on how to use sdl with it on the internet). There would be a few complications, like where to store saves and other stuff, but you will come up with something for sure :D ! (you can fe. store all that stuff on your servers, in the cloud and get rid of steam cloud for the steam version of the game)
Why ?
Because being able to play factorio everywhere without installing anything would be cool! :mrgreen: :mrgreen:

Re: Factorio in web assembly

Posted: Mon Nov 14, 2022 11:20 pm
by posila
Blay wrote: Mon Nov 14, 2022 9:06 pm Because being able to play factorio everywhere without installing anything would be cool! :mrgreen: :mrgreen:
You can already do that by downloadin ZIP package instead of installer.

Re: Factorio in web assembly

Posted: Tue Nov 15, 2022 2:28 pm
by Blay
posila wrote: Mon Nov 14, 2022 11:20 pm
Blay wrote: Mon Nov 14, 2022 9:06 pm Because being able to play factorio everywhere without installing anything would be cool! :mrgreen: :mrgreen:
You can already do that by downloadin ZIP package instead of installer.
Either ways, you have to wait.

Re: Factorio in web assembly

Posted: Tue Nov 15, 2022 2:35 pm
by posila
Blay wrote: Tue Nov 15, 2022 2:28 pm Either ways, you have to wait.
I agree. The browser wouldn't magically download 1.5 GB of assets faster than the ZIP file, so you'd have to wait for the browser hosted version too :D

Anyway, we use SDL but are not completely built on top of SDL. Meaning, we'd have to port at least rendering to WebGL (or something that can run in browser.) We can't port rendering to SDL, because SDL doesn't provide all the graphics features we need.

Re: Factorio in web assembly

Posted: Tue Nov 15, 2022 8:17 pm
by Blay
posila wrote: Tue Nov 15, 2022 2:35 pm The browser wouldn't magically download 1.5 GB of assets faster than the ZIP file, so you'd have to wait for the browser hosted version too :D
I didn't think about that before xd

Re: Factorio in web assembly

Posted: Tue Nov 15, 2022 8:21 pm
by Blay
posila wrote: Tue Nov 15, 2022 2:35 pm Anyway, we use SDL but are not completely built on top of SDL. Meaning, we'd have to port at least rendering to WebGL (or something that can run in browser.) We can't port rendering to SDL, because SDL doesn't provide all the graphics features we need.
Yeah, but still doing such boring and hard stuff like porting opengl to some shit that runs in the browser wouldn't be that hard for such a big team with a lot of time and money. You can still make it just for the seek of it, can't you? I never saw a big pc game being ported to wasm, maybe you will be the first one to do so? ;) ;)

Re: Factorio in web assembly

Posted: Wed Nov 16, 2022 9:12 am
by posila
Blay wrote: Tue Nov 15, 2022 8:21 pm ... doing such boring ...
I don't want to do boring stuff :D But if anyone on the team is interested in making this work, they can put time towards it if they want to. But I wouldn't expect it to happen anytime soon or possibly ever :(

Also I was interested in performance of WebAssembly, and it's hard to tell what would be impact on Factorio be compared to native code, but I saw there is a limit of 4 GB of memory, and it is unclear to me, if the limit is for single allocation (like you can't have an array larger than 4 GB, that would be fine), or all allocations combined (that would be big problem, major reason we stopped making 32bit builds)

Re: Factorio in web assembly

Posted: Wed Nov 16, 2022 8:50 pm
by atomizer
Currently 4 GB is a hard limit, however 64 bit addressing is on the way - already available in chrome behind a flag and in firefox nightly: https://webassembly.org/roadmap/
Hi-res textures take up around 800 MB. Streaming sounds/music on-demand saves another ~140 MB off of initial download.
Not saying that it is viable or easy, but at least it seems not impossible.

Re: Factorio in web assembly

Posted: Sat Nov 19, 2022 6:44 pm
by duskwuff
posila wrote: Wed Nov 16, 2022 9:12 am Also I was interested in performance of WebAssembly, and it's hard to tell what would be impact on Factorio be compared to native code, but I saw there is a limit of 4 GB of memory, and it is unclear to me, if the limit is for single allocation (like you can't have an array larger than 4 GB, that would be fine), or all allocations combined (that would be big problem, major reason we stopped making 32bit builds)
The 4GB limit applies to all allocations made through the WebAssembly VM. But keep in mind that this wouldn't include memory allocated outside the VM, like code and graphics, so a WASM Factorio would still be less resource-constrained than the Switch port (for example).

WASM64 is also under development, but I don't know what the current status of support and tooling for that looks like.

Re: Factorio in web assembly

Posted: Mon Nov 21, 2022 12:40 pm
by posila
duskwuff wrote: Sat Nov 19, 2022 6:44 pma WASM Factorio would still be less resource-constrained than the Switch port (for example)
True

Re: Factorio in web assembly

Posted: Mon Nov 21, 2022 4:32 pm
by FuryoftheStars
I won't lie, Factorio in a web browser sounds cool and all, but I'm not sure I see the point. One can download the zip version and put it to a thumbdrive, then change the needed config files to save all the needed appdata to the thumbdrive as well, and now you have a portable version that can go between multiple computers without having to redownload between each one and keeps its save games and mods with. Unless, of course, you're trying to use this on a computer that has had the USB ports or other needed things for zip Factorio to run locked out... (*cough*work pc*cough* :D )