Skip to content

Commit

Permalink
Don't reallocate visible sprite entities map every frame
Browse files Browse the repository at this point in the history
  • Loading branch information
johanhelsing committed Jun 2, 2022
1 parent 1ddb82d commit 759c292
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ pub fn queue_sprites(
mut extracted_sprites: ResMut<ExtractedSprites>,
mut views: Query<(&VisibleEntities, &mut RenderPhase<Transparent2d>)>,
events: Res<SpriteAssetEvents>,
mut visible_entities_map: Local<HashSet<Entity>>,
) {
// If an image has changed, the GpuImage has (probably) changed
for event in &events.images {
Expand Down Expand Up @@ -403,7 +404,8 @@ pub fn queue_sprites(
let extracted_sprites = &mut extracted_sprites.sprites;
let image_bind_groups = &mut *image_bind_groups;

let visible_entities = HashSet::from_iter(visible_entities.iter().cloned());
visible_entities_map.clear();
visible_entities_map.extend(visible_entities.iter().copied());

transparent_phase.items.reserve(extracted_sprites.len());

Expand Down Expand Up @@ -433,7 +435,7 @@ pub fn queue_sprites(
// Batches are merged later (in `batch_phase_system()`), so that they can be interrupted
// by any other phase item (and they can interrupt other items from batching).
for extracted_sprite in extracted_sprites.iter() {
if !visible_entities.contains(&extracted_sprite.entity) {
if !visible_entities_map.contains(&extracted_sprite.entity) {
continue;
}
let new_batch = SpriteBatch {
Expand Down

0 comments on commit 759c292

Please sign in to comment.