Skip to content

Add a way to cache a QueryLens #12271

Open
@hymm

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.

fn my_system(
    q: Query<(&A, &B), With<C>>, 
    // only allows transmuting a Query<((&A, &B, With<C>)> to a Query<&B>
    transmuter: Transmuter<((&A, &B), With<C>), &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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions