1. 114

Just wanted to share my project of the last few months with the lobsters community!

Source code: https://github.com/maxbittker/sandspiel

Sandspiel leverages Rust for the heavy duty game update logic, WebGL for the fluid simulation, and javascript to glue things together and implement the game’s UI and social features. Building in web assembly was surprisingly productive and painless- the tools, interop, and performance all exceeded my expectations and made this game really rewarding to build!


  2. 20

    Impressive! I particularly like the smoke effects that come from fire. Are you doing some fluid dynamics to get that behaviour?

    1. 21

      yep, the fluid simulation also runs completely on the GPU, which is one reason it’s so smooth. I adapted this excellent implementation for my needs: https://github.com/PavelDoGreat/WebGL-Fluid-Simulation

    2. 12

      I spent an embarrassing amount of time on that, thanks!

      1. 10

        The fact that I don’t experience any significant FPS drop regardless number of particles is quite amazing.

        1. 3

          Cool game :-) I’ve managed to grow some plants in lava, it’s fun :-)

          1. 8

            If you use a mix of the clone dots, seeds, and oil you can get a neat cycle of fire burning up plants and regrowth https://imgur.com/a/Qxmt6x9

            1. 1

              how did you accomplish that? :0 upload an example?

              1. 4

                The trick was to constantly water the surviving plant matter on the lava until it stabilized. Here’s an example: https://sandspiel.club/#uuL30AiL3VoU9roKgbwo

                1. 1

                  I think i had a similar effect of growing plants on lava if it the lava had died down enough. second time around i just put a small area of sand on top of the lava.

                  One more: https://imgur.com/4WnEg4F

              2. 3

                This was very cool when you demoed it before in a previous thread, glad to see it has come along even more since then!

                1. 2

                  Very nifty game. Performance is excellent. Did you have to play performance games to actually make it performant, or was that just out of the box?

                  1. 6

                    good question- for the “engine” aspect of the code, I was keeping performance characteristics in mind through my choice of languages, and there were a few false starts along the way. (i built this entire game once in JS and once in lua in the past)

                    for the “logic” code in species.rs that defines how elements behave, i felt able to do whatever I wanted, including lots of branching, some higher order functions, abstractions, casting type of numbers, etc. (but, definitely very little heap allocation). This is notable because language expressiveness here indirectly impacts how fun the game is, but this code is also super hot and runs thousands of times per frame.

                    an interesting anecdote here is that I unwittingly wrote most of the game with my rustc optimization strategy on “z”, optimize for binary size. once the project was already quite developed I realized this and switched it to o3 which things like inlining and gave me a big performance boost, where i had been being frugal!

                  2. 2

                    This is so fun, thanks for making it!

                    1. 1

                      : )

                    2. 2

                      Awesome! Just curious, what changed between your comment on the previous “Rust and WASM” story and now?

                      1. 6

                        the biggest things were mobile browser GPU support (this was hard), the upload/browse/restore backend, and a few new elements + tweaking to many of their behaviors

                        1. 2

                          what were the issues with mobile browser gpu support?

                          1. 5

                            The two main issues were:

                            The texture types they support (the fluid sim is in floats, but on phone browsers I could only take data in or out of the shaders via unsigned byte textures, required some munging)

                            There’s also a maximum # of bound texture units of 8, and I had to plug a lot of gaps in my knowledge of how OpenGL works in order to correctly bind textures for each program and stay under that limit.

                            all of this was made more complicated by the fact my only phone is an iphone and I don’t own a macbook. Apple only allows you to connect to the safari devtools from a mac >:’( So i was debugging somewhat blind.

                            1. 1

                              Apple requires developers to both own a mac to build and also pay them a yearly fee to be able to offer even free apps on their app store. This kinda sucks, but on the other hand the hardware + macOS is okay.

                      2. 2

                        Cool but I can’t figure out how to insert the bunnies.

                        1. 1

                          Please let me get some work done today! All I can do is lay down fungus, plant seeds and the light it afire with a could of dust. I need to work today!

                          1. 1

                            Why is there always wind to the left? Any way to adjust that?

                            1. 1

                              do you mean that particles are blowing to the left and there’s no fire or anything generating that wind? if so, that sounds like a bug in the webgl code, what browser + device are you on?

                              1. 1

                                I’m using firefox 63 on arch linux. Here’s a screenshot of what I’m observing. Actually, from experimenting with chrome, it seems like almost everything is going in the wrong direction. Fire floats downward, “gases” float up, and ice falls instead of staying put.

                                1. 3

                                  I’m sorry that it doesn’t work, you may have better luck on a smartphone. WebGL has a huge surface area of browser and platform specific implementation details, and I don’t think I could hunt down the issue unless I could reproduce your issue locally. (FWIW, firefox 60 on ubuntu works for me)