[HN Gopher] Show HN: A minimal working Rust / SDL2 / WASM browse...
       ___________________________________________________________________
        
       Show HN: A minimal working Rust / SDL2 / WASM browser game
        
       "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.
        
       Author : awwsmm
       Score  : 53 points
       Date   : 2024-01-15 14:49 UTC (8 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | sdwr wrote:
       | Appreciate the example! I've played around with game dev in JS
       | before, how does this compare?
        
         | awwsmm wrote:
         | I'm only just beginning to scratch the surface with gamedev in
         | Rust, but JS and Rust are quite different languages. Rust is
         | compiled, with strong typing. But once you get the mechanics of
         | compiling to WASM figured out (as I have in this repo), it's
         | pretty pleasant to work with.
        
       | mrkramer wrote:
       | I'm planning on learning Rust and experimenting with game dev so
       | this might help me. Thx.
        
         | SeanAnderson wrote:
         | https://github.com/MeoMix/symbiants Here's my open source game
         | written in Rust and compiled to WASM if you want more reading
         | material :) It uses Bevy not SDL2, though.
        
         | Tsarbomb wrote:
         | Check out Bevy. https://bevyengine.org/ It has the best ECS
         | design I've ever seen for a game engine. Super fun to use.
         | Currently no editor and you need to wrap your head around ECS,
         | but it will definitely push you to improve your rust skills.
         | 
         | Edit: Also it can be compiled for WASM.
        
       | TillE wrote:
       | I was confused about where/how SDL gets recompiled for WASM, but
       | it looks like Emscripten specifically has built-in support for
       | SDL and a handful of other libraries. That's cool.
       | 
       | Other C dependencies could probably be managed with vcpkg.
        
         | speps wrote:
         | If you don't want the portability, you can also write basic
         | drawing code in JS, eg. WebGL, Canvas, WebGPU, whatever other
         | API. Then, you can expose some basic functions to your WASM
         | interface. It's more flexible but not much more complicated if
         | you already are comfortable with JS.
        
         | gnulinux wrote:
         | SDL API is used to interface with HTML5 canvas operations so
         | that SDL doesn't need to be compiled: the entire SDL API is
         | literally a primitive in your browser.
        
           | a1o wrote:
           | That is not true, SDL2 port is written in C and it has to be
           | compiled.
           | 
           | Here's where it's built
           | 
           | https://github.com/emscripten-
           | core/emscripten/blob/main/tool...
        
       | mortallywounded wrote:
       | Ebiten (Go package) compiles for all OSes, Switch and web via
       | Wasm as well. The binaries are little fat but it's really nice :)
        
       | pixelpoet wrote:
       | A minimal C++ / Windows thing like this would've been right up my
       | alley :)
        
         | unclad5968 wrote:
         | https://emscripten.org/docs/getting_started/Tutorial.html
        
       | pengaru wrote:
       | I'm curious why there's so much interest in using Rust for
       | gamedev. It strikes me as the polar opposite of a minimal-
       | friction maximum-iteration-velocity you'd want for something
       | creative like video games. Is it just a product of the general
       | hipness/hype around the language?
       | 
       | Jon Blow (Braid, The Witness) on rust for games:
       | https://www.youtube.com/watch?v=SodXi2t1mtE
        
         | jasonjmcghee wrote:
         | For a lot of the same reasons people use C++, but I'd argue
         | rust is more approachable.
        
         | capitainenemo wrote:
         | IMO Kyren (the game dev who created a large portion of the
         | Starbound game) covers this well in her Rust 2018 keynote.
         | https://kyren.github.io/2018/09/14/rustconf-talk.html
         | 
         | 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?)"
        
       ___________________________________________________________________
       (page generated 2024-01-15 23:00 UTC)