From 5dc8686753fad44beddb51405609d208c2c45b08 Mon Sep 17 00:00:00 2001 From: taizu-jin Date: Tue, 28 Nov 2023 18:44:42 +0200 Subject: [PATCH] Rename `WorldQueryFilter` to `QueryFilter` --- crates/bevy_ecs/macros/src/lib.rs | 4 +-- .../bevy_ecs/macros/src/world_query_filter.rs | 4 +-- crates/bevy_ecs/src/lib.rs | 6 ++-- crates/bevy_ecs/src/query/filter.rs | 36 +++++++++---------- crates/bevy_ecs/src/query/iter.rs | 36 +++++++++---------- crates/bevy_ecs/src/query/mod.rs | 12 +++---- crates/bevy_ecs/src/query/par_iter.rs | 6 ++-- crates/bevy_ecs/src/query/state.rs | 20 +++++------ crates/bevy_ecs/src/query/world_query.rs | 6 ++-- .../src/system/exclusive_system_param.rs | 4 +-- crates/bevy_ecs/src/system/query.rs | 20 +++++------ crates/bevy_ecs/src/system/system_param.rs | 14 ++++---- crates/bevy_ecs/src/world/mod.rs | 4 +-- crates/bevy_hierarchy/src/query_extension.rs | 20 +++++------ crates/bevy_render/src/batching/mod.rs | 4 +-- crates/bevy_render/src/extract_component.rs | 4 +-- crates/bevy_render/src/extract_instances.rs | 4 +-- examples/ecs/custom_query_param.rs | 18 ++++++---- 18 files changed, 111 insertions(+), 111 deletions(-) diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index f02cfd8cb23f41..02f8d91114dd20 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -456,8 +456,8 @@ pub fn derive_world_query_data(input: TokenStream) -> TokenStream { derive_world_query_data_impl(input) } -/// Implement `WorldQueryFilter` to use a struct as a filter parameter in a query -#[proc_macro_derive(WorldQueryFilter, attributes(world_query_filter))] +/// Implement `QueryFilter` to use a struct as a filter parameter in a query +#[proc_macro_derive(QueryFilter, attributes(query_filter))] pub fn derive_world_query_filter(input: TokenStream) -> TokenStream { derive_world_query_filter_impl(input) } diff --git a/crates/bevy_ecs/macros/src/world_query_filter.rs b/crates/bevy_ecs/macros/src/world_query_filter.rs index b10cac09a06c56..49488457645fbf 100644 --- a/crates/bevy_ecs/macros/src/world_query_filter.rs +++ b/crates/bevy_ecs/macros/src/world_query_filter.rs @@ -120,7 +120,7 @@ pub fn derive_world_query_filter_impl(input: TokenStream) -> TokenStream { ); let filter_impl = quote! { - impl #user_impl_generics #path::query::WorldQueryFilter + impl #user_impl_generics #path::query::QueryFilter for #struct_name #user_ty_generics #user_where_clauses { const IS_ARCHETYPAL: bool = true #(&& <#field_types>::IS_ARCHETYPAL)*; @@ -163,7 +163,7 @@ pub fn derive_world_query_filter_impl(input: TokenStream) -> TokenStream { fn assert_filter() where - T: #path::query::WorldQueryFilter, + T: #path::query::QueryFilter, { } diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 69ce32e8a88063..5e00f1c1a8c7f6 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -64,7 +64,7 @@ mod tests { change_detection::Ref, component::{Component, ComponentId}, entity::Entity, - query::{Added, Changed, FilteredAccess, With, Without, WorldQueryFilter}, + query::{Added, Changed, FilteredAccess, QueryFilter, With, Without}, system::Resource, world::{EntityRef, Mut, World}, }; @@ -903,7 +903,7 @@ mod tests { } } - fn get_filtered(world: &mut World) -> Vec { + fn get_filtered(world: &mut World) -> Vec { world .query_filtered::() .iter(world) @@ -986,7 +986,7 @@ mod tests { } } - fn get_filtered(world: &mut World) -> Vec { + fn get_filtered(world: &mut World) -> Vec { world .query_filtered::() .iter(world) diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index a02f9f703a91cc..9af7b0b1aee334 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -17,29 +17,29 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// [`With`] and [`Without`] filters can be applied to check if the queried entity does or does not contain a particular component. /// - **Change detection filters.** /// [`Added`] and [`Changed`] filters can be applied to detect component changes to an entity. -/// - **`WorldQueryFilter` tuples.** -/// If every element of a tuple implements `WorldQueryFilter`, then the tuple itself also implements the same trait. +/// - **`QueryFilter` tuples.** +/// If every element of a tuple implements `QueryFilter`, then the tuple itself also implements the same trait. /// This enables a single `Query` to filter over multiple conditions. /// Due to the current lack of variadic generics in Rust, the trait has been implemented for tuples from 0 to 15 elements, -/// but nesting of tuples allows infinite `WorldQueryFilter`s. +/// but nesting of tuples allows infinite `QueryFilter`s. /// - **Filter disjunction operator.** /// By default, tuples compose query filters in such a way that all conditions must be satisfied to generate a query item for a given entity. /// Wrapping a tuple inside an [`Or`] operator will relax the requirement to just one condition. /// /// Implementing the trait manually can allow for a fundamentally new type of behavior. /// -/// Query design can be easily structured by deriving `WorldQueryFilter` for custom types. -/// Despite the added complexity, this approach has several advantages over using `WorldQueryFilter` tuples. +/// Query design can be easily structured by deriving `QueryFilter` for custom types. +/// Despite the added complexity, this approach has several advantages over using `QueryFilter` tuples. /// The most relevant improvements are: /// /// - Reusability across multiple systems. /// - Filters can be composed together to create a more complex filter. /// -/// This trait can only be derived for structs if each field also implements `WorldQueryFilter`. +/// This trait can only be derived for structs if each field also implements `QueryFilter`. /// /// ``` /// # use bevy_ecs::prelude::*; -/// # use bevy_ecs::{query::WorldQueryFilter, component::Component}; +/// # use bevy_ecs::{query::QueryFilter, component::Component}; /// # /// # #[derive(Component)] /// # struct ComponentA; @@ -52,7 +52,7 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// # #[derive(Component)] /// # struct ComponentE; /// # -/// #[derive(WorldQueryFilter)] +/// #[derive(QueryFilter)] /// struct MyFilter { /// // Field names are not relevant, since they are never manually accessed. /// with_a: With, @@ -77,7 +77,7 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// [`With`]: crate::query::With /// [`Without`]: crate::query::Without -pub trait WorldQueryFilter: WorldQuery { +pub trait QueryFilter: WorldQuery { /// Returns true if (and only if) this Filter relies strictly on archetypes to limit which /// components are accessed by the Query. /// @@ -199,7 +199,7 @@ unsafe impl WorldQuery for With { } } -impl WorldQueryFilter for With { +impl QueryFilter for With { const IS_ARCHETYPAL: bool = true; #[inline(always)] @@ -311,7 +311,7 @@ unsafe impl WorldQuery for Without { } } -impl WorldQueryFilter for Without { +impl QueryFilter for Without { const IS_ARCHETYPAL: bool = true; #[inline(always)] @@ -381,7 +381,7 @@ macro_rules! impl_query_filter_tuple { /// This is sound because `update_component_access` and `update_archetype_component_access` adds accesses according to the implementations of all the subqueries. /// `update_component_access` replace the filters with a disjunction where every element is a conjunction of the previous filters and the filters of one of the subqueries. /// This is sound because `matches_component_set` returns a disjunction of the results of the subqueries' implementations. - unsafe impl<$($filter: WorldQueryFilter),*> WorldQuery for Or<($($filter,)*)> { + unsafe impl<$($filter: QueryFilter),*> WorldQuery for Or<($($filter,)*)> { type Fetch<'w> = ($(OrFetch<'w, $filter>,)*); type Item<'w> = bool; type State = ($($filter::State,)*); @@ -475,7 +475,7 @@ macro_rules! impl_query_filter_tuple { } } - impl<$($filter: WorldQueryFilter),*> WorldQueryFilter for Or<($($filter,)*)> { + impl<$($filter: QueryFilter),*> QueryFilter for Or<($($filter,)*)> { const IS_ARCHETYPAL: bool = true $(&& $filter::IS_ARCHETYPAL)*; #[inline(always)] @@ -496,7 +496,7 @@ macro_rules! impl_tuple_world_query_filter { #[allow(non_snake_case)] #[allow(clippy::unused_unit)] - impl<$($name: WorldQueryFilter),*> WorldQueryFilter for ($($name,)*) { + impl<$($name: QueryFilter),*> QueryFilter for ($($name,)*) { const IS_ARCHETYPAL: bool = true $(&& $name::IS_ARCHETYPAL)*; #[inline(always)] @@ -674,7 +674,7 @@ unsafe impl WorldQuery for Added { } } -impl WorldQueryFilter for Added { +impl QueryFilter for Added { const IS_ARCHETYPAL: bool = false; #[inline(always)] unsafe fn filter_fetch( @@ -850,7 +850,7 @@ unsafe impl WorldQuery for Changed { } } -impl WorldQueryFilter for Changed { +impl QueryFilter for Changed { const IS_ARCHETYPAL: bool = false; #[inline(always)] @@ -868,14 +868,14 @@ impl WorldQueryFilter for Changed { /// This is needed to implement [`ExactSizeIterator`] for /// [`QueryIter`](crate::query::QueryIter) that contains archetype-level filters. /// -/// The trait must only be implemented for filters where its corresponding [`WorldQueryFilter::IS_ARCHETYPAL`] +/// The trait must only be implemented for filters where its corresponding [`QueryFilter::IS_ARCHETYPAL`] /// is [`prim@true`]. As such, only the [`With`] and [`Without`] filters can implement the trait. /// [Tuples](prim@tuple) and [`Or`] filters are automatically implemented with the trait only if its containing types /// also implement the same trait. /// /// [`Added`] and [`Changed`] works with entities, and therefore are not archetypal. As such /// they do not implement [`ArchetypeFilter`]. -pub trait ArchetypeFilter: WorldQueryFilter {} +pub trait ArchetypeFilter: QueryFilter {} impl ArchetypeFilter for With {} impl ArchetypeFilter for Without {} diff --git a/crates/bevy_ecs/src/query/iter.rs b/crates/bevy_ecs/src/query/iter.rs index e9dd5a92c1de21..86f77f3fd493f8 100644 --- a/crates/bevy_ecs/src/query/iter.rs +++ b/crates/bevy_ecs/src/query/iter.rs @@ -8,20 +8,20 @@ use crate::{ }; use std::{borrow::Borrow, iter::FusedIterator, mem::MaybeUninit}; -use super::{QueryData, ReadOnlyQueryData, WorldQueryFilter}; +use super::{QueryData, QueryFilter, ReadOnlyQueryData}; /// An [`Iterator`] over query results of a [`Query`](crate::system::Query). /// /// This struct is created by the [`Query::iter`](crate::system::Query::iter) and /// [`Query::iter_mut`](crate::system::Query::iter_mut) methods. -pub struct QueryIter<'w, 's, Q: QueryData, F: WorldQueryFilter> { +pub struct QueryIter<'w, 's, Q: QueryData, F: QueryFilter> { tables: &'w Tables, archetypes: &'w Archetypes, query_state: &'s QueryState, cursor: QueryIterationCursor<'w, 's, Q, F>, } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> QueryIter<'w, 's, Q, F> { +impl<'w, 's, Q: QueryData, F: QueryFilter> QueryIter<'w, 's, Q, F> { /// # Safety /// - `world` must have permission to access any of the components registered in `query_state`. /// - `world` must be the same one used to initialize `query_state`. @@ -41,7 +41,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> QueryIter<'w, 's, Q, F> { } } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> Iterator for QueryIter<'w, 's, Q, F> { +impl<'w, 's, Q: QueryData, F: QueryFilter> Iterator for QueryIter<'w, 's, Q, F> { type Item = Q::Item<'w>; #[inline(always)] @@ -64,7 +64,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> Iterator for QueryIter<'w, 's, Q } // This is correct as [`QueryIter`] always returns `None` once exhausted. -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> FusedIterator for QueryIter<'w, 's, Q, F> {} +impl<'w, 's, Q: QueryData, F: QueryFilter> FusedIterator for QueryIter<'w, 's, Q, F> {} /// An [`Iterator`] over the query items generated from an iterator of [`Entity`]s. /// @@ -72,7 +72,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> FusedIterator for QueryIter<'w, /// Entities that don't match the query are skipped. /// /// This struct is created by the [`Query::iter_many`](crate::system::Query::iter_many) and [`Query::iter_many_mut`](crate::system::Query::iter_many_mut) methods. -pub struct QueryManyIter<'w, 's, Q: QueryData, F: WorldQueryFilter, I: Iterator> +pub struct QueryManyIter<'w, 's, Q: QueryData, F: QueryFilter, I: Iterator> where I::Item: Borrow, { @@ -85,7 +85,7 @@ where query_state: &'s QueryState, } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter, I: Iterator> QueryManyIter<'w, 's, Q, F, I> +impl<'w, 's, Q: QueryData, F: QueryFilter, I: Iterator> QueryManyIter<'w, 's, Q, F, I> where I::Item: Borrow, { @@ -181,7 +181,7 @@ where } } -impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, I: Iterator> Iterator +impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter, I: Iterator> Iterator for QueryManyIter<'w, 's, Q, F, I> where I::Item: Borrow, @@ -201,7 +201,7 @@ where } // This is correct as [`QueryManyIter`] always returns `None` once exhausted. -impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, I: Iterator> FusedIterator +impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter, I: Iterator> FusedIterator for QueryManyIter<'w, 's, Q, F, I> where I::Item: Borrow, @@ -271,16 +271,14 @@ where /// [`Query`]: crate::system::Query /// [`Query::iter_combinations`]: crate::system::Query::iter_combinations /// [`Query::iter_combinations_mut`]: crate::system::Query::iter_combinations_mut -pub struct QueryCombinationIter<'w, 's, Q: QueryData, F: WorldQueryFilter, const K: usize> { +pub struct QueryCombinationIter<'w, 's, Q: QueryData, F: QueryFilter, const K: usize> { tables: &'w Tables, archetypes: &'w Archetypes, query_state: &'s QueryState, cursors: [QueryIterationCursor<'w, 's, Q, F>; K], } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter, const K: usize> - QueryCombinationIter<'w, 's, Q, F, K> -{ +impl<'w, 's, Q: QueryData, F: QueryFilter, const K: usize> QueryCombinationIter<'w, 's, Q, F, K> { /// # Safety /// - `world` must have permission to access any of the components registered in `query_state`. /// - `world` must be the same one used to initialize `query_state`. @@ -385,7 +383,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter, const K: usize> // Iterator type is intentionally implemented only for read-only access. // Doing so for mutable references would be unsound, because calling `next` // multiple times would allow multiple owned references to the same data to exist. -impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, const K: usize> Iterator +impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter, const K: usize> Iterator for QueryCombinationIter<'w, 's, Q, F, K> { type Item = [Q::Item<'w>; K]; @@ -428,7 +426,7 @@ impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, const K: usize> Iterator } } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> ExactSizeIterator for QueryIter<'w, 's, Q, F> +impl<'w, 's, Q: QueryData, F: QueryFilter> ExactSizeIterator for QueryIter<'w, 's, Q, F> where F: ArchetypeFilter, { @@ -438,12 +436,12 @@ where } // This is correct as [`QueryCombinationIter`] always returns `None` once exhausted. -impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, const K: usize> FusedIterator +impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter, const K: usize> FusedIterator for QueryCombinationIter<'w, 's, Q, F, K> { } -struct QueryIterationCursor<'w, 's, Q: QueryData, F: WorldQueryFilter> { +struct QueryIterationCursor<'w, 's, Q: QueryData, F: QueryFilter> { table_id_iter: std::slice::Iter<'s, TableId>, archetype_id_iter: std::slice::Iter<'s, ArchetypeId>, table_entities: &'w [Entity], @@ -456,7 +454,7 @@ struct QueryIterationCursor<'w, 's, Q: QueryData, F: WorldQueryFilter> { current_row: usize, } -impl Clone for QueryIterationCursor<'_, '_, Q, F> { +impl Clone for QueryIterationCursor<'_, '_, Q, F> { fn clone(&self) -> Self { Self { table_id_iter: self.table_id_iter.clone(), @@ -471,7 +469,7 @@ impl Clone for QueryIterationCursor<'_, '_, Q } } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> QueryIterationCursor<'w, 's, Q, F> { +impl<'w, 's, Q: QueryData, F: QueryFilter> QueryIterationCursor<'w, 's, Q, F> { const IS_DENSE: bool = Q::IS_DENSE && F::IS_DENSE; unsafe fn init_empty( diff --git a/crates/bevy_ecs/src/query/mod.rs b/crates/bevy_ecs/src/query/mod.rs index 19c4d5e64a6c61..7d7c74c2c6740e 100644 --- a/crates/bevy_ecs/src/query/mod.rs +++ b/crates/bevy_ecs/src/query/mod.rs @@ -10,7 +10,7 @@ mod state; mod world_query; pub use access::*; -pub use bevy_ecs_macros::{QueryData, WorldQueryFilter}; +pub use bevy_ecs_macros::{QueryData, QueryFilter}; pub use error::*; pub use fetch::*; pub use filter::*; @@ -67,7 +67,7 @@ impl DebugCheckedUnwrap for Option { #[cfg(test)] mod tests { - use bevy_ecs_macros::{QueryData, WorldQueryFilter}; + use bevy_ecs_macros::{QueryData, QueryFilter}; use crate::prelude::{AnyOf, Changed, Entity, Or, QueryState, With, Without}; use crate::query::{ArchetypeFilter, Has, QueryCombinationIter, ReadOnlyQueryData}; @@ -618,11 +618,11 @@ mod tests { } { - #[derive(WorldQueryFilter)] + #[derive(QueryFilter)] struct AOrBFilter { a: Or<(With, With)>, } - #[derive(WorldQueryFilter)] + #[derive(QueryFilter)] struct NoSparseThatsSlow { no: Without, } @@ -639,7 +639,7 @@ mod tests { } { - #[derive(WorldQueryFilter)] + #[derive(QueryFilter)] struct CSparseFilter { tuple_structs_pls: With, ugh: With, @@ -657,7 +657,7 @@ mod tests { } { - #[derive(WorldQueryFilter)] + #[derive(QueryFilter)] struct WithoutComps { _1: Without, _2: Without, diff --git a/crates/bevy_ecs/src/query/par_iter.rs b/crates/bevy_ecs/src/query/par_iter.rs index 4c2bc4ce64bad7..05c76787b39b03 100644 --- a/crates/bevy_ecs/src/query/par_iter.rs +++ b/crates/bevy_ecs/src/query/par_iter.rs @@ -1,7 +1,7 @@ use crate::{component::Tick, world::unsafe_world_cell::UnsafeWorldCell}; use std::ops::Range; -use super::{QueryData, QueryItem, QueryState, WorldQueryFilter}; +use super::{QueryData, QueryFilter, QueryItem, QueryState}; /// Dictates how a parallel query chunks up large tables/archetypes /// during iteration. @@ -82,7 +82,7 @@ impl BatchingStrategy { /// /// This struct is created by the [`Query::par_iter`](crate::system::Query::par_iter) and /// [`Query::par_iter_mut`](crate::system::Query::par_iter_mut) methods. -pub struct QueryParIter<'w, 's, Q: QueryData, F: WorldQueryFilter> { +pub struct QueryParIter<'w, 's, Q: QueryData, F: QueryFilter> { pub(crate) world: UnsafeWorldCell<'w>, pub(crate) state: &'s QueryState, pub(crate) last_run: Tick, @@ -90,7 +90,7 @@ pub struct QueryParIter<'w, 's, Q: QueryData, F: WorldQueryFilter> { pub(crate) batching_strategy: BatchingStrategy, } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> QueryParIter<'w, 's, Q, F> { +impl<'w, 's, Q: QueryData, F: QueryFilter> QueryParIter<'w, 's, Q, F> { /// Changes the batching strategy used when iterating. /// /// For more information on how this affects the resultant iteration, see diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index a282b67843c9b1..82e28a43f9453b 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -17,16 +17,16 @@ use fixedbitset::FixedBitSet; use std::{any::TypeId, borrow::Borrow, fmt, mem::MaybeUninit}; use super::{ - NopWorldQuery, QueryComponentError, QueryData, QueryEntityError, QueryManyIter, - QuerySingleError, ROQueryItem, WorldQueryFilter, + NopWorldQuery, QueryComponentError, QueryData, QueryEntityError, QueryFilter, QueryManyIter, + QuerySingleError, ROQueryItem, }; -/// Provides scoped access to a [`World`] state according to a given [`QueryData`] and [`WorldQueryFilter`]. +/// Provides scoped access to a [`World`] state according to a given [`QueryData`] and [`QueryFilter`]. #[repr(C)] // SAFETY NOTE: // Do not add any new fields that use the `Q` or `F` generic parameters as this may // make `QueryState::as_transmuted_state` unsound if not done with care. -pub struct QueryState { +pub struct QueryState { world_id: WorldId, pub(crate) archetype_generation: ArchetypeGeneration, pub(crate) matched_tables: FixedBitSet, @@ -43,7 +43,7 @@ pub struct QueryState { par_iter_span: Span, } -impl std::fmt::Debug for QueryState { +impl std::fmt::Debug for QueryState { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("QueryState") .field("world_id", &self.world_id) @@ -53,13 +53,13 @@ impl std::fmt::Debug for QueryState { } } -impl FromWorld for QueryState { +impl FromWorld for QueryState { fn from_world(world: &mut World) -> Self { world.query_filtered() } } -impl QueryState { +impl QueryState { /// Converts this `QueryState` reference to a `QueryState` that does not access anything mutably. pub fn as_readonly(&self) -> &QueryState { // SAFETY: invariant on `WorldQuery` trait upholds that `Q::ReadOnly` and `F::ReadOnly` @@ -89,7 +89,7 @@ impl QueryState { /// `NewF` must have a subset of the access that `F` does and match the exact same archetypes/tables pub(crate) unsafe fn as_transmuted_state< NewQ: QueryData, - NewF: WorldQueryFilter, + NewF: QueryFilter, >( &self, ) -> &QueryState { @@ -97,7 +97,7 @@ impl QueryState { } } -impl QueryState { +impl QueryState { /// Creates a new [`QueryState`] from a given [`World`] and inherits the result of `world.id()`. pub fn new(world: &mut World) -> Self { let fetch_state = Q::init_state(world); @@ -162,7 +162,7 @@ impl QueryState { /// /// # Safety /// - /// - `world` must have permission to read any components required by this instance's `F` [`WorldQueryFilter`]. + /// - `world` must have permission to read any components required by this instance's `F` [`QueryFilter`]. /// - `world` must match the one used to create this [`QueryState`]. #[inline] pub(crate) unsafe fn is_empty_unsafe_world_cell( diff --git a/crates/bevy_ecs/src/query/world_query.rs b/crates/bevy_ecs/src/query/world_query.rs index 113a9e3874bd45..f2f9d0892d412b 100644 --- a/crates/bevy_ecs/src/query/world_query.rs +++ b/crates/bevy_ecs/src/query/world_query.rs @@ -9,7 +9,7 @@ use crate::{ use bevy_utils::all_tuples; /// Types that can be used as parameters in a [`Query`]. -/// Types that implement this should also implement either [`QueryData`] or [`WorldQueryFilter`] +/// Types that implement this should also implement either [`QueryData`] or [`QueryFilter`] /// /// # Safety /// @@ -37,11 +37,11 @@ use bevy_utils::all_tuples; /// [`update_archetype_component_access`]: Self::update_archetype_component_access /// [`update_component_access`]: Self::update_component_access /// [`QueryData`]: crate::query::QueryData -/// [`WorldQueryFilter`]: crate::query::WorldQueryFilter +/// [`QueryFilter`]: crate::query::QueryFilter pub unsafe trait WorldQuery { /// The item returned by this [`WorldQuery`] /// For `QueryData` this will be the item returned by the query. - /// For `WorldQueryFilter` this will be either `()`, or a `bool` indicating whether the entity should be included + /// For `QueryFilter` this will be either `()`, or a `bool` indicating whether the entity should be included /// or a tuple of such things. type Item<'a>; diff --git a/crates/bevy_ecs/src/system/exclusive_system_param.rs b/crates/bevy_ecs/src/system/exclusive_system_param.rs index 87976c029f1b87..759c8ab5473909 100644 --- a/crates/bevy_ecs/src/system/exclusive_system_param.rs +++ b/crates/bevy_ecs/src/system/exclusive_system_param.rs @@ -1,6 +1,6 @@ use crate::{ prelude::{FromWorld, QueryState}, - query::{QueryData, WorldQueryFilter}, + query::{QueryData, QueryFilter}, system::{Local, SystemMeta, SystemParam, SystemState}, world::World, }; @@ -29,7 +29,7 @@ pub trait ExclusiveSystemParam: Sized { /// for a given [`ExclusiveSystemParam`]. pub type ExclusiveSystemParamItem<'s, P> =

