Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information