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

[Merged by Bors] - Move magic numbers into constants in Breakout example #4255

Closed

Conversation

alice-i-cecile
Copy link
Member

@alice-i-cecile alice-i-cecile commented Mar 19, 2022

Objective

  • The Breakout example has a lot of configurable constant values for setup, but these are buried in the source code.
  • Magic numbers scattered in the source code are hard to follow.
  • Providing constants up front makes tweaking examples very approachable.

Solution

  • Move magic numbers into constants

Context

Part of the changes made in #2094; split out for easier review.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Mar 19, 2022
@alice-i-cecile alice-i-cecile added C-Examples An addition or correction to our examples C-Code-Quality A section of code that is hard to understand or change and removed S-Needs-Triage This issue needs to be labelled labels Mar 19, 2022
Copy link
Contributor

@hymm hymm left a comment

Choose a reason for hiding this comment

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

Overall I think moving the relevant constants to the top of the file makes sense as it does let beginners play with things more easily.

examples/game/breakout.rs Outdated Show resolved Hide resolved
examples/game/breakout.rs Show resolved Hide resolved
examples/game/breakout.rs Outdated Show resolved Hide resolved
examples/game/breakout.rs Outdated Show resolved Hide resolved
alice-i-cecile and others added 4 commits March 19, 2022 16:29
Co-authored-by: Mike <mike.hsu@gmail.com>
Co-authored-by: Mike <mike.hsu@gmail.com>
@alice-i-cecile alice-i-cecile requested a review from hymm March 19, 2022 20:44
examples/game/breakout.rs Outdated Show resolved Hide resolved
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

LGTM. As a beginner I would've greatly appreciated the constants so this change makes sense to me.

I think the amount of documentation on the constants is fine as is for now, because otherwise the example would be drowned in comments that don't add a lot to the example itself.

If we see users asking questions about particular constants we should add documentation to those, but they are mostly self explanatory.

examples/game/breakout.rs Outdated Show resolved Hide resolved
examples/game/breakout.rs Outdated Show resolved Hide resolved
examples/game/breakout.rs Outdated Show resolved Hide resolved
examples/game/breakout.rs Outdated Show resolved Hide resolved
Co-authored-by: KDecay <KDecayMusic@protonmail.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 Mar 19, 2022
@alice-i-cecile
Copy link
Member Author

bors r+

bors bot pushed a commit that referenced this pull request Mar 19, 2022
# Objective

- The Breakout example has a lot of configurable constant values for setup, but these are buried in the source code.
- Magic numbers scattered in the source code are hard to follow.
- Providing constants up front makes tweaking examples very approachable.

## Solution

- Move magic numbers into constants

## Context

Part of the changes made in #2094; split out for easier review.
@bors bors bot changed the title Move magic numbers into constants in Breakout example [Merged by Bors] - Move magic numbers into constants in Breakout example Mar 19, 2022
@bors bors bot closed this Mar 19, 2022
// These constants are defined in `Transform` units.
// Using the default 2D camera they correspond 1:1 with screen pixels.
// The `const_vec3!` macros are needed as functions that operate on floats cannot be constant in Rust.
const PADDLE_HEIGHT: f32 = -215.0;
Copy link
Member

Choose a reason for hiding this comment

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

the meaning of this one is not very obvious, even less with the PADDLE_SIZE just under

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I'll fix this in a follow-up PR.

bors bot pushed a commit that referenced this pull request Mar 23, 2022
# Objective

- The components in the Breakout game are defined in a strange fashion.
   - Components should decouple behavior wherever possible.
   - Systems should be as general as possible, to make extending behavior easier.
   - Marker components are idiomatic and useful, but marker components and query filters were not used.
- The existing design makes it challenging for beginners to extend the example into a high-quality game.

## Solution

- Refactor component definitions in the Breakout example to reflect principles above.

## Context

A small portion of the changes made in #2094. Interacts with changes in #4255; merge conflicts will have to be resolved.
aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
# Objective

- The Breakout example has a lot of configurable constant values for setup, but these are buried in the source code.
- Magic numbers scattered in the source code are hard to follow.
- Providing constants up front makes tweaking examples very approachable.

## Solution

- Move magic numbers into constants

## Context

Part of the changes made in bevyengine#2094; split out for easier review.
aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
…engine#4261)

# Objective

- The components in the Breakout game are defined in a strange fashion.
   - Components should decouple behavior wherever possible.
   - Systems should be as general as possible, to make extending behavior easier.
   - Marker components are idiomatic and useful, but marker components and query filters were not used.
- The existing design makes it challenging for beginners to extend the example into a high-quality game.

## Solution

- Refactor component definitions in the Breakout example to reflect principles above.

## Context

A small portion of the changes made in bevyengine#2094. Interacts with changes in bevyengine#4255; merge conflicts will have to be resolved.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- The Breakout example has a lot of configurable constant values for setup, but these are buried in the source code.
- Magic numbers scattered in the source code are hard to follow.
- Providing constants up front makes tweaking examples very approachable.

## Solution

- Move magic numbers into constants

## Context

Part of the changes made in bevyengine#2094; split out for easier review.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…engine#4261)

# Objective

- The components in the Breakout game are defined in a strange fashion.
   - Components should decouple behavior wherever possible.
   - Systems should be as general as possible, to make extending behavior easier.
   - Marker components are idiomatic and useful, but marker components and query filters were not used.
- The existing design makes it challenging for beginners to extend the example into a high-quality game.

## Solution

- Refactor component definitions in the Breakout example to reflect principles above.

## Context

A small portion of the changes made in bevyengine#2094. Interacts with changes in bevyengine#4255; merge conflicts will have to be resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Code-Quality A section of code that is hard to understand or change C-Examples An addition or correction to our examples 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.

3 participants