An experimental falling sand engine written in Rust, successor to the C++ version
Note: development of this project is on hiatus.
It's a bit messy since it was one of my first Rust projects and it's not built on a framework or anything.
(if I continue development I would probably want to overhaul how it's structured)
I haven't worked on it for a while but the folks working on Astratomic were interested in seeing how I did certain things.
Some features:
- Chunk based infinite world
- Multithreaded sand sim (uses unsafe, questionable soundness)
- Multithreaded particles (uses unsafe, probably unsound)
- Rapier2d rigidbodies (with partially simulated pixels)
- GPU compute colored lighting (Terraria style)
- Partially multithreaded world/structure generation system inspired by Minecraft's
- Very basic entity system using specs ECS
demo.mp4
Some points of interest:
- world.rs: World tick function
-
Pseudocode for rigidbody/entity/sand tick sequence
// fill rigidbody hitboxes in world with dummy pixels for each rigidbody for each point in rigidbody calculate world position for the point set world pixel at that position to dummy "object" type (acts like solid) if there was a sand pixel there make it a particle or displace it apply impulse to rigidbody at the point // fill entity hitboxes in world with dummy pixels for each entity for each point in entity calculate world position for the point if world pixel at that position is air: set world pixel at that position to dummy "object" type tick pixel (sand) simulation for chunks tick particle simulation // clear dummy pixels from entity hitboxes for each entity for each point in entity calculate world position for the point if world pixel at that position is dummy "object" type: set world pixel at that position to air tick entities // clear dummy pixels from rigidbody hitboxes for each rigidbody for each point in rigidbody calculate world position for the point if world pixel at that position is dummy "object" type: set world pixel at that position to air tick pixel (sand) simulation for rigidbodies update chunk collision
-
- simulator.rs: Sand simulation for chunks & RigidBodies
- See also this issue thread which describes some of the techniques I used
- chunk_handler.rs: Chunk handler tick function (chunk loading/unloading/etc)
- lighting_prep.comp/lighting_propagate.comp/chunk_light.frag: Lighting shaders
- particle.rs: Particles
- gen/: World gen systems
- Conceptually heavily inspired by Minecraft's biome/feature/structure generation system
- See also this article which describes a cave generation technique that mine is based off of
- gamedir/assets/data/structure/: Worldgen structure data
Automatic builds for Windows x64 can be found here (requires GitHub account to download): https://github.com/PieKing1215/FallingSandEngine/actions/workflows/autobuild.yml
Controls are (arrow keys/C/X/Z) or (WASD/space/shift/Z)
Install rust/cargo
Clone the repo
To run locally you should be able to just do cargo run
/cargo run --release
You can also add -- -d
to enable debug UI
(there's also a profile
feature which enables profiling with Tracy)
I haven't built it to linux in a while but it should work
There's also a bash script which can bundle everything needed to run the game into the package/ folder (builds for release, copies assets, and generates a dependency licences file)
It requires cargo-lichking: cargo install cargo-lichking
To run: sh package.sh
All original code files are licensed under the BSD 3-Clause License.
All art assets (everything in gamedir/assets/texture/) are licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.