bevyengine / bevyengine/bevy

Enumerable iter_many that counts skipped entries

Open
#9,334 0 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

From `bevy_ui::render::extract_uinodes`:

```rust
pub fn extract_uinodes(
mut extracted_uinodes: ResMut,
images: Extract>>,
ui_stack: Extract>,
uinode_query: Extract<
Query<
(
&Node,
&GlobalTransform,
&BackgroundColor,
Option<&UiImage>,
&ComputedVisibility,
Option<&CalculatedClip>,
),
Without,
>,
>,
) {
for (stack_index, entity) in ui_stack.uinodes.iter().enumerate() {
if let Ok((uinode, transform, color, maybe_image, visibility, clip)) =
uinode_query.get(*entity)
{
// code that extracts the uinode, not relevant
};
}
}
```

Thought naively that I could replace the iter-if-let-query stuff with an enumerated `iter_many`:
```rust
for (stack_index, (uinode, transform, color, maybe_image, visibility, clip)) in uinode_query.iter_many(&ui_stack.uinodes).enumerate() {
// ..
}
```

But that doesn't work. `iter_many` skips entities that don't match the query and only the unskipped entries are counted for the enumeration.

## What solution would you like?

Some sort of `iter_many_enumerated(entity_list)` method on Query.
I made a very basic implementation but it doesn't seem very efficient: https://github.com/ickshonpe/bevy/tree/query-many-enumerated

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.