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] - change texture atlas sprite indexing to usize #2887

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/2d/pipelined_texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn setup(
scale: Vec3::splat(4.0),
..Default::default()
},
sprite: TextureAtlasSprite::new(vendor_index as u32),
sprite: TextureAtlasSprite::new(vendor_index),
texture_atlas: atlas_handle,
..Default::default()
});
Expand Down
5 changes: 2 additions & 3 deletions pipelined/bevy_sprite2/src/dynamic_texture_atlas_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl DynamicTextureAtlasBuilder {
texture_atlas: &mut TextureAtlas,
textures: &mut Assets<Image>,
texture: &Image,
) -> Option<u32> {
) -> Option<usize> {
let allocation = self.atlas_allocator.allocate(size2(
texture.texture_descriptor.size.width as i32 + self.padding,
texture.texture_descriptor.size.height as i32 + self.padding,
Expand All @@ -33,8 +33,7 @@ impl DynamicTextureAtlasBuilder {
let mut rect: Rect = allocation.rectangle.into();
rect.max.x -= self.padding as f32;
rect.max.y -= self.padding as f32;
texture_atlas.add_texture(rect);
Some((texture_atlas.len() - 1) as u32)
Some(texture_atlas.add_texture(rect))
} else {
None
}
Expand Down
2 changes: 1 addition & 1 deletion pipelined/bevy_sprite2/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn extract_atlases(
let mut sprites = Vec::new();
for (entity, atlas_sprite, transform, texture_atlas_handle) in atlas_query.iter() {
if let Some(texture_atlas) = texture_atlases.get(texture_atlas_handle) {
let rect = texture_atlas.textures[atlas_sprite.index as usize];
let rect = texture_atlas.textures[atlas_sprite.index];
sprites.push((
entity,
(ExtractedSprite {
Expand Down
8 changes: 5 additions & 3 deletions pipelined/bevy_sprite2/src/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct TextureAtlas {
#[uuid = "7233c597-ccfa-411f-bd59-9af349432ada"]
pub struct TextureAtlasSprite {
pub color: Color,
pub index: u32,
pub index: usize,
pub flip_x: bool,
pub flip_y: bool,
}
Expand All @@ -41,7 +41,7 @@ impl Default for TextureAtlasSprite {
}

impl TextureAtlasSprite {
pub fn new(index: u32) -> TextureAtlasSprite {
pub fn new(index: usize) -> TextureAtlasSprite {
Self {
index,
..Default::default()
Expand Down Expand Up @@ -119,13 +119,15 @@ impl TextureAtlas {
}

/// Add a sprite to the list of textures in the `TextureAtlas`
/// returns an index to the texture which can be used with `TextureAtlasSprite`
///
/// # Arguments
///
/// * `rect` - The section of the atlas that contains the texture to be added,
/// from the top-left corner of the texture to the bottom-right corner
pub fn add_texture(&mut self, rect: Rect) {
pub fn add_texture(&mut self, rect: Rect) -> usize {
self.textures.push(rect);
self.textures.len() - 1
}

/// How many textures are in the `TextureAtlas`
Expand Down