Porting Principia to the web!

(Avatar)
ROllerozxa
Posted on 2025-03-16 15:08 Link

Since last year there has been support for compiling Principia to WebAssembly using Emscripten. WebAssembly is a modern web technology that allows you to compile native code such as C or C++ into something that can be run inside web browsers, which can be combined with WebGL for more advanced graphics rendering. Principia was able to be successfully compiled (which was pretty easy due to SDL's great support for Emscripten), but that was about it.

Recently I picked back up working on it and it has now gotten to the point where the main menu works and you can go in-game without it crashing. However everything but the GUI and the background does not render, the exact issue for which is currently unknown. I ended up throwing up a web build of the game in the current state that it's in (note: very much not playable!), which is available here:

https://principia-web.se/~web/

Help would be appreciated in getting the web port fully functional one day, as the current GL errors that make the game world not render is very difficult to track down.

The goal for the web port would be for it to function well enough for playing levels from the community site in one's web browser, though having the sandbox and level creation experience be fully functional would also be a bonus. The WIP and experimental Dear Imgui dialog backend would also be handy for that.

There are now compilation instructions available for Emscripten on the wiki, and the status of the web port is being tracked in issue #154.

(Avatar)
Galaxium
Posted on 2025-06-22 19:12 Link

I'd help but I suck at coding. Though I know enough to know what does what ¯_(ツ)_/¯

(Avatar)
ROllerozxa
Posted on 2025-12-28 00:12 Link

Today I managed to crack the code as to why the game wouldn't render much of anything, and was pretty quickly able to get some stuff rendering in-game finally.

...However, it was not entirely perfect.

But with some more work later, the web version is now in a state where it could theoretically be playable with some levels.

There is now a link on each level page (only visible for logged in users for now) to open the level in the web version to play it directly in your browser directly on the community site, available for both current levels and levels in the archive. It is of course still highly experimental and expect all sorts of bugs and glitches, though I was able to play through Art Adventure without any issues. The playability and performance will vary from level to level. My Marble Maze level should be fairly playable.

(Avatar)
ROllerozxa
Posted on 2025-12-28 23:45 Link

Another batch of fixes have been made to the web port today that are now live. Most graphical glitches should be fixed now and opening the level player in a new tab should fill the browser window now. The link on each level page is now visible to everyone even without an account, which hopefully may make people interested in trying it out.

Having a functional browser version is good in general as it allows for a more convenient way to try out the game without installing it (or if you can't install the game on a computer), and it will also run on platforms where there is no native version such as macOS, iOS and locked down Chrome OS installations. I'm sure people will manage to get it running on even more weird places where there's a modern web browser available.

While the primary usefulness of the web port is being able to play levels from the community site with it, you can go to https://principia-web.se/wasm/ without a level ID in the URL to launch the game normally and go into the sandbox. However it is very limited at the moment as the web version uses the incomplete Imgui dialog backend with a lot of dialogs in the sandbox unimplemented, and all networking code for the game needs to be rewritten for Emscripten in mind in order to work in the web version (currently only downloading levels has been implemented). But things are looking bright for the future.