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

Uncouple DynamicTextureAtlasBuilder from assets #13717

Merged
merged 1 commit into from
Jun 8, 2024

Conversation

djeedai
Copy link
Contributor

@djeedai djeedai commented Jun 6, 2024

Objective

Remove some unnecessary coupling between DynamicTextureAtlasBuilder and bevy_asset.

Solution

Remove the dependency of DynamicTextureAtlasBuilder::add_texture to bevy_asset, by directly passing the Image of the atlas to mutate, instead of passing separate Assets<Image> and Handle<Image> for the function to do the lookup by itself. The lookup can be done from the caller, and this allows using the builder in contexts where the Image is not stored inside Assets.

Clean-up a bit the font atlas files by introducing a PlacedGlyph type storing the GlyphId and its SubpixelOffset, which were otherwise always both passed as function parameters and the pair used as key in hash maps.

Testing

There's no change in behavior.


Changelog

  • Added a PlacedGlyph type aggregating a GlyphId and a SubpixelOffset. That type is now used as parameter in a few text atlas APIs, instead of passing individual values.

Migration Guide

  • Replace the glyph_id and subpixel_offset of a few text atlas APIs by a single place_glyph: PlacedGlyph parameter trivially combining the two.
  • DynamicTextureAtlasBuilder::add_texture now takes a &mut Image, rather than a Handle<Image>. To access this, fetch the underlying image using Assets<Image>::get_mut.

Remove the dependency of `DynamicTextureAtlasBuilder::add_texture` to
`bevy_asset`, by directly passing the `Image` of the atlas to mutate,
instead of passing separate `Assets<Image>` and `Handle<Image>` for the
function to do the lookup by itself. The lookup can be done from the
caller, and this allows using the builder in contexts where the `Image`
is not stored inside `Assets`.

Clean-up a bit the font atlas files by introducing a `PlacedGlyph` type
storing the `GlyphId` and its `SubpixelOffset`, which were otherwise
always both passed as function parameters and the pair used as key in
hash maps.
@djeedai djeedai added D-Trivial Nice and easy! A great choice to get started with Bevy C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Text Rendering and layout for characters labels Jun 6, 2024
@alice-i-cecile
Copy link
Member

@brandon-reinhart I'd appreciate your opinions here.

@alice-i-cecile alice-i-cecile added M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide X-Uncontroversial This work is generally agreed upon labels Jun 6, 2024
Copy link
Contributor

@rparrett rparrett left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me.

@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 Jun 8, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 8, 2024
@rparrett
Copy link
Contributor

rparrett commented Jun 8, 2024

The DynamicTextureAtlasBuilder::add_texture change should be mentioned in the migration guide.

Merged via the queue into bevyengine:main with commit d38d8a1 Jun 8, 2024
35 checks passed
@alice-i-cecile
Copy link
Member

I've updated the migration guide, but one or both of you may have suggestions on how to improve this.

@djeedai djeedai deleted the dyn-atlas branch June 8, 2024 13:01
@djeedai
Copy link
Contributor Author

djeedai commented Jun 8, 2024

Migration guide looks good to me, thanks @alice-i-cecile!

@rparrett rparrett mentioned this pull request Jun 19, 2024
rparrett added a commit to rparrett/bevy that referenced this pull request Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Text Rendering and layout for characters C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants