Show HN: Wireworld written in Nim
github.com
github.com
It was my first non-trivial project in Nim. I had a lot of fun. It uses SDL 2 as the graphics engine. Let me know if you have any little suggestions for it, or any questions about the development.
Haha, nice catch because I just did that on the other thread ;) https://news.ycombinator.com/item?id=14387684 boring implementation of the classic game of life. I don't know if it's a pure coïncidence or not but I'll have a look at your repo, nice work !
Your GoL implementation is so pretty though. I really need to work on my design skills.
For a more flushed out example there's: https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-...
I did use a tiny bit of code from the tutorial on 2D platformers linked by someone else.
I'm surprised it was that brief actually. I didn't even try for brevity. And I'm sure if I had a better handle on some of the other features like macros and templates it could have been much more elegant in the display/SDL code.
The actual implementation of the automaton is only about 70 lines of code if I remember correctly.
A while back I implemented it in typescript and ran the computer startup file through it for the web. It is such a fun piece of logic to squeeze every nanosecond of performance out of.
https://github.com/dested/WireWorld/blob/master/WireWorldTyp...
This is the file for the computer, shoot me an email if you ever get around to implementing it. I'd love to see the result and talk about optimizing! dested at gmail
That means a lot to me!
> Have you considered using Nim's JS backend to make it work in the browser?
I was thinking about it after seeing someone else's GoL in this thread. I'm guess I would need to write another display layer though.
But even with GC on, Nim is super fast. I use it in real time rendering and I honestly didn't see any significant performance loss. In fact, it made some routines much faster because the Nim compiler produced much better C code than I ever did.
This is what I experienced with GC enabled systems programming languages (Oberon family of languages) back in the late 90's, just with C++ as comparison on my case.
The main problem is the culture of micro-optimizing code without profiling it, that is so prevalent in those communities.
(Of course, deep down the stack is always a non-GCed language, or at least assembly, so if your GC language wins a benchmark, you can always write that same program + the GC runtime in a non-GC language... but that is a trivial observation. Nim compiles to C, so is it GC'ed or not?)
pkg install nim nimble sdl2
git clone https://github.com/JHonaker/wireworld-nim.git
cd wireworld-nim
nimble install sdl2
nim c display.nim
./display