Sandspiel – A falling sand game built in Rust and WebGL

by 15DCFA8Fon 12/17/2018, 1:18 AMwith 185 comments

by chimeon 12/17/2018, 4:29 AM

Wow! This thread brings back some fond memories. Long ago, I came across a tiny Java applet linked on Fark to a Japanese forum post. Everyone loved it but I found it annoyingly small. It was barely 300px x 400px. I had been coding my senior thesis in Java and had recently learned how to use a Java decompiler.

So I downloaded the applet, decompiled it, spent a few minutes figuring out exactly where the dimensions were setup, changed them to 960x640, compiled it all, and hosted it on my site: http://chir.ag/stuff/sand/

I'm always apprehensive about taking any credit for the Falling Sand Game because I DID NOT make it but I'm always glad to see it in the wild. First it was Fark, then a few months later Digg, then Reddit. At one point someone created a Wikipedia page linking to the enlarged version I was hosting, then it got deleted as not-notable, then someone wrote a song about FSG, then a hundred different versions of FSG popped up, many non-Java and functioning much better than the applet, then the Wikipedia page came back up.

I've long stopped getting giddy emails from office slackers about how much time they waste on my site but even though I didn't really create this amazing game/toy/zen-garden, I feel lucky to have been a tiny part of the arcane pop-culture movement.

by dTalon 12/17/2018, 2:11 AM

A nice bit of web programming. The smoke effects look cool. Pity solids don't conduct heat - the first thing I always try and do in these is boil a pot of water.

If you've never seen this kind of thing before, the canonical PC example is The Powder Toy, which is so amazing I wish there a 3D Minecraft-like version. But it's really CPU-heavy even in 2d.

by ullarahon 12/17/2018, 2:42 AM

This is great, I love falling sand games.

The only downfall is that the Pythagorean Cup didn't work?

https://i.imgur.com/ejqBwR4.png

https://sandspiel.club/#cCZB5Un0exri2UajMjcu

by phaedruson 12/17/2018, 4:59 PM

Several years ago I wrote a falling sand game for the Parallax Propeller chip, which is an 8-core microcontroller. One core was needed to drive the video output, and I had up to 7 other cores running a simple ruleset:

1. If a sand pixel had an empty pixel below it, exchange them. 2. If more than two sand pixels are stacked but there's space to the side, kick one sand grain out to that side.

These rules were enough to make the sand form simple hill shapes. All of the cores bash on the same shared memory array; rather than use locks or synchronization I just had each core start in a different column of the screen and all move left to right by columns - in theory there should be enough separation that they'd never conflict.

However - and this is the part I thought interesting to post about - somehow after a few seconds or minutes the 7 cores would catch up with each other and start running in lockstep (effectively reducing the speed of the simulation to equivalent of 1 core).

Barring a bug that was simply crashing cores, what I think was happening was that not every control flow path took the same number of cycles, so a core processing a column with a complex sand pattern might slow down and allow another core to catch up to it. Once two cores were operating on exactly the same data, they'd be doing the same deterministic logic on the same inputs and writing out the same result, effectively just duplicating the work in lockstep.

by NextHendrixon 12/17/2018, 1:50 AM

I wasted hours on these types of games back in the flash era, people were constantly releasing new ones with more types of sand and various effects and combinations, its a shame that whole segment of internet history was deprecated along with flash, good times.

by tapirlon 12/17/2018, 4:22 AM

What's the performance difference from a pure JavaScript version?

Recently, I made a particle game which originally planned to be implemented with WASM. However, I decided to implement it with pure JS firstly. The result is some surprising that the JS version runs so smoothly that I think a WASM version is not essential any more.

by GolDDrankson 12/17/2018, 12:39 PM

This brings to mind a game that many people here might enjoy once it gets released – Noita: a magical action roguelite where every pixel is physically simulated.

https://store.steampowered.com/app/881100/Noita/

(Disclosure: it's being developed by a bunch of my old co-workers.)

by jasonkesteron 12/17/2018, 1:06 PM

Fun feature: on mobile, if you drop a bunch of lava on a bunch of fireworks, your phone gets hot.

Nice work.

by napsterbron 12/17/2018, 2:41 AM

Brings me back some good old memories from this game:

https://dan-ball.jp/en/javagame/dust/

by lhballon 12/17/2018, 2:49 AM

Got tired of all the phalic-volcanoes so I made something nice for you https://sandspiel.club/#2scDpZpyMACGp65FrkPT

by btschaeggon 12/17/2018, 6:59 AM

This very strongly reminds me of a game called "Hydroxis" (or at least I think so) for the Amiga. You started with water pooling in some cavity in an otherwise static level and had to move it to a target location by means of enabling and disabling some blocking segments in the level. That was fun!

I had remembered that one a decade or so ago and it turned out to be the single hardest thing I tried to find for my WinUAE collection :-(

by ummonkon 12/17/2018, 8:11 AM

Grow some plants. Light a fire. Frantically try to put it out with water and watch helplessly as the plants grow due to water, providing more and more fuel for the growing flames, until you have an unstoppable conflagration on your hands. There must be some moral lesson to learn from this.

by jetrinkon 12/17/2018, 2:08 AM

Make a lake of oil, set it aflame and then pour water on it. A small amount of water causes the burning oil to flare and spread. A large amount of water extinguishes the fire. Very cool!

by sorenjanon 12/17/2018, 3:24 AM

I wish fire or lava would make steam out of water, but I love the smoke effect. It was a really nice surprise when the rest of it was so low resolution, great combo.

by gambleron 12/17/2018, 3:49 PM

If you like this game, you might find this project interesting:

http://tinlizzie.org/~ohshima/shadama2/live2017/

http://tinlizzie.org/~ohshima/shadama2/

It's a bit similar, but uses GPU and spawns millions of particles. On the other hand, it's less of a sandbox and more of a demo. You can write your own code in the browser too, but it's a bit tricky to program, because it compiles to shader language and it has some weird limitations.

by t3hprogrammeron 12/17/2018, 2:01 PM

This is awesome! A few years ago I built a more rudimentary version of a falling sand game with just Javascript and WebGL: http://ericleong.me/sand.js/

I tried to embed the "scripting" language as a texture in WebGL to keep the implementation very fast (note that every pixel is a cell), but I think I worked myself into a corner.

Source code here: https://github.com/ericleong/sand.js

by jacobdpon 12/17/2018, 2:53 AM

Any source code for this? I'm learning rust right now and it would be really cool to see how this was made

by spdustinon 12/17/2018, 8:00 PM

Once I realized that pausing the FSG was a thing...

https://sandspiel.club/#Mt35KuNUFTZW9ITyWDxe

by tokyodudeon 12/17/2018, 3:53 AM

This is a perfect example of why I'm still in Chrome. At least for me this runs at 60fps in Chrome on my Mac but 30-45 in Firefox. I see this often in animated sites.

by city41on 12/17/2018, 2:49 AM

Thousands of particles and the worst frame rate I saw on my iPhone 6 was 25fps. Impressive.

by louskenon 12/17/2018, 2:10 AM

Not seeing vaporizing water when lava was put into it was a bit of a bummer, otherwise it's great

by Ezkuon 12/17/2018, 6:00 AM

Love the performance, no trouble with 60fps. The swirly wind, fire, and smoke effects are beautiful! It’s also the only part here with which I would not know how to get started building, could anyone share their thoughts on the implementation?

by flaqueon 12/17/2018, 1:42 AM

This feels wayyy smoother than I remember this game being.

by nagyadam2092on 12/17/2018, 2:37 PM

A question to the creator: is the fungus growing respecting the rules of Conway's Game of Life? It seems very much like that. Very nice app!

by mlindneron 12/17/2018, 2:27 AM

My current map set up, paused. https://imgur.com/71p1H8W

by devilmoonon 12/17/2018, 8:04 AM

Holy shit, I remember playing something very similar to this for hours on end in the early 90s as a kid; it might have even been an early version of the powder toy (another user mentioned it), not entirely sure, but regardless this thread is making me go back down memory lane and now I'd love to get into the insides of a game like this one and understand how it works!

by Tade0on 12/17/2018, 2:03 AM

You can get some interesting effects if you put a grid of one-pixel cloners, make them clone gas and put some lava at the bottom.

by Semaphoron 12/17/2018, 9:45 AM

Literally unplayable, exploding gas goes through thick solid walls without even damaging the wall.

Awesome game, I love the options :)

by emilfihlmanon 12/17/2018, 4:23 PM

There's an off by one error on sides, fire and it's effects can go along the sides.

by Kyeon 12/17/2018, 9:27 PM

You can create a little self-sustaining motion with a cloner covered in something that falls over a lake of acid.

https://sandspiel.club/#IbQHF3edJmCy1dLJAWO8

by lstoddon 12/17/2018, 1:57 AM

This is great. I'm almost tempted to redo this with believable thermodynamics.

by glitchcon 12/17/2018, 1:55 AM

Working in Safari on iOS 12

by itsjustme321on 12/17/2018, 3:21 AM

Reminds me of The Powder Toy, which is great by the way, lots of fun!

by sj4nzon 12/17/2018, 2:06 AM

Drop oil on lava.

The effect is worth it.

by jl6on 12/17/2018, 6:49 AM

I remember watching Confetti Factory on After Dark, which I think of as a primitive precursor to this. Must have been very early 1990s. Any earlier examples?

by johnisgoodon 12/17/2018, 2:10 PM

I love fungus. It makes the plant grow. Pour some acid on it, it will regrow! On the other hand, fire is pretty destructive.

You know what feature I miss? Fast-forwarding!

by neveson 12/17/2018, 12:49 PM

Does this game have any objective? I didn't get it.

by _57jbon 12/17/2018, 4:07 AM

This was mesmerizing. Well done, thoroughly enjoyed it.

by avipon 12/17/2018, 1:53 AM

Wind effect is beautiful and looks like a Julia set.

by anoncowon 12/17/2018, 5:27 AM

Really liked lava and fire. I don’t know why gravity doesn’t affect the blue stuff. Can you disable page swipe gestures on mobile chrome?

by ok-replon 12/18/2018, 2:07 PM

I've always been fascinated by these simulations. Can anybody give a rough overview of how these (I guess?) fluid simulations work?

by mgoetzkeon 12/18/2018, 1:05 PM

Great ! Was just looking for something like this for a snow effect. I used to do something with falling snow on text for Christmas.

by sadjadon 12/17/2018, 6:25 PM

It's weird, but I can't share the link on Twitter, and goo.gl shortlink doesn't work either.

Does anyone have the same problem?

by mattdeboardon 12/17/2018, 4:10 AM

Weird, I was just looking at this today. Very cool project! I have a feature idea on my stack of ideas I hope to get to

by windlessstormon 12/17/2018, 5:52 AM

Site is got down of big HN hug I guess

by skykooleron 12/17/2018, 7:31 AM

This is excellent fun. I'm kind of curious though as to why blowing wind at the dust ignites it?

by shittyadminon 12/17/2018, 6:02 PM

The smoke and explosion effects are amazing, better than any other FSG I've tried. Very cool.

by ddinguson 12/17/2018, 3:20 PM

I had fun with this. Great effects. Lava, lol.

I got a lot going, 25fps Samsung Note 8, Power Saving Mode

32 fps Performance Mode

by Santosh83on 12/17/2018, 3:00 AM

Will activating WebRender improve framerates?

Not that it needs improving anyway... just curious.

by gigatexalon 12/17/2018, 5:36 AM

Fun little game! 42FPS on my iPhone X, too. And best of all no excessive heat

by ecabukon 12/17/2018, 1:28 PM

Lava cannot melt ice? :D

by profalseidolon 12/19/2018, 11:06 AM

Ice can hold lava?

btw, adding oil over lava produces a very cool smoke effect.

by miguelmotaon 12/17/2018, 7:01 PM

This is incredible. Runs flawlessly and surprisingly smooth

by nablaoperatoron 12/17/2018, 9:27 AM

Reminds me of Clonk!

by jtsiskinon 12/17/2018, 5:30 AM

I get 1-2 FPS running this in Chrome on macOS Mojave.

by jeffrallenon 12/17/2018, 2:29 PM

Lava should make water turn to gas and blow up!

by bredrenon 12/17/2018, 4:06 AM

I like the smoke when you burn the fungus.

by geitiron 12/17/2018, 1:59 AM

This is fun

by omanion 12/17/2018, 1:45 AM

nothing happens on mobile

by Evidloon 12/17/2018, 8:28 PM

Fun, but a bit blurry.

by hujunon 12/17/2018, 4:28 AM

create some plants, and drop some seed on it

by gworfon 12/17/2018, 11:50 AM

This is fun!

by hyperpalliumon 12/17/2018, 2:02 AM

Is it really a "game" if there's no goal or "win" condition? Or is it a "webtoy" or "simulation" (or... "sandbox". Think it's a sandbox).

by PavlovsCaton 12/17/2018, 2:19 AM

https://sandspiel.club/#A6xPmAP4TSEpcwThAFSB

erase the thingy to the right, and the planets on the left grow upwards again.

by choochootrain6on 12/17/2018, 12:34 PM

I've never played Powder Toy, but I do remember playing something called Powder Game. Are they related in some way?

by the_other_guyon 12/17/2018, 1:54 AM

This is the most satisfying thing I've ever seen on HN!