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

Disable camera on window close #8802

Merged
merged 2 commits into from Jun 10, 2023

Conversation

IceSentry
Copy link
Contributor

@IceSentry IceSentry commented Jun 9, 2023

Objective

  • When a window is closed, the associated camera keeps rendering even if the RenderTarget isn't valid anymore.
    • This is essentially just wasting a lot of performance.

Solution

  • Detect the window close event and disable any camera that used the window has a RenderTarget.

Notes

It's possible a similar thing could be done for camera that use an image handle, but I would fix that in a separate PR.

@IceSentry IceSentry added A-Windowing Platform-agnostic interface layer to run your app in A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use labels Jun 9, 2023
@@ -520,6 +526,18 @@ pub fn camera_system<T: CameraProjection + Component>(
) {
let primary_window = primary_window.iter().next();

// Disable the camera associated to a window that's just been closed
for ev in window_close_events.iter() {
for (mut camera, _) in &mut cameras {
Copy link
Member

Choose a reason for hiding this comment

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

Why not use query.get_mut here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There could be multiple camera per window, like for split screen. Also, the window doesn't have a camera entity id. It's the camera that contains a reference to the window.

@cart
Copy link
Member

cart commented Jun 10, 2023

This feels slightly off to me. Camera "activeness" is user-provided configuration that happens to result in camera outputs being rendered. I think it makes more sense to transparently skip rendering without touching user configuration (aka do the skip on the render app side).

Otherwise this will probably lead to weird / unexpected behaviors. For example: if you remove the "primary window" and then re-add it, it seems like this PR would result in default cameras not silently not working when the primary window is respawned. The user would need to know to re-activate the cameras manually.

@IceSentry
Copy link
Contributor Author

Right, I see what you mean. I'll see if there's a cleaner way to do this then.

@IceSentry IceSentry force-pushed the disable-camera-window-close branch from 7c8454a to d515786 Compare June 10, 2023 15:28
@IceSentry
Copy link
Contributor Author

Alright @cart that was a good call. I now disable it just before running the graph. It's a lot more transparent for the user and seems like a cleaner fix.

@cart cart added this pull request to the merge queue Jun 10, 2023
Merged via the queue into bevyengine:main with commit 75da2e7 Jun 10, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants