Skip to content

Commit

Permalink
Performance tweaks and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF committed Jan 29, 2024
1 parent b940bff commit 6f415e5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/bevy_sprite/src/texture_slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ impl TextureSlice {
// Each tile expected size
let expected_size = Vec2::new(
if tile_x {
rect_size.x * stretch_value
// No slice should be less than 1 pixel wide
(rect_size.x * stretch_value).max(1.0)
} else {
self.draw_size.x
},
if tile_y {
rect_size.y * stretch_value
// No slice should be less than 1 pixel high
(rect_size.y * stretch_value).max(1.0)
} else {
self.draw_size.y
},
);
)
.min(self.draw_size);
let mut slices = Vec::new();
let base_offset = Vec2::new(
-self.draw_size.x / 2.0,
Expand Down Expand Up @@ -82,6 +85,9 @@ impl TextureSlice {
offset.y -= size_y / 2.0;
remaining_columns -= size_y;
}
if slices.len() > 1_000 {
bevy_log::warn!("One of your tiled textures has generated {} slices. You might want to use higher stretch values to avoid a great performance cost", slices.len());
}
slices
}
}

0 comments on commit 6f415e5

Please sign in to comment.