5 ms·
Show HN: A PSX/DOS style 3D game written in Rust with a custom software renderer
So, after years of abandoning Rust after the hello world stage, I finally decided to do something substantial. It started with simple line rendering, but I liked how it was progressing so I figured I could make a reasonably complete PSX style renderer and a game with it.
My only dependency is SDL2; I treat it as my "platform", so it handles windowing, input and audio. This means my Cargo.toml is as simple as:
[dependencies.sdl2]
version = "0.35"
default-features = false
features = ["mixer"]
this pulls around 6-7 other dependencies.
I am doing actual true color 3D rendering (with Z buffer, transforming, lighting and rasterizing each triangle and so on, no special techniques or raycasting), the framebuffer is 320x180 (widescreen 320x240). SDL handles the hardware-accelerated final scaling to the display resolution (if available, for example in VMs it's sometimes not so it's pure software). I do my own physics, quaternion/matrix/vector math, TGA and OBJ loading.
Performance: I have not spent a lot of time on this really, but I am kind of satisfied: FPS ranges from [200-500] on a 2011 i5 Thinkpad to [70-80] on a 2005 Pentium laptop (this could barely run rustc...I had to jump through some hoops to make it work on 32 bit Linux), to [40-50] on a RaspberryPi 3B+. I don't have more modern hardware to test.
All of this is single threaded, no SIMD, no inline asm. Also, implementing interlaced rendering provided a +50% perf boost (and a nice effect).
The Pentium laptop has an ATI (yes) chip which is, maybe not surprisingly, supported perfectly by SDL.
Regarding Rust: I've barely touched the language. I am using it more as a "C with vec!s, borrow checker, pattern matching, error propagation, and traits". I love the syntax of the subset that I use; it's crystal clear, readable, ergonomic. Things like matches/ifs returning values are extremely useful for concise and productive code. However, pro/idiomatic code that I see around, looks unreadable to me. I've written all of the code from scratch on my own terms, so this was not a problem, but still... In any case, the ecosystem and tooling are amazing. All in all, an amazing development experience. I am a bit afraid to switch back to C++ for my next project.
Also, rustup/cargo made things a walk in the park while creating a deployment script that automates the whole process: after a commit, it scans source files for used assets and packages only those, copies dependencies (DLLs for Win), sets up build dependencies depending on the target, builds all 3 targets (Win10_64, Linux32, Linux64), bundles everything into separate zips and uploads them to my local server. I am doing this from a 64bit Lubuntu 18.04 virtual machine.
You can try the game and read all info about it on the linked itch.io page:
https://totenarctanz.itch.io/a-scavenging-trip https://totenarctanz.itch.io/a-scavenging-trip
All assets (audio/images/fonts) where also made by me for this project (you could guess from the low quality).
Development tools: Geany (on Linux), notepad++ (on Windows), both vanilla with no plugins, Blender, Gimp, REAPER.
- creikey 1y agoVery cool project, can't play because on mac but looks like cool approach
- mvx64 1y agoI have considered getting a Mac in the past (even a very old Air) to make and, most importantly test, Mac builds, but I never got to it and cross-compiling to Mac seems like a pain, if at all possible. If you have a VM laying around though, it should work. A good thing about the approach is that if it compiles, it should work exactly the same everywhere and with predictable/linear performance, no matter the environment or driver situation.
- p0w3n3d 1y agoI believe you can build to mac targets on github though
- mvx64 1y agoDidn't know this, but I'd rather not use github to be honest. Isn't there also some kind of signing required to publish a Mac build?
- p0w3n3d 1y agoyou're right, I wasn't aware of it. Of course you could build it and leave it as is, so we would need to accept the binary, but still - a lot of work. Makes some good projects made by devoted programmers exclusive to other platforms, sadly.
- Klonoar 1y agoYou don’t need to sign it, the user just has to do some leg work to run it without it.
- ioma8 1y agoIt works perfectly cool through wine. Also i think adding mac builds wouldnt be hard given its simple dependencies.