emoon / rust_minifb

Cross platfrom window and framebuffer crate for Rust
MIT License
1.01k stars 97 forks source link

Wasm websys wip #239

Closed dc740 closed 2 years ago

dc740 commented 3 years ago

This is a possible implementation, based on @tversteeg code. For the web part to work you need to have an executor and use spawn_local. This implementation does not force any executor, in fact, it does not even care what you use.

I still need to work on an example, and test it. It compiles, and all that really matters on this is to always keep a reference to the window, so the buffer does not go out of scope (which would trigger this: https://github.com/rustwasm/wasm-bindgen/issues/2445 ) Compile using:


cargo build --target=wasm32-unknown-unknown --verbose --no-default-features --features web                       
dc740 commented 2 years ago

Hi, I put some extra work the last couple of days on this:

This is usable now. Getting minifb on the web requires some extra work, and I can't provide a simple example to do "cargo run minifb_web", that's why I had to add the example in other repository.

I kept it as small as possible, and after some research I don't think there is any other way to implement it. There is no way to keep the simple application loop that the desktop uses, but after this PR it's possible to finally run a (mostly canon) minifb application on the web using webassembly and some auto generated javascript glue code as shown in the demo.

I was hoping this PR could be merged so other people can start making improvements on it. Let me know if you think that's possible, or which things you think are blocking this PR.

emoon commented 2 years ago

Merged! Thanks for your work on this :)