-
-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Third Party WASM Library Support #212
Comments
It is certainly possible, we do not use either wasm-bindgen nor stdweb, therefore it may be possible to load macroquad's wasm with those tools somehow. But personally, I am not really interested in this - I like the pipeline without So I would not work on this in foreseen future, but people want it sometimes and if someone will do some guide on using macroquad will wasm-bindgen - I would appreciate it and will add a link to that guide to readme :) |
Approaching it from the other end, maybe there should be a guide for doing this using the standard method for macroquad. I.e., how would a user go about binding a new dependency without those tools? |
Sure, we actually have such a guide! |
I took a stab at getting wasm-bindgen to work for macroquad; and a working flow is as follows:
With these changes, the index.html below seems to work. Note that this needs to use the wasm file generated by wasm-bindgen, as it'll otherwise contain some unlinkable methods in undefined modules. <script src="https://not-fl3.github.io/miniquad-samples/mq_js_bundle.js"></script>
<script type="module">
import init, { set_wasm } from "./wbindgen/my-project.js";
async function run() {
let wbg = await init();
miniquad_add_plugin({
register_plugin: (a) => (a.wbg = wbg),
on_init: () => set_wasm(wasm_exports),
version: "0.0.1",
name: "wbg",
});
load("./wbindgen/my-project_bg.wasm");
}
run();
</script> I packaged this as a build-script here: https://gist.github.com/tgolsson/d78f7887a8542f3fd6f125070e5e22d6 |
The script is not working for me. Could you explain what kind of patch is necessary to make it work with wasm-bindgen? |
Otherwise wasm builds don't work Ok, this is an interesting one. Apparently Macroquad has a custom WASM build process[1], and the moment another WASM compatible library is added the the project, it no longer works in browser. rand crate, or rather its dependency getrandom, is one of those. There is a way to make it potentially work together[2], but I decided not going into this madness, I feel it's a huge time sink. Using quad_rand is not without its problems, it still needs a source of randomness to intialize the RNG; the workaround that I found is using time from the launch of the app till the player chooses side. Then, the shuffle method is Fisher-Yates algorithm that I got from wikipedia[3]. Admittedly, it took more than one attempt to weed out all the off-by-one errors that I made. Overall I feel like this whole situation is a big turn-off for me from using macroquad for anything that needs to run in a web-browser. Being locked out from using many dependencies is quite a limitation. As I mentioned above, it's potentially solvable, but this not something you want to spend your time while developing a game. [1] not-fl3/macroquad#212 [2] not-fl3/macroquad#212 (comment) [3] https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
the last version of the script to build macroquad whit wasm bindgen: https://gist.github.com/nicolas-sabbatini/8af10dddc96be76d2bf24fc671131add |
I am not skilled with webassembly Rust builds but as noted here:
https://gitlab.com/gilrs-project/gilrs/-/issues/99
Macroquad has a custom WASM build process. The only downside to this I see is that all other WASM compatible libraries do not work with Macroquad.
It's possible that a custom or manual step is needed and I just don't know what it is, but perhaps integrating into a standard like wasm-bindgen or stdweb would enable other WASM compatible libraries to be seamlessly used with Macroquad.
If there is an easy manual step like adding a script tag to the HTML page and I just don't know how that is another matter but it'd be awesome to just build and run :)
The text was updated successfully, but these errors were encountered: