-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 the ability to request a redraw from an external source #12197
Conversation
pub use the event loop proxy
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
crates/bevy_winit/src/lib.rs
Outdated
@@ -690,6 +692,9 @@ fn handle_winit_event( | |||
event_loop.set_control_flow(ControlFlow::Wait); | |||
} | |||
} | |||
Event::UserEvent(_) => { |
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.
Could you expose a specific type that should be sent to trigger a redraw rather than match on anything?
Reusing https://docs.rs/bevy/latest/bevy/window/struct.RequestRedraw.html would be nice
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.
I replaced the type with RequestRedraw. Also the reexport is now a type alias which prevents someone from using the wrong generic parameter when requesting the resource
crates/bevy_winit/src/lib.rs
Outdated
@@ -49,6 +49,8 @@ use winit::{ | |||
event_loop::{ControlFlow, EventLoop, EventLoopBuilder, EventLoopWindowTarget}, | |||
}; | |||
|
|||
pub use winit::event_loop::EventLoopProxy; |
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.
Nit: it'd be nice to have some documentation pointing users to this pattern somewhere. Maybe on WinitSettings::desktop_app
? Or maybe there's a better place for it?
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.
hi, i added some documentation. I also added it to the bullet points of Reactive
and ReactiveLowPower
This is already possible today by importing Worth noting bevy used to have something similar, so we should probably understand why it was removed before re-adding it: #674 |
@aevyrie Does this still work in 0.13? We used the same in version 0.12 but it was seemingly patched out. This pr is mostly to make the behavior explicit and prevent someone from using the wrong version of the event loop proxy. |
Nope, haven't updated to bevy 0.13 yet. Not sure what you mean by patched out - it's being used in this PR.
Yeah, that's a great point. Not needing to depend on |
@aevyrie the winit runner received some fixes to reduce sporadic updates. This also lead to the user event having no longer any effect, because the |
Ah good catch. in that case, this PR is also a bugfix for a regression. 😆 @alice-i-cecile IMO this should be be on the 0.13.1 milestone, if the event loop proxy no longer works, that's a pretty serious regression. |
@aevyrie yeah, i wasn't sure when making it. I did not know if the behavior was intentional ( also a case for better docs 😅) |
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.
Please make the type of user event explicit instead of "anything". that way it will be a breaking change later if we add support for more events
Hi, this is a minimal implementation of #12159. I wasn't sure if the `EventLoopProxy` should be wrapped somewhat to make it more explicit. Minimal implementation of #12159 When using `UpdateMode::Reactive` it is currently not possible to request a redraw when a long running task is finished or an external source has new data. This makes the following possible which will then run an app update once ``` rust // EventLoopProxy is Send on most architectures // The EventLoopProxy can also be saved in a thread local for WASM or a static in other architecturecs pub fn example(proxy: NonSend<EventLoopProxy<()>>) { let clone: EventLoopProxy<()> = proxy.clone(); thread::spawn(move || { // do long work clone.send_event(()); }); } ``` By using the EventLoopProxy one can manually send events from external threads to the event loop as `UserEvent`s. This simply sets redraw_requested when a `UserEvent` is received. - Added the ability to request a redraw from an external source --------- Co-authored-by: Kellner, Robin <Robin.Kellner@vector.com>
…ne#12197) Hi, this is a minimal implementation of bevyengine#12159. I wasn't sure if the `EventLoopProxy` should be wrapped somewhat to make it more explicit. # Objective Minimal implementation of bevyengine#12159 When using `UpdateMode::Reactive` it is currently not possible to request a redraw when a long running task is finished or an external source has new data. This makes the following possible which will then run an app update once ``` rust // EventLoopProxy is Send on most architectures // The EventLoopProxy can also be saved in a thread local for WASM or a static in other architecturecs pub fn example(proxy: NonSend<EventLoopProxy<()>>) { let clone: EventLoopProxy<()> = proxy.clone(); thread::spawn(move || { // do long work clone.send_event(()); }); } ``` ## Solution By using the EventLoopProxy one can manually send events from external threads to the event loop as `UserEvent`s. This simply sets redraw_requested when a `UserEvent` is received. ## Changelog - Added the ability to request a redraw from an external source --------- Co-authored-by: Kellner, Robin <Robin.Kellner@vector.com>
…ne#12197) Hi, this is a minimal implementation of bevyengine#12159. I wasn't sure if the `EventLoopProxy` should be wrapped somewhat to make it more explicit. # Objective Minimal implementation of bevyengine#12159 When using `UpdateMode::Reactive` it is currently not possible to request a redraw when a long running task is finished or an external source has new data. This makes the following possible which will then run an app update once ``` rust // EventLoopProxy is Send on most architectures // The EventLoopProxy can also be saved in a thread local for WASM or a static in other architecturecs pub fn example(proxy: NonSend<EventLoopProxy<()>>) { let clone: EventLoopProxy<()> = proxy.clone(); thread::spawn(move || { // do long work clone.send_event(()); }); } ``` ## Solution By using the EventLoopProxy one can manually send events from external threads to the event loop as `UserEvent`s. This simply sets redraw_requested when a `UserEvent` is received. ## Changelog - Added the ability to request a redraw from an external source --------- Co-authored-by: Kellner, Robin <Robin.Kellner@vector.com>
Hi, this is a minimal implementation of #12159. I wasn't sure if the
EventLoopProxy
should be wrapped somewhat to make it more explicit.Objective
Minimal implementation of #12159
When using
UpdateMode::Reactive
it is currently not possible to request a redraw when a long running task is finished or an external source has new data.This makes the following possible which will then run an app update once
Solution
By using the EventLoopProxy one can manually send events from external threads to the event loop as
UserEvent
s.This simply sets redraw_requested when a
UserEvent
is received.Changelog