billyb2 / game

GNU Affero General Public License v3.0
2 stars 0 forks source link

Web Assembly (Browser) Support #1

Closed billyb2 closed 3 years ago

billyb2 commented 3 years ago

Eventually, we're gonna want to run this game on the browser. Though the game is very clearly incomplete right now, we need to keep some things in mind as this game rolls through development:

  1. WebAssembly doesn't have ANY graphics access. That means that some (small and easy) parts of the game will have to be rewritten, such as the entirity of the main.rs file. Stuff like the bots.rs file and the game.rs file are mostly fine, though some parts will have to be rewritten to use WebAPIs. Basically, anything to do with game logic will require very little rewriting, and anything to do with stuff like audio or graphics will have to be rewritten in JavaScript (though these parts of the code would be very easy to rewrite, using the HTML5 canvas).
  2. WebAssembly doesn't have ANY network access. As such, any multiplayer stuff couldn't be rewritten with big beautiful UDP, and instead would probably have to be written to use WebSockets or something similar for compatibility with web stuff.
billyb2 commented 3 years ago

Look into this.

billyb2 commented 3 years ago

We could possibly have this crate as a submodule, then reference the game_logic crate using path in Cargo.toml to compile the WASM.

billyb2 commented 3 years ago

After trying both WebAssembly and ASM.js while working on 59d86a4167f8ea2bf9e85f1a6c480fa860585198, I noticed that WebAssembly is much, much faster (like compression took 3 seconds vs 20 seconds), so unless we have to , it's the way to go. Though I must note that ASM.js was much easier to get ready, since I didn't have to do any data post-processing (mainly converting it to base64)

billyb2 commented 3 years ago

Closing, 70a7b35696b64e6dc06c2e2423c0e5826647e6b2 finally gets WASM working!