r/monogame • u/jma-dev • 7h ago
Multi threaded Falling Sand simulator in a browser using MonoGame
Enable HLS to view with audio, or disable this notification
Using MonoGame DesktopGL together with KNI to achieve multithreading in the browser.
In the browser, .NET’s threaded WebAssembly runtime lets workers share memory, so the simulation and terrain rasterization can run off the page thread. The renderer draws from a snapshot while the next simulation step runs. A small native bridge lets the game hand off the whole draw at once, keeping WebGL calls on the page thread.
My first attempt was running single threaded, but the game ran at a complete crawl. The render thread could have handled it, but all the simulation steps are very heavy (pixel level physics). This browser version is a Demo of the full game. I'm very happy with how well it ended up running, although it's not as performant as the full desktop version.
If interested, check out the browser demo at https://gravitonia.com/ and check out the Steam Store Page at https://store.steampowered.com/app/5272000/Gravitonia/
The game will be released on December 17.