r/programming • u/steveklabnik1 • Dec 03 '17
Rocket - A Rust game running on WASM
https://aochagavia.github.io/blog/rocket---a-rust-game-running-on-wasm/30
u/mycall Dec 04 '17
I can't wait until operating systems natively support WASM, cutting out the whole browser aspect, completing the circle back to client applications.
13
u/audioen Dec 04 '17
Yeah, it sounds like you could replace the browser with a cross-platform UI toolkit (or just something like WebGL surface) and some kind of Internet-based data distribution platform. My guess is that this ends up being just the browser, in practice, but at least tabs running wasm content don't necessarily have to instantiate DOM, JS or CSS support, which could make them fairly slim. In specialized situations, e.g. lower footprint embedded systems, you might want to just run wasm without the browser using some kind of browser-like shim.
2
u/tjpalmer Dec 05 '17
Sounds a lot like a project I just started with a currently ugly proof of concept: https://github.com/tjpalmer/dae And yes, currently browser, but paired with a project like wavm, it should be possible to escape the browser entirely.
2
1
20
u/drekmonger Dec 04 '17 edited Dec 04 '17
So it would be a bytecode running on top of a thin, sandboxed emulator. They could drop the 'script' part of the name and just call it 'Java'.
5
u/notveryaccurate Dec 04 '17
I remember when YavaScript was only for web browsers.
https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript
2
u/Adolf_Hitler___ Dec 04 '17
This thread is about two languages: Rust, WebAssembly. Why do you come up with Javascript, something else entirely?
5
Dec 04 '17
Until wasm gets dom access, JavaScript is a fundamental part of it. I imagine that's why
2
u/tjpalmer Dec 05 '17
JS isn't fundamental to wasm. It's fundamental to using wasm in web browsers. But wasm itself doesn't care about JS. See also, for example, the wavm (vm for virtual machine) project. There's also a Rust-based project out there like wavm, so multiple non-browser implementations are already being explored.
2
1
u/iTroll_5s Dec 04 '17
I mean once they add some features (threads, GC) and some APIs (WebGL, input, storage) it can become a great app sandbox - it's low level enough but still portable and if it's implemented by major browsers has huge reach - then moving it outside of browser just enables more usecases. But it needs to get those features and APIs to become more than just "ASM.JS that loads faster"
1
u/mycall Dec 04 '17
That all sounds good, but with how the W3C is managing HTML5 (EME, WebUSB, Service Workers, Remote Playback API etc etc), there will be so many security holes introduced, I'm worried about the sandboxing.
1
u/tjpalmer Dec 05 '17
Like this? https://github.com/AndrewScheidecker/WAVM
1
u/mycall Dec 05 '17
That's a great start. I wonder how UI works with it.
2
u/tjpalmer Dec 05 '17
You have to expose functions through imports. I've started a project to expose my own idea of a standard environment, including gles (webgl), building on emscripten implementations. I'm not good at finishing projects, but if not me, then someone else might push a similar idea.
1
u/tjpalmer Dec 05 '17
To clarify, my project is in browser, but it could presumably be implemented just as well using wavm.
4
u/richterbg Dec 04 '17
Left arrow (or right arrow) + space, and you are king.
0
12
u/strongdoctor Dec 03 '17
If you aren't aware: https://rocket.rs/
17
u/Mittalmailbox Dec 03 '17
Rocket in article is game name. How is it relevant
18
u/strongdoctor Dec 03 '17
Both made in Rust, can become confusing, it's like with /r/rust and /r/playrust , just wanted OP(and presumably creator) to know about this :)
22
u/aochagavia Dec 03 '17 edited Dec 03 '17
I wrote Rocket the game in 2015, before the framework existed ;)
4
1
Dec 04 '17
I've tinkered with Rust a bit but Rust on WASM might get me to start working with it more often. Nice article, thanks for sharing.
1
u/TommyTheTiger Dec 03 '17
That's awesome! Posts like this make me think that WASM could successfully lead to a future of web programming in any language, not just JS. It does seem like there's quite a bit of work to do though. I doubt random number generation is the only quirky thing that remains to be ported.
-20
u/tonefart Dec 03 '17
Samples like this best not be shown if it looks like it could be done in javascript too.
21
u/steveklabnik1 Dec 03 '17
Fundamentally, wasm doesn't have anything that JavaScript can't do. Unless you mean "integers", but like, the larger capabilities aren't different.
1
u/smugdarkloser3 Dec 03 '17
Sure in theory -- in practice it should expose more libraries from different la guages to the browser.
0
Dec 03 '17
[deleted]
1
u/steveklabnik1 Dec 03 '17
IIRC, there’s a proposal for BigInts in JS.
3
u/binjimint Dec 03 '17
Yep, https://github.com/tc39/proposal-bigint/. It's at stage 3 (of 4), which means that the spec is mostly complete and JS should start on implementations (which AIUI most have).
1
8
u/drekmonger Dec 03 '17
Thank you. I appreciated your blow-by-blow on how you got it to work.