Skip to content
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

Improve bevy_winit documentation #7609

Merged
merged 7 commits into from
Jul 31, 2023

Conversation

maniwani
Copy link
Contributor

@maniwani maniwani commented Feb 10, 2023

Redo of #7590 since I messed up my branch.

Objective

  • Revise docs.
  • Refactor event loop code a little bit to make it easier to follow.

Solution

  • Do the above.

Migration Guide

  • UpdateMode::Reactive { max_wait: .. } -> UpdateMode::Reactive { wait: .. }
  • UpdateMode::ReactiveLowPower { max_wait: .. } -> UpdateMode::ReactiveLowPower { wait: .. }

@maniwani maniwani changed the title refactoring Improve bevy_winit documentation Feb 10, 2023
@maniwani maniwani added C-Docs An addition or correction to our documentation A-Windowing Platform-agnostic interface layer to run your app in C-Code-Quality A section of code that is hard to understand or change C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide labels Feb 10, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me and clean things up, but this needs to be rebased.

@maniwani maniwani force-pushed the bevy-winit-refactoring branch 2 times, most recently from f1a0efb to 45ac905 Compare July 25, 2023 19:23
@github-actions
Copy link
Contributor

Example alien_cake_addict failed to run, please try running it locally and check the result.

@maniwani maniwani force-pushed the bevy-winit-refactoring branch 2 times, most recently from b664432 to dfe3bea Compare July 25, 2023 19:37
@github-actions
Copy link
Contributor

Example alien_cake_addict failed to run, please try running it locally and check the result.

@github-actions
Copy link
Contributor

Example alien_cake_addict failed to run, please try running it locally and check the result.

Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this looks good to me. I can't comment on the unsafe part though.

crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_winit/src/lib.rs Show resolved Hide resolved
crates/bevy_winit/src/lib.rs Show resolved Hide resolved
crates/bevy_winit/src/lib.rs Show resolved Hide resolved
@maniwani maniwani force-pushed the bevy-winit-refactoring branch 2 times, most recently from a716fce to 10a8ea6 Compare July 25, 2023 21:10
@maniwani
Copy link
Contributor Author

I can't comment on the unsafe part though.

@IceSentry, I changed it back to doing the SystemState::get_mut and passing those references into the function. I was doing the lifetime transmute in #9122 because it's essential with those changes, but it's not essential here.

Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, nothing else jumps out at me so LGTM

@ickk
Copy link
Member

ickk commented Jul 25, 2023

I'm guessing the addition of the generic T to functions taking EventLoop<()> is to support #9122?

Otherwise in this PR I don't understand its purpose, since all the functions of note here are private, and WinitPlugin only explicitly constructs an EventLoop<()>; it adds some cognitive load. But if you're going to add it anyway in that other PR then its fine here

@maniwani
Copy link
Contributor Author

I'm guessing the addition of the generic T to functions taking EventLoop<()> is #9122?

Ah, yes, that's correct. I'll change it back though. It's small enough, and it'll be justified then.

crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@Selene-Amanita Selene-Amanita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understood everything but I finally reviewed it.

Sorry for the delay.

I'm mostly concerned about #7609 (comment).

crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
@@ -244,79 +241,83 @@ struct InputEvents<'w> {
mouse_wheel_input: EventWriter<'w, MouseWheel>,
touch_input: EventWriter<'w, TouchInput>,
ime_input: EventWriter<'w, Ime>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Maybe events from bevy_input should be bellow the ones from bevy_window?

(with maybe a mention of that in the comments, and the "// device events" could mention more clearly that it's a winit's DeviceEvent and the other ones are WindowEvents?)

crates/bevy_winit/src/winit_config.rs Outdated Show resolved Hide resolved
/// input, or the window being resized) is received or the time limit is reached.
/// The [`App`](bevy_app::App) will update in response to the following, until an
/// [`AppExit`](bevy_app::AppExit) event appears:
/// - enough time has elapsed since the previous update
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - enough time has elapsed since the previous update
/// - enough time has elapsed since the previous update, see [`UpdateMode::Reactive::wait`]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why link back to Reactive a second time here when ReactiveLowPower's wait field already has its own documentation?

crates/bevy_winit/src/winit_config.rs Outdated Show resolved Hide resolved
crates/bevy_winit/src/winit_config.rs Outdated Show resolved Hide resolved
crates/bevy_winit/src/winit_config.rs Outdated Show resolved Hide resolved
maniwani and others added 3 commits July 30, 2023 23:11
Co-authored-by: Sélène Amanita <134181069+Selene-Amanita@users.noreply.github.com>
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jul 31, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 31, 2023
Merged via the queue into bevyengine:main with commit c0510c8 Jul 31, 2023
21 checks passed
@maniwani maniwani deleted the bevy-winit-refactoring branch August 5, 2023 17:38
github-merge-queue bot pushed a commit that referenced this pull request Sep 23, 2023
# Objective

- #7609 broke Android support

```
8721  8770 I event crates/bevy_winit/src/system.rs:55:  Creating new window "App" (0v0)
8721  8769 I RustStdoutStderr: thread '<unnamed>' panicked at 'Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.', winit-0.28.6/src/platform_impl/android/mod.rs:1058:13
```
## Solution

- Don't create windows on `StartCause::Init` as it's too early
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# Objective

- bevyengine#7609 broke Android support

```
8721  8770 I event crates/bevy_winit/src/system.rs:55:  Creating new window "App" (0v0)
8721  8769 I RustStdoutStderr: thread '<unnamed>' panicked at 'Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.', winit-0.28.6/src/platform_impl/android/mod.rs:1058:13
```
## Solution

- Don't create windows on `StartCause::Init` as it's too early
Subserial pushed a commit to Subserial/bevy_winit_hook that referenced this pull request Jan 24, 2024
# Objective

- bevyengine/bevy#7609 broke Android support

```
8721  8770 I event crates/bevy_winit/src/system.rs:55:  Creating new window "App" (0v0)
8721  8769 I RustStdoutStderr: thread '<unnamed>' panicked at 'Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.', winit-0.28.6/src/platform_impl/android/mod.rs:1058:13
```
## Solution

- Don't create windows on `StartCause::Init` as it's too early
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Code-Quality A section of code that is hard to understand or change C-Docs An addition or correction to our documentation S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants