-
-
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
Cleanup bevy_winit #11257
Cleanup bevy_winit #11257
Conversation
This will conflict with #11245: opinions on merge order? |
This set of changes is relatively trivial. Unlike #11227, which was a pretty fundamental change in the way the event loop gets updated, this just changes the way we send event, and extracts common code in a type alias. I'm fine if we merge #11245 first. At this point, I'm comfortable with rebasing. What I really do not want to happen is for this PR to stall like #9768. I'd be happy if this gets reviewed as soon as #11245 is merged and this rebased. |
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.
Looks good, but it looks like WindowTitleCache
is never used. So maybe remove that too?
let msg = "Bevy must be setup with the #[bevy_main] macro on Android"; | ||
event_loop_builder.with_android_app(ANDROID_APP.get().expect(msg).clone()); |
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 don't really understand why you are separating the msg
into a separate variable. If you wanted to reduce indentation I think this will work better:
let msg = "Bevy must be setup with the #[bevy_main] macro on Android"; | |
event_loop_builder.with_android_app(ANDROID_APP.get().expect(msg).clone()); | |
let app = ANDROID_APP | |
.get() | |
.expect("Bevy must be setup with the #[bevy_main] macro on Android") | |
.clone(); | |
event_loop_builder.with_android_app(app); |
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.
It's just a personal style choice. I prefer to avoid expanding the method chain into several lines, it occupies vertical space and you can see less things on screen at the same time.
But it's purely personal preference. If the community prefers the expanded version, I'll switch back.
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.
Alright that's fine by me.
Merging #11245 now; rebase and ping me then I'll merge this in immediately. |
The `bevy_winit` crate has a very large `lib.rs`, the size is daunting and discourages both contributors and reviewers. Beside, more code implies more ways to accidentally introduce bugs. This PR does a few things to reduce greatly the line count, without really changing much logic: - Move the winit event handler to a standalone function. This reduces the amount of indentation, and isolates relevant code. - Replace the `WindowAndInputEventWriters` struct with direct calls to `World::send_event`. This is done through a new private extension trait called `AppSendEvent`. Now, instead of using `event_writers.specific_events.send(SpecificEvent { … })`, it directly does `app.send_event(SpecificEvent { … })`. Looking at the `send_event` implementation, I didn't see anything that would lead me to believe this is more costly or leads to different behaviors. With this change, we both reduce boilerplate on event sending and delete the `WindowAndInputEventWriters` struct - Rename `window_entity` to `window`. This allows constructing most `bevy_window` events in a single line, rather than being split on several lines by `rustfmt`. This is also more consistent, since the `Entity` field of `bevy_window` events is called `window`, it makes sense to re-use the same name to designate the same thing. This removes a lot of boilerplate. - Explicitly name the `CreateWindowParams` as a type alias instead of copy/pasting it about everywhere. In `create_windows`, instead of accepting each param field, accept the whole param. This removes a lot of boilerplate as well. The combination of all those changes leads to a reduction of 200 lines. **Notes to reviewers** You should really use the "Hide whitespaces" diff display mode. The trickiest bit is probably the scale factor handling. Because we now directly access the world, I had to move event-sending code around, to avoid breaking mutual exclusion rules. I'm fairly confident it's the same behavior. Another thing that deserves looking-at is non-linux plateform handling. I've only compiled this for linux targets, hence it might fail to compile on other plateforms.
59b6f1e
to
70c36bf
Compare
@alice-i-cecile should be good to go. Also TIL that you can use |
impl AppSendEvent for App { | ||
fn send_event<E: bevy_ecs::event::Event>(&mut self, event: E) { | ||
self.world.send_event(event); | ||
} | ||
} |
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 like it, and I wouldn't block on it, but this might be better as a usability method within bevy_ecs maybe?
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 tried to add it earlier and it was controversial IIRC 😅 Private helper is fine though.
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 like it 👍 tested a few examples on windows native + firefox
Once we've checked that there's no new problems on Android / iOS this is good to go. |
Merging later today. Ping me if I forget. |
Oops misclicked on mobile
Has it been tested on enough platforms? |
Hmm. We should resolve conflicts and do another round of testing. |
# Objective Get #11257 changes merged. I rewrote them one by one checking each to ensure correctness. In particular, the window rescale logic changes to accomodate mut app access are double checked. Not all changes have been included as some of bevy_winit has since changed, and i am not confident including them. Namely, the `run_app_update_if_should` change. ### Notes to reviewers Review commits individually, use the "Hide whitespaces" diff display mode. ## Changelog * `bevy::window::WindowMoved`'s `entity` field has been renamed to `window` ## Migration Guide `bevy::window::WindowMoved`'s `entity` field has been renamed to `window`. This is to be more consistent with other windowing events. Consider changing usage: ```diff -window_moved.entity +window_moved.window ``` --------- Co-authored-by: François <[email protected]>
#11489 completes this. |
# Objective Get bevyengine#11257 changes merged. I rewrote them one by one checking each to ensure correctness. In particular, the window rescale logic changes to accomodate mut app access are double checked. Not all changes have been included as some of bevy_winit has since changed, and i am not confident including them. Namely, the `run_app_update_if_should` change. ### Notes to reviewers Review commits individually, use the "Hide whitespaces" diff display mode. ## Changelog * `bevy::window::WindowMoved`'s `entity` field has been renamed to `window` ## Migration Guide `bevy::window::WindowMoved`'s `entity` field has been renamed to `window`. This is to be more consistent with other windowing events. Consider changing usage: ```diff -window_moved.entity +window_moved.window ``` --------- Co-authored-by: François <[email protected]>
Objective
The
bevy_winit
crate has a very largelib.rs
, the size is daunting and discourages both contributors and reviewers. Beside, more code implies more ways to accidentally introduce bugs.Solution
This PR does a few things to reduce the line count, without changing logic:
WindowAndInputEventWriters
struct with direct calls toWorld::send_event
. This is done through a new private extension trait calledAppSendEvent
. Now, instead of usingevent_writers.specific_events.send(SpecificEvent { … })
, it directly doesapp.send_event(SpecificEvent { … })
. Looking at thesend_event
implementation, I didn't see anything that would lead me to believe this is more costly or leads to different behaviors. With this change, we both reduce boilerplate on event sending and delete theWindowAndInputEventWriters
structwindow_entity
towindow
. This allows constructing mostbevy_window
events in a single line, rather than being split on several lines byrustfmt
. This is also more consistent, since theEntity
field ofbevy_window
events is calledwindow
, it makes sense to re-use the same name to designate the same thing. This removes a lot of boilerplate.CreateWindowParams
as a type alias instead of copy/pasting it about everywhere. Increate_windows
, instead of accepting each param field, accept the whole param. This removes a lot of boilerplate as well.The combination of all those changes leads to a reduction of 200 lines.
Notes to reviewers
You should really use the "Hide whitespaces" diff display mode.
The trickiest bit is probably the scale factor handling. Because we now directly access the world, I had to move event-sending code around, to avoid breaking mutual exclusion rules. I'm fairly confident it's the same behavior.
Another thing that deserves looking-at is non-linux plateform handling. I've only compiled this for linux targets, hence it might fail to compile on other plateforms.
Changelog
bevy::window::WindowMoved
'sentity
field has been renamed towindow
Migration Guide
bevy::window::WindowMoved
'sentity
field has been renamed towindow
. This is to be more consistent with other windowing events.Consider changing usage: