bevyengine / bevyengine/bevy

Add a way to cache a QueryLens

Open
#12,271 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?

Creating a QueryLens for a transmute or join operation requires creating the query state and checking to make sure that the new state is a valid state. It should be possible to cache some of this to skip these.

## What solution would you like?

Provide a safe wrapper around a QueryLens that allows updating the internal QueryState by passing in the updated Query(s). This would update all the variable internal state like the matched_table's and matched_archetypes's.

```rust
fn my_system(
q: Query<(&A, &B), With>,
// only allows transmuting a Query<((&A, &B, With)> to a Query<&B>
transmuter: Transmuter<((&A, &B), With), &B>) {
// Transmute the query to a Query<&B>
let new_q = transmuter.transmute(&mut q);
// ...
}
```

## What alternative(s) have you considered?

We could instead just have a method on QueryState that allows reusing the internal `State`, but still requires checking the compatibility. This would at least reduce some of the costs, but be a lot less verbose.

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.