Show HN: A minimal working Rust / SDL2 / WASM browser game (github.com)
"Game" is a stretch, but I put together this repo containing a pure Rust app which uses SDL2 and compiles to WASM (and can be run in a browser). Older resources were a bit out of date and a bit too verbose for my purposes, so here's a minimal working example.
41 comments
[ 3.3 ms ] story [ 101 ms ] threadEdit: Also it can be compiled for WASM.
Other C dependencies could probably be managed with vcpkg.
Here's where it's built
https://github.com/emscripten-core/emscripten/blob/main/tool...
So there's quite a size penalty to using SDL 2 rather than SDL 1.2, but the reimplemented SDL[_mixer] 1.2 is incomplete and differs from official.
Jon Blow (Braid, The Witness) on rust for games: https://www.youtube.com/watch?v=SodXi2t1mtE
She is of the opinion Rust is well suited to game dev, and ECS is an excellent choice for a game design. She works off an example from the Starbound code.
Her thesis.
"Rust, by design, makes certain programming patterns more painful than others. This is a GOOD thing! It turns out that, for game development, the patterns that end up being the easiest to deal with in Rust closely mirror the patterns that are easiest for game development in any language.
I unfortunately had to learn this the HARD way!
Rust highly rewards data-oriented design with simple, understandable ownership semantics, and this is great news because this is a really good fit for game development. I suspect this is also true generally, not just for game development! (but what do I know?)"
And yeah, there's a fair # of indie games that have already been written in rust. But if you use the criteria of "successful" (high sales?) that excludes the vast majority of indie games. So getting one of those to a high level of visibility may take a while.
https://itch.io/games/made-with-rust
Random reddit thread claims https://store.steampowered.com/app/808160/UniverCity/ was written in rust. But, yeah, there's the other problem, I doubt anyone is digging around in function signatures on a systematic basis to identify these.
Personally I feel one of the better rust games out there is Veloren, but given it's FOSS, making a ton of $$ is never going to be on their success benchmarks. https://veloren.net/ The veloren folks have been on HN frontpage a few times and attribute some of the successes of their engine to rust.
Embark Studios were the other big player promoting Rust for gamedev and they're still at it, but mostly for tooling and backend infrastructure. Their first game release, The Finals, is plain old C++ on the client side.
The amount of hype I see surrounding ECS like it's some kind of groundbreaking amazing thing, often muddled into "Rust for gamedev" conversations, causes me to question everything said in such pro-Rust discussions.
Blow actually responded to the keynote you linked [0].
What's still unclear to me is what's the advantage that Rust is bringing to the table? Is game development velocity higher than in C++/C/C#? The ecosystem is obviously less mature, and the borrow-checker is an obvious source of friction... How do we separate the hype from the facts?
[0] https://www.youtube.com/watch?v=4t1K66dMhWk&t=1650s
I can't tell you how many times I've had Unreal Engine segfault on me and how much time that's wasted.
Bevy is a fantastic game engine, and with enough velocity, it'll start looking like Godot.
EDIT: trying to answer this myself got me down this rathole: https://users.rust-lang.org/t/fixing-rusts-webassembly-targe... and https://github.com/rust-lang/rust/issues/83788
I did find older alternative solutions that uses wasm32-unknown-emscripten, like https://github.com/tanis2000/rust-sdl2-wasm but it's not obvious to me that this is a better solution.
TL;DR: it's currently a mess
That gives you a simple software framebuffer, and it builds as a native app or for the web. You'd set up a window (or web canvas) using winit, then pass that to softbuffer so it can render to it.
https://trunkrs.dev
I think Trunk is the most streamlined way of building for the web at the moment, superseding wasm-pack.