Hacker News new | ask | show | jobs
by dom96 2075 days ago
I'm going to do a little bit of a shameless plug as a way to show off just what Nim is capable of. If you've ever played one of the many IO games, it might seem familiar to you. Basically I have used Nim to create a multiplayer game that can be played in the browser[1].

I'm planning to write up a more detailed post outlining the architecture of this. But suffice it to say, Stardust is written 100% in Nim. Both the servers and the client running in your browser is written in Nim. The client uses Nim's JS backend and the server Nim's C backend. The two share code to ensure the game simulation is the same across both. Communication happens over websockets.

It's been a lot of fun working on this and I cannot imagine another language being as flexible as Nim to make something like this possible. I already have an Android client up and running too, it also is built from the same code and I plan to release it soon.

1 - https://stardust.dev/play

3 comments

Not to disparage Nim, but I can think of a number of other languages where this is possible:

* JS, obviously

* Rust

* C/C++

* Anything else that can compile to WASM

Fair enough. I think then we get into how easy this is to do in these. For example, can you really target the web browser vs node from the same JS codebase by simply changing the compiler invokation?
This looks really amazing! Would love to read an architecture post for this. Adding this in your book would also be pretty cool
> Android client up and running too, it also is built from the same code

How does that work, and is it an alternative to dart/flutter?

I wouldn't say so. Since my game mostly just needs a canvas I make use of SDL2 to target Android (and plan to use it for iOS/desktop as well). I created a thin library which targets either HTML5 canvas (JS) or SDL2 (everything else): https://github.com/dom96/gamelight