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

Refactor rendering systems to use let-else #9870

Merged
merged 4 commits into from
Sep 20, 2023

Conversation

nicopap
Copy link
Contributor

@nicopap nicopap commented Sep 20, 2023

Objective

Some rendering system did heavy use of if let, and could be improved by using let else.

Solution

  • Reduce rightward drift by using let-else over if-let
  • Extract value-to-key mappings to their own functions so that the system is less bloated, easier to understand
  • Use a let binding instead of untupling in closure argument to reduce indentation

Note to reviewers

Enable the "no white space diff" for easier viewing.
In the "Files changed" view, click on the little cog right of the "Jump to" text, on the row where the "Review changes" button is. then enable the "Hide whitespace" checkbox and click reload.

- Reduce rightward drift by using let-else over if-let
- Extract value-to-key mappings to their own functions so that the
  system is less bloated, easier to understand
@nicopap nicopap added A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change labels Sep 20, 2023
@nicopap
Copy link
Contributor Author

nicopap commented Sep 20, 2023

Wait, there is also wireframe.rs that can get the same change.

crates/bevy_pbr/src/material.rs Outdated Show resolved Hide resolved
crates/bevy_pbr/src/material.rs Outdated Show resolved Hide resolved
crates/bevy_sprite/src/mesh2d/material.rs Outdated Show resolved Hide resolved
@nicopap
Copy link
Contributor Author

nicopap commented Sep 20, 2023

There is still more in render/light.rs

@nicopap nicopap changed the title Refactor material queue systems Refactor rendering systems to use let-else Sep 20, 2023
Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

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

Not a huge fan of how rustfmt handles let-else, but less heavy indentation in these huge functions is definitely the lesser evil 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.

I personally preferred having all the pipeline_key stuff inlined instead of in separate functions but other than that I like using let else everywhere so I'll just approve this.

@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 Sep 20, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 20, 2023
Merged via the queue into bevyengine:main with commit 47d87e4 Sep 20, 2023
22 checks passed
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# Objective

Some rendering system did heavy use of `if let`, and could be improved
by using `let else`.

## Solution

- Reduce rightward drift by using let-else over if-let
- Extract value-to-key mappings to their own functions so that the
system is less bloated, easier to understand
- Use a `let` binding instead of untupling in closure argument to reduce
indentation

## Note to reviewers

Enable the "no white space diff" for easier viewing.
In the "Files changed" view, click on the little cog right of the "Jump
to" text, on the row where the "Review changes" button is. then enable
the "Hide whitespace" checkbox and click reload.
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 C-Code-Quality A section of code that is hard to understand or change 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