-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Add WebPlugin to keep running in background #371
Conversation
This has universally great functionality - Should be a plugin one can easily |
if window().unwrap().document().unwrap().hidden() { | ||
// Imitate app.update() | ||
let world = unsafe { world_ptr.write().unwrap().as_mut().unwrap() }; | ||
world.run_schedule(Main); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magnifique
@simbleau thanks :p |
re: configurable interval
|
re: trottled web workers |
Another note ill save here: |
Please let me know when it's done, I'd add this to my bevy_rtc project today. |
maybe make an impl urself for now then, ill prob wont have time until weekend |
Fixes #144
All credit for this PR goes to @Nul-led who came up with the idea and did the entire implementation.
I just copy-pasted his code to put it in a
WebPlugin
. Thank you very much for this amazing solution!In wasm, the main thread gets quickly throttled by the browser when it is hidden (e.g. when the user switches tabs).
This means that the app.update() function will not be called, because bevy's scheduler only runs
app.update()
whenthe browser's requestAnimationFrame is called. (and that happens only when the tab is visible)
This is problematic because:
This solution spawns a WebWorker (a background thread) which is not throttled, and which runs
app.update()
at a fixed interval. This way, the client can keep sending and receiving packets,and updating the local World.
TODO:
world.clear_trackers()