::Item<'s>; -impl<'a, Q: QueryData + 'static, F: WorldQueryFilter + 'static> ExclusiveSystemParam +impl<'a, Q: QueryData + 'static, F: QueryFilter + 'static> ExclusiveSystemParam for &'a mut QueryState { type State = QueryState; diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index 7a5c178b0e7476..ec0db16e5db309 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -3,8 +3,8 @@ use crate::{ entity::Entity, query::{ BatchingStrategy, QueryCombinationIter, QueryComponentError, QueryData, QueryEntityError, - QueryIter, QueryManyIter, QueryParIter, QuerySingleError, QueryState, ROQueryItem, - ReadOnlyQueryData, WorldQueryFilter, + QueryFilter, QueryIter, QueryManyIter, QueryParIter, QuerySingleError, QueryState, + ROQueryItem, ReadOnlyQueryData, }, world::{unsafe_world_cell::UnsafeWorldCell, Mut}, }; @@ -24,7 +24,7 @@ use std::{any::TypeId, borrow::Borrow}; /// Must implement the [`QueryData`] trait. /// - **`F` (query filter).** /// A set of conditions that determines whether query items should be kept or discarded. -/// Must implement the [`WorldQueryFilter`] trait. +/// Must implement the [`QueryFilter`] trait. /// This type parameter is optional. /// /// [`World`]: crate::world::World @@ -73,7 +73,7 @@ use std::{any::TypeId, borrow::Borrow}; /// # bevy_ecs::system::assert_is_system(system); /// ``` /// -/// ## `QueryData` or `WorldQueryFilter` tuples +/// ## `QueryData` or `QueryFilter` tuples /// /// Using tuples, each `Query` type parameter can contain multiple elements. /// @@ -325,7 +325,7 @@ use std::{any::TypeId, borrow::Borrow}; /// [`Table`]: crate::storage::Table /// [`With`]: crate::query::With /// [`Without`]: crate::query::Without -pub struct Query<'world, 'state, Q: QueryData, F: WorldQueryFilter = ()> { +pub struct Query<'world, 'state, Q: QueryData, F: QueryFilter = ()> { // SAFETY: Must have access to the components registered in `state`. world: UnsafeWorldCell<'world>, state: &'state QueryState, @@ -339,7 +339,7 @@ pub struct Query<'world, 'state, Q: QueryData, F: WorldQueryFilter = ()> { force_read_only_component_access: bool, } -impl std::fmt::Debug for Query<'_, '_, Q, F> { +impl std::fmt::Debug for Query<'_, '_, Q, F> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { f.debug_struct("Query") .field("matched_entities", &self.iter().count()) @@ -351,7 +351,7 @@ impl std::fmt::Debug for Query<'_, '_, Q, F> } } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> Query<'w, 's, Q, F> { +impl<'w, 's, Q: QueryData, F: QueryFilter> Query<'w, 's, Q, F> { /// Creates a new query. /// /// # Panics @@ -1422,7 +1422,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> Query<'w, 's, Q, F> { } } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> IntoIterator for &'w Query<'_, 's, Q, F> { +impl<'w, 's, Q: QueryData, F: QueryFilter> IntoIterator for &'w Query<'_, 's, Q, F> { type Item = ROQueryItem<'w, Q>; type IntoIter = QueryIter<'w, 's, Q::ReadOnly, F>; @@ -1431,7 +1431,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> IntoIterator for &'w Query<'_, ' } } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> IntoIterator for &'w mut Query<'_, 's, Q, F> { +impl<'w, 's, Q: QueryData, F: QueryFilter> IntoIterator for &'w mut Query<'_, 's, Q, F> { type Item = Q::Item<'w>; type IntoIter = QueryIter<'w, 's, Q, F>; @@ -1440,7 +1440,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> IntoIterator for &'w mut Query<' } } -impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter> Query<'w, 's, Q, F> { +impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter> Query<'w, 's, Q, F> { /// Returns the query item for the given [`Entity`], with the actual "inner" world lifetime. /// /// In case of a nonexisting entity or mismatched component, a [`QueryEntityError`] is diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 595bbb06766f78..15ca066b59ba82 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -6,8 +6,8 @@ use crate::{ component::{ComponentId, ComponentTicks, Components, Tick}, entity::Entities, query::{ - Access, FilteredAccess, FilteredAccessSet, QueryData, QueryState, ReadOnlyQueryData, - WorldQueryFilter, + Access, FilteredAccess, FilteredAccessSet, QueryData, QueryFilter, QueryState, + ReadOnlyQueryData, }, system::{Query, SystemMeta}, world::{unsafe_world_cell::UnsafeWorldCell, FromWorld, World}, @@ -153,16 +153,14 @@ pub unsafe trait ReadOnlySystemParam: SystemParam {} pub type SystemParamItem<'w, 's, P> =

::Item<'w, 's>; // SAFETY: QueryState is constrained to read-only fetches, so it only reads World. -unsafe impl<'w, 's, Q: ReadOnlyQueryData + 'static, F: WorldQueryFilter + 'static> - ReadOnlySystemParam for Query<'w, 's, Q, F> +unsafe impl<'w, 's, Q: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam + for Query<'w, 's, Q, F> { } // SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If // this Query conflicts with any prior access, a panic will occur. -unsafe impl SystemParam - for Query<'_, '_, Q, F> -{ +unsafe impl SystemParam for Query<'_, '_, Q, F> { type State = QueryState; type Item<'w, 's> = Query<'w, 's, Q, F>; @@ -1570,7 +1568,7 @@ mod tests { 'w, 's, Q: QueryData + Send + Sync + 'static, - F: WorldQueryFilter + Send + Sync + 'static = (), + F: QueryFilter + Send + Sync + 'static = (), > { _query: Query<'w, 's, Q, F>, } diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 3d364cc0cc24a6..36744dc01789fd 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -18,7 +18,7 @@ use crate::{ component::{Component, ComponentDescriptor, ComponentId, ComponentInfo, Components, Tick}, entity::{AllocAtWithoutReplacement, Entities, Entity, EntityLocation}, event::{Event, EventId, Events, SendBatchIds}, - query::{DebugCheckedUnwrap, QueryData, QueryEntityError, QueryState, WorldQueryFilter}, + query::{DebugCheckedUnwrap, QueryData, QueryEntityError, QueryFilter, QueryState}, removal_detection::RemovedComponentEvents, schedule::{Schedule, ScheduleLabel, Schedules}, storage::{ResourceData, Storages}, @@ -1009,7 +1009,7 @@ impl World { /// assert_eq!(matching_entities, vec![e2]); /// ``` #[inline] - pub fn query_filtered(&mut self) -> QueryState { + pub fn query_filtered(&mut self) -> QueryState { QueryState::new(self) } diff --git a/crates/bevy_hierarchy/src/query_extension.rs b/crates/bevy_hierarchy/src/query_extension.rs index 43ab27434c4e1f..fdf8cd4e7936b0 100644 --- a/crates/bevy_hierarchy/src/query_extension.rs +++ b/crates/bevy_hierarchy/src/query_extension.rs @@ -2,14 +2,14 @@ use std::collections::VecDeque; use bevy_ecs::{ entity::Entity, - query::{QueryData, WorldQuery, WorldQueryFilter}, + query::{QueryData, QueryFilter, WorldQuery}, system::Query, }; use crate::{Children, Parent}; /// An extension trait for [`Query`] that adds hierarchy related methods. -pub trait HierarchyQueryExt<'w, 's, Q: QueryData, F: WorldQueryFilter> { +pub trait HierarchyQueryExt<'w, 's, Q: QueryData, F: QueryFilter> { /// Returns an [`Iterator`] of [`Entity`]s over all of `entity`s descendants. /// /// Can only be called on a [`Query`] of [`Children`] (i.e. `Query<&Children>`). @@ -57,9 +57,7 @@ pub trait HierarchyQueryExt<'w, 's, Q: QueryData, F: WorldQueryFilter> { Q::ReadOnly: WorldQuery = &'w Parent>; } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> HierarchyQueryExt<'w, 's, Q, F> - for Query<'w, 's, Q, F> -{ +impl<'w, 's, Q: QueryData, F: QueryFilter> HierarchyQueryExt<'w, 's, Q, F> for Query<'w, 's, Q, F> { fn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, Q, F> where Q::ReadOnly: WorldQuery = &'w Children>, @@ -78,7 +76,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> HierarchyQueryExt<'w, 's, Q, F> /// An [`Iterator`] of [`Entity`]s over the descendants of an [`Entity`]. /// /// Traverses the hierarchy breadth-first. -pub struct DescendantIter<'w, 's, Q: QueryData, F: WorldQueryFilter> +pub struct DescendantIter<'w, 's, Q: QueryData, F: QueryFilter> where Q::ReadOnly: WorldQuery = &'w Children>, { @@ -86,7 +84,7 @@ where vecdeque: VecDeque, } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> DescendantIter<'w, 's, Q, F> +impl<'w, 's, Q: QueryData, F: QueryFilter> DescendantIter<'w, 's, Q, F> where Q::ReadOnly: WorldQuery = &'w Children>, { @@ -104,7 +102,7 @@ where } } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> Iterator for DescendantIter<'w, 's, Q, F> +impl<'w, 's, Q: QueryData, F: QueryFilter> Iterator for DescendantIter<'w, 's, Q, F> where Q::ReadOnly: WorldQuery = &'w Children>, { @@ -122,7 +120,7 @@ where } /// An [`Iterator`] of [`Entity`]s over the ancestors of an [`Entity`]. -pub struct AncestorIter<'w, 's, Q: QueryData, F: WorldQueryFilter> +pub struct AncestorIter<'w, 's, Q: QueryData, F: QueryFilter> where Q::ReadOnly: WorldQuery = &'w Parent>, { @@ -130,7 +128,7 @@ where next: Option, } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> AncestorIter<'w, 's, Q, F> +impl<'w, 's, Q: QueryData, F: QueryFilter> AncestorIter<'w, 's, Q, F> where Q::ReadOnly: WorldQuery = &'w Parent>, { @@ -143,7 +141,7 @@ where } } -impl<'w, 's, Q: QueryData, F: WorldQueryFilter> Iterator for AncestorIter<'w, 's, Q, F> +impl<'w, 's, Q: QueryData, F: QueryFilter> Iterator for AncestorIter<'w, 's, Q, F> where Q::ReadOnly: WorldQuery = &'w Parent>, { diff --git a/crates/bevy_render/src/batching/mod.rs b/crates/bevy_render/src/batching/mod.rs index 0b4be6587be36a..70807443c7f9ed 100644 --- a/crates/bevy_render/src/batching/mod.rs +++ b/crates/bevy_render/src/batching/mod.rs @@ -1,7 +1,7 @@ use bevy_ecs::{ component::Component, prelude::Res, - query::{QueryItem, ReadOnlyQueryData, WorldQueryFilter}, + query::{QueryFilter, QueryItem, ReadOnlyQueryData}, system::{Query, ResMut, StaticSystemParam, SystemParam, SystemParamItem}, }; use bevy_utils::nonmax::NonMaxU32; @@ -58,7 +58,7 @@ impl BatchMeta { pub trait GetBatchData { type Param: SystemParam + 'static; type Query: ReadOnlyQueryData; - type QueryFilter: WorldQueryFilter; + type QueryFilter: QueryFilter; /// Data used for comparison between phase items. If the pipeline id, draw /// function id, per-instance data buffer dynamic offset and this data /// matches, the draws can be batched. diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_render/src/extract_component.rs index f3c2420f22210d..b45d18c143eec0 100644 --- a/crates/bevy_render/src/extract_component.rs +++ b/crates/bevy_render/src/extract_component.rs @@ -9,7 +9,7 @@ use bevy_asset::{Asset, Handle}; use bevy_ecs::{ component::Component, prelude::*, - query::{QueryItem, ReadOnlyQueryData, WorldQueryFilter}, + query::{QueryFilter, QueryItem, ReadOnlyQueryData}, system::lifetimeless::Read, }; use std::{marker::PhantomData, ops::Deref}; @@ -38,7 +38,7 @@ pub trait ExtractComponent: Component { /// ECS [`ReadOnlyQueryData`] to fetch the components to extract. type Query: ReadOnlyQueryData; /// Filters the entities with additional constraints. - type Filter: WorldQueryFilter; + type Filter: QueryFilter; /// The output from extraction. /// diff --git a/crates/bevy_render/src/extract_instances.rs b/crates/bevy_render/src/extract_instances.rs index d3d424e9b4574c..4321a98b279127 100644 --- a/crates/bevy_render/src/extract_instances.rs +++ b/crates/bevy_render/src/extract_instances.rs @@ -11,7 +11,7 @@ use bevy_asset::{Asset, AssetId, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ prelude::Entity, - query::{QueryItem, ReadOnlyQueryData, WorldQueryFilter}, + query::{QueryFilter, QueryItem, ReadOnlyQueryData}, system::{lifetimeless::Read, Query, ResMut, Resource}, }; use bevy_utils::EntityHashMap; @@ -31,7 +31,7 @@ pub trait ExtractInstance: Send + Sync + Sized + 'static { /// ECS [`ReadOnlyQueryData`] to fetch the components to extract. type Query: ReadOnlyQueryData; /// Filters the entities with additional constraints. - type Filter: WorldQueryFilter; + type Filter: QueryFilter; /// Defines how the component is transferred into the "render world". fn extract(item: QueryItem<'_, Self::Query>) -> Option; diff --git a/examples/ecs/custom_query_param.rs b/examples/ecs/custom_query_param.rs index a60dbbae90d369..4df666bf337e5f 100644 --- a/examples/ecs/custom_query_param.rs +++ b/examples/ecs/custom_query_param.rs @@ -13,7 +13,7 @@ //! For more details on the `WorldQuery` derive macro, see the trait documentation. use bevy::{ - ecs::query::{QueryData, WorldQueryFilter}, + ecs::query::{QueryData, QueryFilter}, prelude::*, }; use std::fmt::Debug; @@ -59,7 +59,10 @@ struct ReadOnlyCustomQuery { } fn print_components_read_only( - query: Query, QueryFilter>, + query: Query< + ReadOnlyCustomQuery, + CustomQueryFilter, + >, ) { println!("Print components (read_only):"); for e in &query { @@ -112,8 +115,8 @@ struct GenericQuery { generic: (&'static T, &'static P), } -#[derive(WorldQueryFilter)] -struct QueryFilter { +#[derive(QueryFilter)] +struct CustomQueryFilter { _c: With, _d: With, _or: Or<(Added, Changed, Without)>, @@ -125,7 +128,10 @@ fn spawn(mut commands: Commands) { } fn print_components_iter_mut( - mut query: Query, QueryFilter>, + mut query: Query< + CustomQuery, + CustomQueryFilter, + >, ) { println!("Print components (iter_mut):"); for e in &mut query { @@ -143,7 +149,7 @@ fn print_components_iter_mut( } fn print_components_iter( - query: Query, QueryFilter>, + query: Query, CustomQueryFilter>, ) { println!("Print components (iter):"); for e in &query {