smokku/bevy_networking_turbulence

Graphical wasm example (Enhancement)

ostwilkens opened this issue ยท 12 comments

With bevy and wasm support, you can't avoid longingly looking at https://github.com/mrk-its/bevy_webgl2.

The balls example should be possible to get running in the browser with this plugin.
This requires

  • git version of bevy
  • working channels

With some fiddling, I have gotten it to build (webrtc server, wasm client):
https://github.com/ostwilkens/bevy_networking_turbulence/tree/channel_wasm_example

Server seems to work well, but the client hangs on load, freezing my chrome tab. I'm pretty sure this has to do with the channels, as it doesn't hang when the networking is commented out.

You should be able to break the execution in browser (F8) and see where it hangs.
WASM debugger in Chrome is awesome.

Good tip, pausing with the debugger made the tab responsive again.

It might be related to the do_delay function, it seems to spend a lot of time here. The current function is take_last_exception, but I don't get any exceptions in the log..

image

I will keep looking.

do_delay seems to be called ~1000 times per second, with a delay of 100ms. I wonder if this is expected?

Sounds like an overkill. I'm not sure how bevy_winit/bevy_webgl2 does vsync under WASM.
I think it should be synced with RequestAnimationFrame.

@ostwilkens @smokku bevy_webgl2 doesn't touch bevy's runner at all, so runner provided by winit is used. And yes, winit under WASM uses RequestAnimationFrame internally

Thank you for the information @mrk-its :-)

Fix for do_delay is on master now.

I am hesitant to support balls example on WASM, as it pulls so many dependencies in. Notice that bevy_networking_turbulence plugin runs with Bevy's default features disabled. You only pull "bevy/default" for the balls example build.
I would rather create a headless example for channels feature, that would just work both native and in browser.

@ostwilkens thank you for your bug report and investigation.

I will close this bug now. Feel free to reopen if there are still issues with the code on current master branch. ๐Ÿ˜ƒ

You're doing god's work! This confirms channels are working.

I understand wanting to keep it headless. My example also uses a lot of ugly #[cfg] stuff. I might set up an example bevy_networking_turbulence + bevy_webgl2 repo to help attract the attention this deserves!

Yeah. A separate repo might work.

Said and done, an initial version with ping/pong messages:
https://github.com/ostwilkens/arugio