mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
Rename WorldQueryData
& WorldQueryFilter
to QueryData
& QueryFilter
(#10779)
# Rename `WorldQueryData` & `WorldQueryFilter` to `QueryData` & `QueryFilter` Fixes #10776 ## Solution Traits `WorldQueryData` & `WorldQueryFilter` were renamed to `QueryData` and `QueryFilter`, respectively. Related Trait types were also renamed. --- ## Changelog - Trait `WorldQueryData` has been renamed to `QueryData`. Derive macro's `QueryData` attribute `world_query_data` has been renamed to `query_data`. - Trait `WorldQueryFilter` has been renamed to `QueryFilter`. Derive macro's `QueryFilter` attribute `world_query_filter` has been renamed to `query_filter`. - Trait's `ExtractComponent` type `Query` has been renamed to `Data`. - Trait's `GetBatchData` types `Query` & `QueryFilter` has been renamed to `Data` & `Filter`, respectively. - Trait's `ExtractInstance` type `Query` has been renamed to `Data`. - Trait's `ViewNode` type `ViewQuery` has been renamed to `ViewData`. - Trait's `RenderCommand` types `ViewWorldQuery` & `ItemWorldQuery` has been renamed to `ViewData` & `ItemData`, respectively. ## Migration Guide Note: if merged before 0.13 is released, this should instead modify the migration guide of #10776 with the updated names. - Rename `WorldQueryData` & `WorldQueryFilter` trait usages to `QueryData` & `QueryFilter` and their respective derive macro attributes `world_query_data` & `world_query_filter` to `query_data` & `query_filter`. - Rename the following trait type usages: - Trait's `ExtractComponent` type `Query` to `Data`. - Trait's `GetBatchData` type `Query` to `Data`. - Trait's `ExtractInstance` type `Query` to `Data`. - Trait's `ViewNode` type `ViewQuery` to `ViewData`' - Trait's `RenderCommand` types `ViewWolrdQuery` & `ItemWorldQuery` to `ViewData` & `ItemData`, respectively. ```rust // Before #[derive(WorldQueryData)] #[world_query_data(derive(Debug))] struct EmptyQuery { empty: (), } // After #[derive(QueryData)] #[query_data(derive(Debug))] struct EmptyQuery { empty: (), } // Before #[derive(WorldQueryFilter)] struct CustomQueryFilter<T: Component, P: Component> { _c: With<ComponentC>, _d: With<ComponentD>, _or: Or<(Added<ComponentC>, Changed<ComponentD>, Without<ComponentZ>)>, _generic_tuple: (With<T>, With<P>), } // After #[derive(QueryFilter)] struct CustomQueryFilter<T: Component, P: Component> { _c: With<ComponentC>, _d: With<ComponentD>, _or: Or<(Added<ComponentC>, Changed<ComponentD>, Without<ComponentZ>)>, _generic_tuple: (With<T>, With<P>), } // Before impl ExtractComponent for ContrastAdaptiveSharpeningSettings { type Query = &'static Self; type Filter = With<Camera>; type Out = (DenoiseCAS, CASUniform); fn extract_component(item: QueryItem<Self::Query>) -> Option<Self::Out> { //... } } // After impl ExtractComponent for ContrastAdaptiveSharpeningSettings { type Data = &'static Self; type Filter = With<Camera>; type Out = (DenoiseCAS, CASUniform); fn extract_component(item: QueryItem<Self::Data>) -> Option<Self::Out> { //... } } // Before impl GetBatchData for MeshPipeline { type Param = SRes<RenderMeshInstances>; type Query = Entity; type QueryFilter = With<Mesh3d>; type CompareData = (MaterialBindGroupId, AssetId<Mesh>); type BufferData = MeshUniform; fn get_batch_data( mesh_instances: &SystemParamItem<Self::Param>, entity: &QueryItem<Self::Query>, ) -> (Self::BufferData, Option<Self::CompareData>) { // .... } } // After impl GetBatchData for MeshPipeline { type Param = SRes<RenderMeshInstances>; type Data = Entity; type Filter = With<Mesh3d>; type CompareData = (MaterialBindGroupId, AssetId<Mesh>); type BufferData = MeshUniform; fn get_batch_data( mesh_instances: &SystemParamItem<Self::Param>, entity: &QueryItem<Self::Data>, ) -> (Self::BufferData, Option<Self::CompareData>) { // .... } } // Before impl<A> ExtractInstance for AssetId<A> where A: Asset, { type Query = Read<Handle<A>>; type Filter = (); fn extract(item: QueryItem<'_, Self::Query>) -> Option<Self> { Some(item.id()) } } // After impl<A> ExtractInstance for AssetId<A> where A: Asset, { type Data = Read<Handle<A>>; type Filter = (); fn extract(item: QueryItem<'_, Self::Data>) -> Option<Self> { Some(item.id()) } } // Before impl ViewNode for PostProcessNode { type ViewQuery = ( &'static ViewTarget, &'static PostProcessSettings, ); fn run( &self, _graph: &mut RenderGraphContext, render_context: &mut RenderContext, (view_target, _post_process_settings): QueryItem<Self::ViewQuery>, world: &World, ) -> Result<(), NodeRunError> { // ... } } // After impl ViewNode for PostProcessNode { type ViewData = ( &'static ViewTarget, &'static PostProcessSettings, ); fn run( &self, _graph: &mut RenderGraphContext, render_context: &mut RenderContext, (view_target, _post_process_settings): QueryItem<Self::ViewData>, world: &World, ) -> Result<(), NodeRunError> { // ... } } // Before impl<P: CachedRenderPipelinePhaseItem> RenderCommand<P> for SetItemPipeline { type Param = SRes<PipelineCache>; type ViewWorldQuery = (); type ItemWorldQuery = (); #[inline] fn render<'w>( item: &P, _view: (), _entity: (), pipeline_cache: SystemParamItem<'w, '_, Self::Param>, pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { // ... } } // After impl<P: CachedRenderPipelinePhaseItem> RenderCommand<P> for SetItemPipeline { type Param = SRes<PipelineCache>; type ViewData = (); type ItemData = (); #[inline] fn render<'w>( item: &P, _view: (), _entity: (), pipeline_cache: SystemParamItem<'w, '_, Self::Param>, pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { // ... } } ```
This commit is contained in:
parent
79641c7f08
commit
5af2f022d8
57 changed files with 413 additions and 416 deletions
|
@ -1,4 +1,4 @@
|
|||
use bevy_ecs::query::WorldQueryData;
|
||||
use bevy_ecs::query::QueryData;
|
||||
use bevy_ecs::{component::Component, entity::Entity, reflect::ReflectComponent};
|
||||
|
||||
use bevy_reflect::std_traits::ReflectDefault;
|
||||
|
@ -102,7 +102,7 @@ impl std::fmt::Debug for Name {
|
|||
/// }
|
||||
/// # bevy_ecs::system::assert_is_system(increment_score);
|
||||
/// ```
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
pub struct DebugName {
|
||||
/// A [`Name`] that the entity might have that is displayed if available.
|
||||
pub name: Option<&'static Name>,
|
||||
|
|
|
@ -113,7 +113,7 @@ impl Plugin for BloomPlugin {
|
|||
#[derive(Default)]
|
||||
struct BloomNode;
|
||||
impl ViewNode for BloomNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ExtractedCamera,
|
||||
&'static ViewTarget,
|
||||
&'static BloomTexture,
|
||||
|
@ -140,7 +140,7 @@ impl ViewNode for BloomNode {
|
|||
bloom_settings,
|
||||
upsampling_pipeline_ids,
|
||||
downsampling_pipeline_ids,
|
||||
): QueryItem<Self::ViewQuery>,
|
||||
): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let downsampling_pipeline_res = world.resource::<BloomDownsamplingPipeline>();
|
||||
|
|
|
@ -182,12 +182,12 @@ pub enum BloomCompositeMode {
|
|||
}
|
||||
|
||||
impl ExtractComponent for BloomSettings {
|
||||
type Query = (&'static Self, &'static Camera);
|
||||
type Data = (&'static Self, &'static Camera);
|
||||
|
||||
type Filter = ();
|
||||
type Out = (Self, BloomUniforms);
|
||||
|
||||
fn extract_component((settings, camera): QueryItem<'_, Self::Query>) -> Option<Self::Out> {
|
||||
fn extract_component((settings, camera): QueryItem<'_, Self::Data>) -> Option<Self::Out> {
|
||||
match (
|
||||
camera.physical_viewport_rect(),
|
||||
camera.physical_viewport_size(),
|
||||
|
|
|
@ -77,11 +77,11 @@ pub struct CASUniform {
|
|||
}
|
||||
|
||||
impl ExtractComponent for ContrastAdaptiveSharpeningSettings {
|
||||
type Query = &'static Self;
|
||||
type Data = &'static Self;
|
||||
type Filter = With<Camera>;
|
||||
type Out = (DenoiseCAS, CASUniform);
|
||||
|
||||
fn extract_component(item: QueryItem<Self::Query>) -> Option<Self::Out> {
|
||||
fn extract_component(item: QueryItem<Self::Data>) -> Option<Self::Out> {
|
||||
if !item.enabled || item.sharpening_strength == 0.0 {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ use super::{AlphaMask3d, Camera3dDepthLoadOp};
|
|||
#[derive(Default)]
|
||||
pub struct MainOpaquePass3dNode;
|
||||
impl ViewNode for MainOpaquePass3dNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ExtractedCamera,
|
||||
&'static RenderPhase<Opaque3d>,
|
||||
&'static RenderPhase<AlphaMask3d>,
|
||||
|
@ -58,7 +58,7 @@ impl ViewNode for MainOpaquePass3dNode {
|
|||
skybox_pipeline,
|
||||
skybox_bind_group,
|
||||
view_uniform_offset,
|
||||
): QueryItem<Self::ViewQuery>,
|
||||
): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let load = if deferred_prepass.is_none() {
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::ops::Range;
|
|||
pub struct MainTransmissivePass3dNode;
|
||||
|
||||
impl ViewNode for MainTransmissivePass3dNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ExtractedCamera,
|
||||
&'static Camera3d,
|
||||
&'static RenderPhase<Transmissive3d>,
|
||||
|
@ -34,7 +34,7 @@ impl ViewNode for MainTransmissivePass3dNode {
|
|||
graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(camera, camera_3d, transmissive_phase, target, transmission, depth): QueryItem<
|
||||
Self::ViewQuery,
|
||||
Self::ViewData,
|
||||
>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
|
|
|
@ -16,7 +16,7 @@ use bevy_utils::tracing::info_span;
|
|||
pub struct MainTransparentPass3dNode;
|
||||
|
||||
impl ViewNode for MainTransparentPass3dNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ExtractedCamera,
|
||||
&'static RenderPhase<Transparent3d>,
|
||||
&'static ViewTarget,
|
||||
|
@ -26,7 +26,7 @@ impl ViewNode for MainTransparentPass3dNode {
|
|||
&self,
|
||||
graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(camera, transparent_phase, target, depth): QueryItem<Self::ViewQuery>,
|
||||
(camera, transparent_phase, target, depth): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let view_entity = graph.view_entity();
|
||||
|
|
|
@ -61,7 +61,7 @@ impl CopyDeferredLightingIdNode {
|
|||
}
|
||||
|
||||
impl ViewNode for CopyDeferredLightingIdNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ViewTarget,
|
||||
&'static ViewPrepassTextures,
|
||||
&'static DeferredLightingIdDepthTexture,
|
||||
|
@ -72,7 +72,7 @@ impl ViewNode for CopyDeferredLightingIdNode {
|
|||
_graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(_view_target, view_prepass_textures, deferred_lighting_id_depth_texture): QueryItem<
|
||||
Self::ViewQuery,
|
||||
Self::ViewData,
|
||||
>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
|
|
|
@ -29,7 +29,7 @@ use super::{AlphaMask3dDeferred, Opaque3dDeferred};
|
|||
pub struct DeferredGBufferPrepassNode;
|
||||
|
||||
impl ViewNode for DeferredGBufferPrepassNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ExtractedCamera,
|
||||
&'static RenderPhase<Opaque3dDeferred>,
|
||||
&'static RenderPhase<AlphaMask3dDeferred>,
|
||||
|
@ -55,7 +55,7 @@ impl ViewNode for DeferredGBufferPrepassNode {
|
|||
depth_prepass,
|
||||
normal_prepass,
|
||||
motion_vector_prepass,
|
||||
): QueryItem<Self::ViewQuery>,
|
||||
): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let view_entity = graph.view_entity();
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct FxaaNode {
|
|||
}
|
||||
|
||||
impl ViewNode for FxaaNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ViewTarget,
|
||||
&'static CameraFxaaPipeline,
|
||||
&'static Fxaa,
|
||||
|
@ -30,7 +30,7 @@ impl ViewNode for FxaaNode {
|
|||
&self,
|
||||
_graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(target, pipeline, fxaa): QueryItem<Self::ViewQuery>,
|
||||
(target, pipeline, fxaa): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let pipeline_cache = world.resource::<PipelineCache>();
|
||||
|
|
|
@ -25,7 +25,7 @@ use super::{AlphaMask3dPrepass, DeferredPrepass, Opaque3dPrepass, ViewPrepassTex
|
|||
pub struct PrepassNode;
|
||||
|
||||
impl ViewNode for PrepassNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ExtractedCamera,
|
||||
&'static RenderPhase<Opaque3dPrepass>,
|
||||
&'static RenderPhase<AlphaMask3dPrepass>,
|
||||
|
@ -45,7 +45,7 @@ impl ViewNode for PrepassNode {
|
|||
view_depth_texture,
|
||||
view_prepass_textures,
|
||||
deferred_prepass,
|
||||
): QueryItem<Self::ViewQuery>,
|
||||
): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let view_entity = graph.view_entity();
|
||||
|
|
|
@ -168,7 +168,7 @@ impl Default for TemporalAntiAliasSettings {
|
|||
pub struct TemporalAntiAliasNode;
|
||||
|
||||
impl ViewNode for TemporalAntiAliasNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ExtractedCamera,
|
||||
&'static ViewTarget,
|
||||
&'static TemporalAntiAliasHistoryTextures,
|
||||
|
@ -181,7 +181,7 @@ impl ViewNode for TemporalAntiAliasNode {
|
|||
_graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(camera, view_target, taa_history_textures, prepass_textures, taa_pipeline_id): QueryItem<
|
||||
Self::ViewQuery,
|
||||
Self::ViewData,
|
||||
>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
|
|
|
@ -24,7 +24,7 @@ pub struct TonemappingNode {
|
|||
}
|
||||
|
||||
impl ViewNode for TonemappingNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ViewUniformOffset,
|
||||
&'static ViewTarget,
|
||||
&'static ViewTonemappingPipeline,
|
||||
|
@ -36,7 +36,7 @@ impl ViewNode for TonemappingNode {
|
|||
_graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(view_uniform_offset, target, view_tonemapping_pipeline, tonemapping): QueryItem<
|
||||
Self::ViewQuery,
|
||||
Self::ViewData,
|
||||
>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
|
|
|
@ -18,7 +18,7 @@ pub struct UpscalingNode {
|
|||
}
|
||||
|
||||
impl ViewNode for UpscalingNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ViewTarget,
|
||||
&'static ViewUpscalingPipeline,
|
||||
Option<&'static ExtractedCamera>,
|
||||
|
@ -28,7 +28,7 @@ impl ViewNode for UpscalingNode {
|
|||
&self,
|
||||
_graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(target, upscaling_target, camera): QueryItem<Self::ViewQuery>,
|
||||
(target, upscaling_target, camera): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let pipeline_cache = world.get_resource::<PipelineCache>().unwrap();
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
extern crate proc_macro;
|
||||
|
||||
mod component;
|
||||
mod query_data;
|
||||
mod query_filter;
|
||||
mod states;
|
||||
mod world_query;
|
||||
mod world_query_data;
|
||||
mod world_query_filter;
|
||||
|
||||
use crate::{
|
||||
world_query_data::derive_world_query_data_impl,
|
||||
world_query_filter::derive_world_query_filter_impl,
|
||||
};
|
||||
use crate::{query_data::derive_query_data_impl, query_filter::derive_query_filter_impl};
|
||||
use bevy_macro_utils::{derive_label, ensure_no_collision, get_struct_fields, BevyManifest};
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
|
@ -450,16 +447,16 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
|
|||
})
|
||||
}
|
||||
|
||||
/// Implement `WorldQueryData` to use a struct as a data parameter in a query
|
||||
#[proc_macro_derive(WorldQueryData, attributes(world_query_data))]
|
||||
pub fn derive_world_query_data(input: TokenStream) -> TokenStream {
|
||||
derive_world_query_data_impl(input)
|
||||
/// Implement `QueryData` to use a struct as a data parameter in a query
|
||||
#[proc_macro_derive(QueryData, attributes(query_data))]
|
||||
pub fn derive_query_data(input: TokenStream) -> TokenStream {
|
||||
derive_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))]
|
||||
pub fn derive_world_query_filter(input: TokenStream) -> TokenStream {
|
||||
derive_world_query_filter_impl(input)
|
||||
/// Implement `QueryFilter` to use a struct as a filter parameter in a query
|
||||
#[proc_macro_derive(QueryFilter, attributes(query_filter))]
|
||||
pub fn derive_query_filter(input: TokenStream) -> TokenStream {
|
||||
derive_query_filter_impl(input)
|
||||
}
|
||||
|
||||
/// Derive macro generating an impl of the trait `ScheduleLabel`.
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[derive(Default)]
|
||||
struct WorldQueryDataAttributes {
|
||||
struct QueryDataAttributes {
|
||||
pub is_mutable: bool,
|
||||
|
||||
pub derive_args: Punctuated<Meta, syn::token::Comma>,
|
||||
|
@ -29,20 +29,20 @@ mod field_attr_keywords {
|
|||
syn::custom_keyword!(ignore);
|
||||
}
|
||||
|
||||
pub static WORLD_QUERY_DATA_ATTRIBUTE_NAME: &str = "world_query_data";
|
||||
pub static QUERY_DATA_ATTRIBUTE_NAME: &str = "query_data";
|
||||
|
||||
pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
||||
pub fn derive_query_data_impl(input: TokenStream) -> TokenStream {
|
||||
let tokens = input.clone();
|
||||
|
||||
let ast = parse_macro_input!(input as DeriveInput);
|
||||
let visibility = ast.vis;
|
||||
|
||||
let mut attributes = WorldQueryDataAttributes::default();
|
||||
let mut attributes = QueryDataAttributes::default();
|
||||
for attr in &ast.attrs {
|
||||
if !attr
|
||||
.path()
|
||||
.get_ident()
|
||||
.map_or(false, |ident| ident == WORLD_QUERY_DATA_ATTRIBUTE_NAME)
|
||||
.map_or(false, |ident| ident == QUERY_DATA_ATTRIBUTE_NAME)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap_or_else(|_| panic!("Invalid `{WORLD_QUERY_DATA_ATTRIBUTE_NAME}` attribute format"));
|
||||
.unwrap_or_else(|_| panic!("Invalid `{QUERY_DATA_ATTRIBUTE_NAME}` attribute format"));
|
||||
}
|
||||
|
||||
let path = bevy_ecs_path();
|
||||
|
@ -137,7 +137,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
let Data::Struct(DataStruct { fields, .. }) = &ast.data else {
|
||||
return syn::Error::new(
|
||||
Span::call_site(),
|
||||
"#[derive(WorldQueryData)]` only supports structs",
|
||||
"#[derive(QueryData)]` only supports structs",
|
||||
)
|
||||
.into_compile_error()
|
||||
.into();
|
||||
|
@ -151,7 +151,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
let mut read_only_field_types = Vec::new();
|
||||
for (i, field) in fields.iter().enumerate() {
|
||||
let attrs = match read_world_query_field_info(field) {
|
||||
Ok(WorldQueryDataFieldInfo { attrs }) => attrs,
|
||||
Ok(QueryDataFieldInfo { attrs }) => attrs,
|
||||
Err(e) => return e.into_compile_error().into(),
|
||||
};
|
||||
|
||||
|
@ -171,7 +171,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
field_visibilities.push(field.vis.clone());
|
||||
let field_ty = field.ty.clone();
|
||||
field_types.push(quote!(#field_ty));
|
||||
read_only_field_types.push(quote!(<#field_ty as #path::query::WorldQueryData>::ReadOnly));
|
||||
read_only_field_types.push(quote!(<#field_ty as #path::query::QueryData>::ReadOnly));
|
||||
}
|
||||
|
||||
let derive_args = &attributes.derive_args;
|
||||
|
@ -274,7 +274,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
let read_only_data_impl = if attributes.is_mutable {
|
||||
quote! {
|
||||
/// SAFETY: we assert fields are readonly below
|
||||
unsafe impl #user_impl_generics #path::query::WorldQueryData
|
||||
unsafe impl #user_impl_generics #path::query::QueryData
|
||||
for #read_only_struct_name #user_ty_generics #user_where_clauses {
|
||||
type ReadOnly = #read_only_struct_name #user_ty_generics;
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
|
||||
quote! {
|
||||
/// SAFETY: we assert fields are readonly below
|
||||
unsafe impl #user_impl_generics #path::query::WorldQueryData
|
||||
unsafe impl #user_impl_generics #path::query::QueryData
|
||||
for #struct_name #user_ty_generics #user_where_clauses {
|
||||
type ReadOnly = #read_only_struct_name #user_ty_generics;
|
||||
}
|
||||
|
@ -296,24 +296,24 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
|
||||
let read_only_data_impl = quote! {
|
||||
/// SAFETY: we assert fields are readonly below
|
||||
unsafe impl #user_impl_generics #path::query::ReadOnlyWorldQueryData
|
||||
unsafe impl #user_impl_generics #path::query::ReadOnlyQueryData
|
||||
for #read_only_struct_name #user_ty_generics #user_where_clauses {}
|
||||
};
|
||||
|
||||
let read_only_asserts = if attributes.is_mutable {
|
||||
quote! {
|
||||
// Double-check that the data fetched by `<_ as WorldQuery>::ReadOnly` is read-only.
|
||||
// This is technically unnecessary as `<_ as WorldQuery>::ReadOnly: ReadOnlyWorldQueryData`
|
||||
// but to protect against future mistakes we assert the assoc type implements `ReadOnlyWorldQueryData` anyway
|
||||
// This is technically unnecessary as `<_ as WorldQuery>::ReadOnly: ReadOnlyQueryData`
|
||||
// but to protect against future mistakes we assert the assoc type implements `ReadOnlyQueryData` anyway
|
||||
#( assert_readonly::<#read_only_field_types>(); )*
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
// Statically checks that the safety guarantee of `ReadOnlyWorldQueryData` for `$fetch_struct_name` actually holds true.
|
||||
// We need this to make sure that we don't compile `ReadOnlyWorldQueryData` if our struct contains nested `WorldQueryData`
|
||||
// Statically checks that the safety guarantee of `ReadOnlyQueryData` for `$fetch_struct_name` actually holds true.
|
||||
// We need this to make sure that we don't compile `ReadOnlyQueryData` if our struct contains nested `QueryData`
|
||||
// members that don't implement it. I.e.:
|
||||
// ```
|
||||
// #[derive(WorldQueryData)]
|
||||
// #[derive(QueryData)]
|
||||
// pub struct Foo { a: &'static mut MyComponent }
|
||||
// ```
|
||||
#( assert_readonly::<#field_types>(); )*
|
||||
|
@ -352,13 +352,13 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
const _: () = {
|
||||
fn assert_readonly<T>()
|
||||
where
|
||||
T: #path::query::ReadOnlyWorldQueryData,
|
||||
T: #path::query::ReadOnlyQueryData,
|
||||
{
|
||||
}
|
||||
|
||||
fn assert_data<T>()
|
||||
where
|
||||
T: #path::query::WorldQueryData,
|
||||
T: #path::query::QueryData,
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -385,26 +385,26 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
|||
})
|
||||
}
|
||||
|
||||
struct WorldQueryDataFieldInfo {
|
||||
/// All field attributes except for `world_query_data` ones.
|
||||
struct QueryDataFieldInfo {
|
||||
/// All field attributes except for `query_data` ones.
|
||||
attrs: Vec<Attribute>,
|
||||
}
|
||||
|
||||
fn read_world_query_field_info(field: &Field) -> syn::Result<WorldQueryDataFieldInfo> {
|
||||
fn read_world_query_field_info(field: &Field) -> syn::Result<QueryDataFieldInfo> {
|
||||
let mut attrs = Vec::new();
|
||||
for attr in &field.attrs {
|
||||
if attr
|
||||
.path()
|
||||
.get_ident()
|
||||
.map_or(false, |ident| ident == WORLD_QUERY_DATA_ATTRIBUTE_NAME)
|
||||
.map_or(false, |ident| ident == QUERY_DATA_ATTRIBUTE_NAME)
|
||||
{
|
||||
return Err(syn::Error::new_spanned(
|
||||
attr,
|
||||
"#[derive(WorldQueryData)] does not support field attributes.",
|
||||
"#[derive(QueryData)] does not support field attributes.",
|
||||
));
|
||||
}
|
||||
attrs.push(attr.clone());
|
||||
}
|
||||
|
||||
Ok(WorldQueryDataFieldInfo { attrs })
|
||||
Ok(QueryDataFieldInfo { attrs })
|
||||
}
|
|
@ -13,7 +13,7 @@ mod field_attr_keywords {
|
|||
syn::custom_keyword!(ignore);
|
||||
}
|
||||
|
||||
pub fn derive_world_query_filter_impl(input: TokenStream) -> TokenStream {
|
||||
pub fn derive_query_filter_impl(input: TokenStream) -> TokenStream {
|
||||
let tokens = input.clone();
|
||||
|
||||
let ast = parse_macro_input!(input as DeriveInput);
|
||||
|
@ -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<T>()
|
||||
where
|
||||
T: #path::query::WorldQueryFilter,
|
||||
T: #path::query::QueryFilter,
|
||||
{
|
||||
}
|
||||
|
|
@ -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},
|
||||
};
|
||||
|
@ -907,7 +907,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_filtered<F: WorldQueryFilter>(world: &mut World) -> Vec<Entity> {
|
||||
fn get_filtered<F: QueryFilter>(world: &mut World) -> Vec<Entity> {
|
||||
world
|
||||
.query_filtered::<Entity, F>()
|
||||
.iter(world)
|
||||
|
@ -990,7 +990,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_filtered<F: WorldQueryFilter>(world: &mut World) -> Vec<Entity> {
|
||||
fn get_filtered<F: QueryFilter>(world: &mut World) -> Vec<Entity> {
|
||||
world
|
||||
.query_filtered::<Entity, F>()
|
||||
.iter(world)
|
||||
|
|
|
@ -17,8 +17,8 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// - **Component references.**
|
||||
/// Fetches a component by reference (immutably or mutably).
|
||||
/// - **`WorldQueryData` tuples.**
|
||||
/// If every element of a tuple implements `WorldQueryData`, then the tuple itself also implements the same trait.
|
||||
/// - **`QueryData` tuples.**
|
||||
/// If every element of a tuple implements `QueryData`, then the tuple itself also implements the same trait.
|
||||
/// This enables a single `Query` to access multiple components.
|
||||
/// 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 `WorldQuery`s.
|
||||
|
@ -39,8 +39,8 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// # Trait derivation
|
||||
///
|
||||
/// Query design can be easily structured by deriving `WorldQueryData` for custom types.
|
||||
/// Despite the added complexity, this approach has several advantages over using `WorldQueryData` tuples.
|
||||
/// Query design can be easily structured by deriving `QueryData` for custom types.
|
||||
/// Despite the added complexity, this approach has several advantages over using `QueryData` tuples.
|
||||
/// The most relevant improvements are:
|
||||
///
|
||||
/// - Reusability across multiple systems.
|
||||
|
@ -49,18 +49,18 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// - Methods can be implemented for the query items.
|
||||
/// - There is no hardcoded limit on the number of elements.
|
||||
///
|
||||
/// This trait can only be derived for structs, if each field also implements `WorldQueryData`.
|
||||
/// This trait can only be derived for structs, if each field also implements `QueryData`.
|
||||
///
|
||||
/// ```
|
||||
/// # use bevy_ecs::prelude::*;
|
||||
/// use bevy_ecs::query::WorldQueryData;
|
||||
/// use bevy_ecs::query::QueryData;
|
||||
/// #
|
||||
/// # #[derive(Component)]
|
||||
/// # struct ComponentA;
|
||||
/// # #[derive(Component)]
|
||||
/// # struct ComponentB;
|
||||
///
|
||||
/// #[derive(WorldQueryData)]
|
||||
/// #[derive(QueryData)]
|
||||
/// struct MyQuery {
|
||||
/// entity: Entity,
|
||||
/// // It is required that all reference lifetimes are explicitly annotated, just like in any
|
||||
|
@ -90,33 +90,33 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// ## Adding mutable references
|
||||
///
|
||||
/// Simply adding mutable references to a derived `WorldQueryData` will result in a compilation error:
|
||||
/// Simply adding mutable references to a derived `QueryData` will result in a compilation error:
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// # use bevy_ecs::prelude::*;
|
||||
/// # use bevy_ecs::query::WorldQueryData;
|
||||
/// # use bevy_ecs::query::QueryData;
|
||||
/// #
|
||||
/// # #[derive(Component)]
|
||||
/// # struct ComponentA;
|
||||
/// #
|
||||
/// #[derive(WorldQueryData)]
|
||||
/// #[derive(QueryData)]
|
||||
/// struct CustomQuery {
|
||||
/// component_a: &'static mut ComponentA,
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// To grant mutable access to components, the struct must be marked with the `#[world_query_data(mutable)]` attribute.
|
||||
/// To grant mutable access to components, the struct must be marked with the `#[query_data(mutable)]` attribute.
|
||||
/// This will also create three more structs that will be used for accessing the query immutably (see table above).
|
||||
///
|
||||
/// ```
|
||||
/// # use bevy_ecs::prelude::*;
|
||||
/// # use bevy_ecs::query::WorldQueryData;
|
||||
/// # use bevy_ecs::query::QueryData;
|
||||
/// #
|
||||
/// # #[derive(Component)]
|
||||
/// # struct ComponentA;
|
||||
/// #
|
||||
/// #[derive(WorldQueryData)]
|
||||
/// #[world_query_data(mutable)]
|
||||
/// #[derive(QueryData)]
|
||||
/// #[query_data(mutable)]
|
||||
/// struct CustomQuery {
|
||||
/// component_a: &'static mut ComponentA,
|
||||
/// }
|
||||
|
@ -130,7 +130,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// ```
|
||||
/// # use bevy_ecs::prelude::*;
|
||||
/// # use bevy_ecs::query::WorldQueryData;
|
||||
/// # use bevy_ecs::query::QueryData;
|
||||
/// #
|
||||
/// #[derive(Component)]
|
||||
/// struct Health(f32);
|
||||
|
@ -138,8 +138,8 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// #[derive(Component)]
|
||||
/// struct Buff(f32);
|
||||
///
|
||||
/// #[derive(WorldQueryData)]
|
||||
/// #[world_query_data(mutable)]
|
||||
/// #[derive(QueryData)]
|
||||
/// #[query_data(mutable)]
|
||||
/// struct HealthQuery {
|
||||
/// health: &'static mut Health,
|
||||
/// buff: Option<&'static mut Buff>,
|
||||
|
@ -179,19 +179,19 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// ## Deriving traits for query items
|
||||
///
|
||||
/// The `WorldQueryData` derive macro does not automatically implement the traits of the struct to the query item types.
|
||||
/// Something similar can be done by using the `#[world_query_data(derive(...))]` attribute.
|
||||
/// The `QueryData` derive macro does not automatically implement the traits of the struct to the query item types.
|
||||
/// Something similar can be done by using the `#[query_data(derive(...))]` attribute.
|
||||
/// This will apply the listed derivable traits to the query item structs.
|
||||
///
|
||||
/// ```
|
||||
/// # use bevy_ecs::prelude::*;
|
||||
/// # use bevy_ecs::query::WorldQueryData;
|
||||
/// # use bevy_ecs::query::QueryData;
|
||||
/// #
|
||||
/// # #[derive(Component, Debug)]
|
||||
/// # struct ComponentA;
|
||||
/// #
|
||||
/// #[derive(WorldQueryData)]
|
||||
/// #[world_query_data(mutable, derive(Debug))]
|
||||
/// #[derive(QueryData)]
|
||||
/// #[query_data(mutable, derive(Debug))]
|
||||
/// struct CustomQuery {
|
||||
/// component_a: &'static ComponentA,
|
||||
/// }
|
||||
|
@ -205,12 +205,12 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// ## Query composition
|
||||
///
|
||||
/// It is possible to use any `WorldQueryData` as a field of another one.
|
||||
/// This means that a `WorldQueryData` can also be used as a subquery, potentially in multiple places.
|
||||
/// It is possible to use any `QueryData` as a field of another one.
|
||||
/// This means that a `QueryData` can also be used as a subquery, potentially in multiple places.
|
||||
///
|
||||
/// ```
|
||||
/// # use bevy_ecs::prelude::*;
|
||||
/// # use bevy_ecs::query::WorldQueryData;
|
||||
/// # use bevy_ecs::query::QueryData;
|
||||
/// #
|
||||
/// # #[derive(Component)]
|
||||
/// # struct ComponentA;
|
||||
|
@ -219,13 +219,13 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// # #[derive(Component)]
|
||||
/// # struct ComponentC;
|
||||
/// #
|
||||
/// #[derive(WorldQueryData)]
|
||||
/// #[derive(QueryData)]
|
||||
/// struct SubQuery {
|
||||
/// component_a: &'static ComponentA,
|
||||
/// component_b: &'static ComponentB,
|
||||
/// }
|
||||
///
|
||||
/// #[derive(WorldQueryData)]
|
||||
/// #[derive(QueryData)]
|
||||
/// struct MyQuery {
|
||||
/// subquery: SubQuery,
|
||||
/// component_c: &'static ComponentC,
|
||||
|
@ -235,13 +235,13 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// # Generic Queries
|
||||
///
|
||||
/// When writing generic code, it is often necessary to use [`PhantomData`]
|
||||
/// to constrain type parameters. Since `WorldQueryData` is implemented for all
|
||||
/// to constrain type parameters. Since `QueryData` is implemented for all
|
||||
/// `PhantomData<T>` types, this pattern can be used with this macro.
|
||||
///
|
||||
/// ```
|
||||
/// # use bevy_ecs::{prelude::*, query::WorldQueryData};
|
||||
/// # use bevy_ecs::{prelude::*, query::QueryData};
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #[derive(WorldQueryData)]
|
||||
/// #[derive(QueryData)]
|
||||
/// pub struct GenericQuery<T> {
|
||||
/// id: Entity,
|
||||
/// marker: PhantomData<T>,
|
||||
|
@ -257,22 +257,22 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// [`Query`]: crate::system::Query
|
||||
/// [`ReadOnly`]: Self::ReadOnly
|
||||
pub unsafe trait WorldQueryData: WorldQuery {
|
||||
/// The read-only variant of this [`WorldQueryData`], which satisfies the [`ReadOnlyWorldQueryData`] trait.
|
||||
type ReadOnly: ReadOnlyWorldQueryData<State = <Self as WorldQuery>::State>;
|
||||
pub unsafe trait QueryData: WorldQuery {
|
||||
/// The read-only variant of this [`QueryData`], which satisfies the [`ReadOnlyQueryData`] trait.
|
||||
type ReadOnly: ReadOnlyQueryData<State = <Self as WorldQuery>::State>;
|
||||
}
|
||||
|
||||
/// A [`WorldQueryData`] that is read only.
|
||||
/// A [`QueryData`] that is read only.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This must only be implemented for read-only [`WorldQueryData`]'s.
|
||||
pub unsafe trait ReadOnlyWorldQueryData: WorldQueryData<ReadOnly = Self> {}
|
||||
/// This must only be implemented for read-only [`QueryData`]'s.
|
||||
pub unsafe trait ReadOnlyQueryData: QueryData<ReadOnly = Self> {}
|
||||
|
||||
/// The item type returned when a [`WorldQuery`] is iterated over
|
||||
pub type QueryItem<'w, Q> = <Q as WorldQuery>::Item<'w>;
|
||||
/// The read-only variant of the item type returned when a [`WorldQueryData`] is iterated over immutably
|
||||
pub type ROQueryItem<'w, Q> = QueryItem<'w, <Q as WorldQueryData>::ReadOnly>;
|
||||
/// The read-only variant of the item type returned when a [`QueryData`] is iterated over immutably
|
||||
pub type ROQueryItem<'w, Q> = QueryItem<'w, <Q as QueryData>::ReadOnly>;
|
||||
|
||||
/// SAFETY:
|
||||
/// `update_component_access` and `update_archetype_component_access` do nothing.
|
||||
|
@ -338,12 +338,12 @@ unsafe impl WorldQuery for Entity {
|
|||
}
|
||||
|
||||
/// SAFETY: `Self` is the same as `Self::ReadOnly`
|
||||
unsafe impl WorldQueryData for Entity {
|
||||
unsafe impl QueryData for Entity {
|
||||
type ReadOnly = Self;
|
||||
}
|
||||
|
||||
/// SAFETY: access is read only
|
||||
unsafe impl ReadOnlyWorldQueryData for Entity {}
|
||||
unsafe impl ReadOnlyQueryData for Entity {}
|
||||
|
||||
/// SAFETY:
|
||||
/// `fetch` accesses all components in a readonly way.
|
||||
|
@ -423,12 +423,12 @@ unsafe impl<'a> WorldQuery for EntityRef<'a> {
|
|||
}
|
||||
|
||||
/// SAFETY: `Self` is the same as `Self::ReadOnly`
|
||||
unsafe impl<'a> WorldQueryData for EntityRef<'a> {
|
||||
unsafe impl<'a> QueryData for EntityRef<'a> {
|
||||
type ReadOnly = Self;
|
||||
}
|
||||
|
||||
/// SAFETY: access is read only
|
||||
unsafe impl ReadOnlyWorldQueryData for EntityRef<'_> {}
|
||||
unsafe impl ReadOnlyQueryData for EntityRef<'_> {}
|
||||
|
||||
/// SAFETY: The accesses of `Self::ReadOnly` are a subset of the accesses of `Self`
|
||||
unsafe impl<'a> WorldQuery for EntityMut<'a> {
|
||||
|
@ -505,7 +505,7 @@ unsafe impl<'a> WorldQuery for EntityMut<'a> {
|
|||
}
|
||||
|
||||
/// SAFETY: access of `EntityRef` is a subset of `EntityMut`
|
||||
unsafe impl<'a> WorldQueryData for EntityMut<'a> {
|
||||
unsafe impl<'a> QueryData for EntityMut<'a> {
|
||||
type ReadOnly = EntityRef<'a>;
|
||||
}
|
||||
|
||||
|
@ -651,12 +651,12 @@ unsafe impl<T: Component> WorldQuery for &T {
|
|||
}
|
||||
|
||||
/// SAFETY: `Self` is the same as `Self::ReadOnly`
|
||||
unsafe impl<T: Component> WorldQueryData for &T {
|
||||
unsafe impl<T: Component> QueryData for &T {
|
||||
type ReadOnly = Self;
|
||||
}
|
||||
|
||||
/// SAFETY: access is read only
|
||||
unsafe impl<T: Component> ReadOnlyWorldQueryData for &T {}
|
||||
unsafe impl<T: Component> ReadOnlyQueryData for &T {}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub struct RefFetch<'w, T> {
|
||||
|
@ -818,12 +818,12 @@ unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> {
|
|||
}
|
||||
|
||||
/// SAFETY: `Self` is the same as `Self::ReadOnly`
|
||||
unsafe impl<'__w, T: Component> WorldQueryData for Ref<'__w, T> {
|
||||
unsafe impl<'__w, T: Component> QueryData for Ref<'__w, T> {
|
||||
type ReadOnly = Self;
|
||||
}
|
||||
|
||||
/// SAFETY: access is read only
|
||||
unsafe impl<'__w, T: Component> ReadOnlyWorldQueryData for Ref<'__w, T> {}
|
||||
unsafe impl<'__w, T: Component> ReadOnlyQueryData for Ref<'__w, T> {}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub struct WriteFetch<'w, T> {
|
||||
|
@ -985,7 +985,7 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T {
|
|||
}
|
||||
|
||||
/// SAFETY: access of `&T` is a subset of `&mut T`
|
||||
unsafe impl<'__w, T: Component> WorldQueryData for &'__w mut T {
|
||||
unsafe impl<'__w, T: Component> QueryData for &'__w mut T {
|
||||
type ReadOnly = &'__w T;
|
||||
}
|
||||
|
||||
|
@ -1102,12 +1102,12 @@ unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
|
|||
}
|
||||
|
||||
// SAFETY: defers to soundness of `T: WorldQuery` impl
|
||||
unsafe impl<T: WorldQueryData> WorldQueryData for Option<T> {
|
||||
unsafe impl<T: QueryData> QueryData for Option<T> {
|
||||
type ReadOnly = Option<T::ReadOnly>;
|
||||
}
|
||||
|
||||
/// SAFETY: [`OptionFetch`] is read only because `T` is read only
|
||||
unsafe impl<T: ReadOnlyWorldQueryData> ReadOnlyWorldQueryData for Option<T> {}
|
||||
unsafe impl<T: ReadOnlyQueryData> ReadOnlyQueryData for Option<T> {}
|
||||
|
||||
/// Returns a bool that describes if an entity has the component `T`.
|
||||
///
|
||||
|
@ -1242,12 +1242,12 @@ unsafe impl<T: Component> WorldQuery for Has<T> {
|
|||
}
|
||||
|
||||
/// SAFETY: `Self` is the same as `Self::ReadOnly`
|
||||
unsafe impl<T: Component> WorldQueryData for Has<T> {
|
||||
unsafe impl<T: Component> QueryData for Has<T> {
|
||||
type ReadOnly = Self;
|
||||
}
|
||||
|
||||
/// SAFETY: [`Has`] is read only
|
||||
unsafe impl<T: Component> ReadOnlyWorldQueryData for Has<T> {}
|
||||
unsafe impl<T: Component> ReadOnlyQueryData for Has<T> {}
|
||||
|
||||
/// The `AnyOf` query parameter fetches entities with any of the component types included in T.
|
||||
///
|
||||
|
@ -1256,18 +1256,18 @@ unsafe impl<T: Component> ReadOnlyWorldQueryData for Has<T> {}
|
|||
/// Entities are guaranteed to have at least one of the components in `T`.
|
||||
pub struct AnyOf<T>(PhantomData<T>);
|
||||
|
||||
macro_rules! impl_tuple_world_query_data {
|
||||
macro_rules! impl_tuple_query_data {
|
||||
($(($name: ident, $state: ident)),*) => {
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[allow(clippy::unused_unit)]
|
||||
// SAFETY: defers to soundness `$name: WorldQuery` impl
|
||||
unsafe impl<$($name: WorldQueryData),*> WorldQueryData for ($($name,)*) {
|
||||
unsafe impl<$($name: QueryData),*> QueryData for ($($name,)*) {
|
||||
type ReadOnly = ($($name::ReadOnly,)*);
|
||||
}
|
||||
|
||||
/// SAFETY: each item in the tuple is read only
|
||||
unsafe impl<$($name: ReadOnlyWorldQueryData),*> ReadOnlyWorldQueryData for ($($name,)*) {}
|
||||
unsafe impl<$($name: ReadOnlyQueryData),*> ReadOnlyQueryData for ($($name,)*) {}
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -1387,27 +1387,27 @@ macro_rules! impl_anytuple_fetch {
|
|||
#[allow(non_snake_case)]
|
||||
#[allow(clippy::unused_unit)]
|
||||
// SAFETY: defers to soundness of `$name: WorldQuery` impl
|
||||
unsafe impl<$($name: WorldQueryData),*> WorldQueryData for AnyOf<($($name,)*)> {
|
||||
unsafe impl<$($name: QueryData),*> QueryData for AnyOf<($($name,)*)> {
|
||||
type ReadOnly = AnyOf<($($name::ReadOnly,)*)>;
|
||||
}
|
||||
|
||||
/// SAFETY: each item in the tuple is read only
|
||||
unsafe impl<$($name: ReadOnlyWorldQueryData),*> ReadOnlyWorldQueryData for AnyOf<($($name,)*)> {}
|
||||
unsafe impl<$($name: ReadOnlyQueryData),*> ReadOnlyQueryData for AnyOf<($($name,)*)> {}
|
||||
};
|
||||
}
|
||||
|
||||
all_tuples!(impl_tuple_world_query_data, 0, 15, F, S);
|
||||
all_tuples!(impl_tuple_query_data, 0, 15, F, S);
|
||||
all_tuples!(impl_anytuple_fetch, 0, 15, F, S);
|
||||
|
||||
/// [`WorldQuery`] used to nullify queries by turning `Query<Q>` into `Query<NopWorldQuery<Q>>`
|
||||
///
|
||||
/// This will rarely be useful to consumers of `bevy_ecs`.
|
||||
pub struct NopWorldQuery<Q: WorldQueryData>(PhantomData<Q>);
|
||||
pub struct NopWorldQuery<Q: QueryData>(PhantomData<Q>);
|
||||
|
||||
/// SAFETY:
|
||||
/// `update_component_access` and `update_archetype_component_access` do nothing.
|
||||
/// This is sound because `fetch` does not access components.
|
||||
unsafe impl<Q: WorldQueryData> WorldQuery for NopWorldQuery<Q> {
|
||||
unsafe impl<Q: QueryData> WorldQuery for NopWorldQuery<Q> {
|
||||
type Fetch<'w> = ();
|
||||
type Item<'w> = ();
|
||||
type State = Q::State;
|
||||
|
@ -1467,12 +1467,12 @@ unsafe impl<Q: WorldQueryData> WorldQuery for NopWorldQuery<Q> {
|
|||
}
|
||||
|
||||
/// SAFETY: `Self::ReadOnly` is `Self`
|
||||
unsafe impl<Q: WorldQueryData> WorldQueryData for NopWorldQuery<Q> {
|
||||
unsafe impl<Q: QueryData> QueryData for NopWorldQuery<Q> {
|
||||
type ReadOnly = Self;
|
||||
}
|
||||
|
||||
/// SAFETY: `NopFetch` never accesses any data
|
||||
unsafe impl<Q: WorldQueryData> ReadOnlyWorldQueryData for NopWorldQuery<Q> {}
|
||||
unsafe impl<Q: QueryData> ReadOnlyQueryData for NopWorldQuery<Q> {}
|
||||
|
||||
/// SAFETY:
|
||||
/// `update_component_access` and `update_archetype_component_access` do nothing.
|
||||
|
@ -1535,16 +1535,16 @@ unsafe impl<T: ?Sized> WorldQuery for PhantomData<T> {
|
|||
}
|
||||
|
||||
/// SAFETY: `Self::ReadOnly` is `Self`
|
||||
unsafe impl<T: ?Sized> WorldQueryData for PhantomData<T> {
|
||||
unsafe impl<T: ?Sized> QueryData for PhantomData<T> {
|
||||
type ReadOnly = Self;
|
||||
}
|
||||
|
||||
/// SAFETY: `PhantomData` never accesses any world data.
|
||||
unsafe impl<T: ?Sized> ReadOnlyWorldQueryData for PhantomData<T> {}
|
||||
unsafe impl<T: ?Sized> ReadOnlyQueryData for PhantomData<T> {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bevy_ecs_macros::WorldQueryData;
|
||||
use bevy_ecs_macros::QueryData;
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
|
@ -1561,16 +1561,16 @@ mod tests {
|
|||
// Tests that each variant of struct can be used as a `WorldQuery`.
|
||||
#[test]
|
||||
fn world_query_struct_variants() {
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
pub struct NamedQuery {
|
||||
id: Entity,
|
||||
a: &'static A,
|
||||
}
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
pub struct TupleQuery(&'static A, &'static B);
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
pub struct UnitQuery;
|
||||
|
||||
fn my_system(_: Query<(NamedQuery, TupleQuery, UnitQuery)>) {}
|
||||
|
@ -1581,7 +1581,7 @@ mod tests {
|
|||
// Compile test for https://github.com/bevyengine/bevy/pull/8030.
|
||||
#[test]
|
||||
fn world_query_phantom_data() {
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
pub struct IgnoredQuery<Marker> {
|
||||
id: Entity,
|
||||
_marker: PhantomData<Marker>,
|
||||
|
@ -1599,8 +1599,8 @@ mod tests {
|
|||
mod private {
|
||||
use super::*;
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(mutable)]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(mutable)]
|
||||
pub struct Q {
|
||||
pub a: &'static mut A,
|
||||
}
|
||||
|
@ -1624,7 +1624,7 @@ mod tests {
|
|||
fn world_query_metadata_collision() {
|
||||
// The metadata types generated would be named `ClientState` and `ClientFetch`,
|
||||
// but they should rename themselves to avoid conflicts.
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
pub struct Client<S: ClientState> {
|
||||
pub state: &'static S,
|
||||
pub fetch: &'static ClientFetch,
|
||||
|
|
|
@ -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<T: Component, P: Component> {
|
||||
/// // Field names are not relevant, since they are never manually accessed.
|
||||
/// with_a: With<ComponentA>,
|
||||
|
@ -73,7 +73,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// [`update_archetype_component_access`]: Self::update_archetype_component_access
|
||||
/// [`update_component_access`]: Self::update_component_access
|
||||
|
||||
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.
|
||||
///
|
||||
|
@ -195,7 +195,7 @@ unsafe impl<T: Component> WorldQuery for With<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Component> WorldQueryFilter for With<T> {
|
||||
impl<T: Component> QueryFilter for With<T> {
|
||||
const IS_ARCHETYPAL: bool = true;
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -307,7 +307,7 @@ unsafe impl<T: Component> WorldQuery for Without<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Component> WorldQueryFilter for Without<T> {
|
||||
impl<T: Component> QueryFilter for Without<T> {
|
||||
const IS_ARCHETYPAL: bool = true;
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -377,7 +377,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,)*);
|
||||
|
@ -471,7 +471,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)]
|
||||
|
@ -486,13 +486,13 @@ macro_rules! impl_query_filter_tuple {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_tuple_world_query_filter {
|
||||
macro_rules! impl_tuple_query_filter {
|
||||
($($name: ident),*) => {
|
||||
#[allow(unused_variables)]
|
||||
#[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)]
|
||||
|
@ -509,7 +509,7 @@ macro_rules! impl_tuple_world_query_filter {
|
|||
};
|
||||
}
|
||||
|
||||
all_tuples!(impl_tuple_world_query_filter, 0, 15, F);
|
||||
all_tuples!(impl_tuple_query_filter, 0, 15, F);
|
||||
all_tuples!(impl_query_filter_tuple, 0, 15, F, S);
|
||||
|
||||
/// A filter on a component that only retains results added after the system last ran.
|
||||
|
@ -670,7 +670,7 @@ unsafe impl<T: Component> WorldQuery for Added<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Component> WorldQueryFilter for Added<T> {
|
||||
impl<T: Component> QueryFilter for Added<T> {
|
||||
const IS_ARCHETYPAL: bool = false;
|
||||
#[inline(always)]
|
||||
unsafe fn filter_fetch(
|
||||
|
@ -846,7 +846,7 @@ unsafe impl<T: Component> WorldQuery for Changed<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Component> WorldQueryFilter for Changed<T> {
|
||||
impl<T: Component> QueryFilter for Changed<T> {
|
||||
const IS_ARCHETYPAL: bool = false;
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -864,14 +864,14 @@ impl<T: Component> WorldQueryFilter for Changed<T> {
|
|||
/// 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<T: Component> ArchetypeFilter for With<T> {}
|
||||
impl<T: Component> ArchetypeFilter for Without<T> {}
|
||||
|
|
|
@ -8,20 +8,20 @@ use crate::{
|
|||
};
|
||||
use std::{borrow::Borrow, iter::FusedIterator, mem::MaybeUninit, ops::Range};
|
||||
|
||||
use super::{ReadOnlyWorldQueryData, WorldQueryData, 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: WorldQueryData, F: WorldQueryFilter> {
|
||||
pub struct QueryIter<'w, 's, Q: QueryData, F: QueryFilter> {
|
||||
tables: &'w Tables,
|
||||
archetypes: &'w Archetypes,
|
||||
query_state: &'s QueryState<Q, F>,
|
||||
cursor: QueryIterationCursor<'w, 's, Q, F>,
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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`.
|
||||
|
@ -198,7 +198,7 @@ impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> QueryIter<'w, 's, Q, F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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)]
|
||||
|
@ -259,7 +259,7 @@ impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> Iterator for QueryIter<'w,
|
|||
}
|
||||
|
||||
// This is correct as [`QueryIter`] always returns `None` once exhausted.
|
||||
impl<'w, 's, Q: WorldQueryData, 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.
|
||||
///
|
||||
|
@ -267,7 +267,7 @@ impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> FusedIterator for QueryIter
|
|||
/// 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: WorldQueryData, F: WorldQueryFilter, I: Iterator>
|
||||
pub struct QueryManyIter<'w, 's, Q: QueryData, F: QueryFilter, I: Iterator>
|
||||
where
|
||||
I::Item: Borrow<Entity>,
|
||||
{
|
||||
|
@ -280,7 +280,7 @@ where
|
|||
query_state: &'s QueryState<Q, F>,
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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<Entity>,
|
||||
{
|
||||
|
@ -376,7 +376,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: ReadOnlyWorldQueryData, 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<Entity>,
|
||||
|
@ -396,7 +396,7 @@ where
|
|||
}
|
||||
|
||||
// This is correct as [`QueryManyIter`] always returns `None` once exhausted.
|
||||
impl<'w, 's, Q: ReadOnlyWorldQueryData, 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<Entity>,
|
||||
|
@ -466,16 +466,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: WorldQueryData, 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<Q, F>,
|
||||
cursors: [QueryIterationCursor<'w, 's, Q, F>; K],
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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`.
|
||||
|
@ -580,7 +578,7 @@ impl<'w, 's, Q: WorldQueryData, 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: ReadOnlyWorldQueryData, 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];
|
||||
|
@ -623,7 +621,7 @@ impl<'w, 's, Q: ReadOnlyWorldQueryData, F: WorldQueryFilter, const K: usize> Ite
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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,
|
||||
{
|
||||
|
@ -633,12 +631,12 @@ where
|
|||
}
|
||||
|
||||
// This is correct as [`QueryCombinationIter`] always returns `None` once exhausted.
|
||||
impl<'w, 's, Q: ReadOnlyWorldQueryData, 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: WorldQueryData, 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],
|
||||
|
@ -651,7 +649,7 @@ struct QueryIterationCursor<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> {
|
|||
current_row: usize,
|
||||
}
|
||||
|
||||
impl<Q: WorldQueryData, F: WorldQueryFilter> Clone for QueryIterationCursor<'_, '_, Q, F> {
|
||||
impl<Q: QueryData, F: QueryFilter> Clone for QueryIterationCursor<'_, '_, Q, F> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
table_id_iter: self.table_id_iter.clone(),
|
||||
|
@ -666,7 +664,7 @@ impl<Q: WorldQueryData, F: WorldQueryFilter> Clone for QueryIterationCursor<'_,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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(
|
||||
|
|
|
@ -10,7 +10,7 @@ mod state;
|
|||
mod world_query;
|
||||
|
||||
pub use access::*;
|
||||
pub use bevy_ecs_macros::{WorldQueryData, WorldQueryFilter};
|
||||
pub use bevy_ecs_macros::{QueryData, QueryFilter};
|
||||
pub use error::*;
|
||||
pub use fetch::*;
|
||||
pub use filter::*;
|
||||
|
@ -67,10 +67,10 @@ impl<T> DebugCheckedUnwrap for Option<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bevy_ecs_macros::{WorldQueryData, WorldQueryFilter};
|
||||
use bevy_ecs_macros::{QueryData, QueryFilter};
|
||||
|
||||
use crate::prelude::{AnyOf, Changed, Entity, Or, QueryState, With, Without};
|
||||
use crate::query::{ArchetypeFilter, Has, QueryCombinationIter, ReadOnlyWorldQueryData};
|
||||
use crate::query::{ArchetypeFilter, Has, QueryCombinationIter, ReadOnlyQueryData};
|
||||
use crate::schedule::{IntoSystemConfigs, Schedule};
|
||||
use crate::system::{IntoSystem, Query, System, SystemState};
|
||||
use crate::{self as bevy_ecs, component::Component, world::World};
|
||||
|
@ -117,7 +117,7 @@ mod tests {
|
|||
}
|
||||
fn assert_combination<Q, F, const K: usize>(world: &mut World, expected_size: usize)
|
||||
where
|
||||
Q: ReadOnlyWorldQueryData,
|
||||
Q: ReadOnlyQueryData,
|
||||
F: ArchetypeFilter,
|
||||
{
|
||||
let mut query = world.query_filtered::<Q, F>();
|
||||
|
@ -131,7 +131,7 @@ mod tests {
|
|||
}
|
||||
fn assert_all_sizes_equal<Q, F>(world: &mut World, expected_size: usize)
|
||||
where
|
||||
Q: ReadOnlyWorldQueryData,
|
||||
Q: ReadOnlyQueryData,
|
||||
F: ArchetypeFilter,
|
||||
{
|
||||
let mut query = world.query_filtered::<Q, F>();
|
||||
|
@ -501,8 +501,8 @@ mod tests {
|
|||
#[test]
|
||||
#[should_panic = "&mut bevy_ecs::query::tests::A conflicts with a previous access in this query."]
|
||||
fn self_conflicting_worldquery() {
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(mutable)]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(mutable)]
|
||||
struct SelfConflicting {
|
||||
a: &'static mut A,
|
||||
b: &'static mut A,
|
||||
|
@ -538,7 +538,7 @@ mod tests {
|
|||
world.spawn_empty();
|
||||
|
||||
{
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
struct CustomAB {
|
||||
a: &'static A,
|
||||
b: &'static B,
|
||||
|
@ -558,7 +558,7 @@ mod tests {
|
|||
}
|
||||
|
||||
{
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
struct FancyParam {
|
||||
e: Entity,
|
||||
b: &'static B,
|
||||
|
@ -579,11 +579,11 @@ mod tests {
|
|||
}
|
||||
|
||||
{
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
struct MaybeBSparse {
|
||||
blah: Option<(&'static B, &'static Sparse)>,
|
||||
}
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
struct MatchEverything {
|
||||
abcs: AnyOf<(&'static A, &'static B, &'static C)>,
|
||||
opt_bsparse: MaybeBSparse,
|
||||
|
@ -618,11 +618,11 @@ mod tests {
|
|||
}
|
||||
|
||||
{
|
||||
#[derive(WorldQueryFilter)]
|
||||
#[derive(QueryFilter)]
|
||||
struct AOrBFilter {
|
||||
a: Or<(With<A>, With<B>)>,
|
||||
}
|
||||
#[derive(WorldQueryFilter)]
|
||||
#[derive(QueryFilter)]
|
||||
struct NoSparseThatsSlow {
|
||||
no: Without<Sparse>,
|
||||
}
|
||||
|
@ -639,7 +639,7 @@ mod tests {
|
|||
}
|
||||
|
||||
{
|
||||
#[derive(WorldQueryFilter)]
|
||||
#[derive(QueryFilter)]
|
||||
struct CSparseFilter {
|
||||
tuple_structs_pls: With<C>,
|
||||
ugh: With<Sparse>,
|
||||
|
@ -657,7 +657,7 @@ mod tests {
|
|||
}
|
||||
|
||||
{
|
||||
#[derive(WorldQueryFilter)]
|
||||
#[derive(QueryFilter)]
|
||||
struct WithoutComps {
|
||||
_1: Without<A>,
|
||||
_2: Without<B>,
|
||||
|
@ -676,7 +676,7 @@ mod tests {
|
|||
}
|
||||
|
||||
{
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
struct IterCombAB {
|
||||
a: &'static A,
|
||||
b: &'static B,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{component::Tick, world::unsafe_world_cell::UnsafeWorldCell};
|
||||
use std::ops::Range;
|
||||
|
||||
use super::{QueryItem, QueryState, WorldQueryData, 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: WorldQueryData, F: WorldQueryFilter> {
|
||||
pub struct QueryParIter<'w, 's, Q: QueryData, F: QueryFilter> {
|
||||
pub(crate) world: UnsafeWorldCell<'w>,
|
||||
pub(crate) state: &'s QueryState<Q, F>,
|
||||
pub(crate) last_run: Tick,
|
||||
|
@ -90,7 +90,7 @@ pub struct QueryParIter<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> {
|
|||
pub(crate) batching_strategy: BatchingStrategy,
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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
|
||||
|
|
|
@ -17,16 +17,16 @@ use fixedbitset::FixedBitSet;
|
|||
use std::{any::TypeId, borrow::Borrow, fmt, mem::MaybeUninit};
|
||||
|
||||
use super::{
|
||||
NopWorldQuery, QueryComponentError, QueryEntityError, QueryManyIter, QuerySingleError,
|
||||
ROQueryItem, WorldQueryData, WorldQueryFilter,
|
||||
NopWorldQuery, QueryComponentError, QueryData, QueryEntityError, QueryFilter, QueryManyIter,
|
||||
QuerySingleError, ROQueryItem,
|
||||
};
|
||||
|
||||
/// Provides scoped access to a [`World`] state according to a given [`WorldQueryData`] 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<Q: WorldQueryData, F: WorldQueryFilter = ()> {
|
||||
pub struct QueryState<Q: QueryData, F: QueryFilter = ()> {
|
||||
world_id: WorldId,
|
||||
pub(crate) archetype_generation: ArchetypeGeneration,
|
||||
pub(crate) matched_tables: FixedBitSet,
|
||||
|
@ -43,7 +43,7 @@ pub struct QueryState<Q: WorldQueryData, F: WorldQueryFilter = ()> {
|
|||
par_iter_span: Span,
|
||||
}
|
||||
|
||||
impl<Q: WorldQueryData, F: WorldQueryFilter> fmt::Debug for QueryState<Q, F> {
|
||||
impl<Q: QueryData, F: QueryFilter> fmt::Debug for QueryState<Q, F> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("QueryState")
|
||||
.field("world_id", &self.world_id)
|
||||
|
@ -53,13 +53,13 @@ impl<Q: WorldQueryData, F: WorldQueryFilter> fmt::Debug for QueryState<Q, F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Q: WorldQueryData, F: WorldQueryFilter> FromWorld for QueryState<Q, F> {
|
||||
impl<Q: QueryData, F: QueryFilter> FromWorld for QueryState<Q, F> {
|
||||
fn from_world(world: &mut World) -> Self {
|
||||
world.query_filtered()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Q: WorldQueryData, F: WorldQueryFilter> QueryState<Q, F> {
|
||||
impl<Q: QueryData, F: QueryFilter> QueryState<Q, F> {
|
||||
/// Converts this `QueryState` reference to a `QueryState` that does not access anything mutably.
|
||||
pub fn as_readonly(&self) -> &QueryState<Q::ReadOnly, F> {
|
||||
// SAFETY: invariant on `WorldQuery` trait upholds that `Q::ReadOnly` and `F::ReadOnly`
|
||||
|
@ -88,8 +88,8 @@ impl<Q: WorldQueryData, F: WorldQueryFilter> QueryState<Q, F> {
|
|||
/// `NewQ` must have a subset of the access that `Q` does and match the exact same archetypes/tables
|
||||
/// `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: WorldQueryData<State = Q::State>,
|
||||
NewF: WorldQueryFilter<State = F::State>,
|
||||
NewQ: QueryData<State = Q::State>,
|
||||
NewF: QueryFilter<State = F::State>,
|
||||
>(
|
||||
&self,
|
||||
) -> &QueryState<NewQ, NewF> {
|
||||
|
@ -97,7 +97,7 @@ impl<Q: WorldQueryData, F: WorldQueryFilter> QueryState<Q, F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Q: WorldQueryData, F: WorldQueryFilter> QueryState<Q, F> {
|
||||
impl<Q: QueryData, F: QueryFilter> QueryState<Q, F> {
|
||||
/// 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<Q: WorldQueryData, F: WorldQueryFilter> QueryState<Q, F> {
|
|||
///
|
||||
/// # 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(
|
||||
|
|
|
@ -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 [`WorldQueryData`] or [`WorldQueryFilter`]
|
||||
/// Types that implement this should also implement either [`QueryData`] or [`QueryFilter`]
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
|
@ -36,12 +36,12 @@ use bevy_utils::all_tuples;
|
|||
/// [`Query`]: crate::system::Query
|
||||
/// [`update_archetype_component_access`]: Self::update_archetype_component_access
|
||||
/// [`update_component_access`]: Self::update_component_access
|
||||
/// [`WorldQueryData`]: crate::query::WorldQueryData
|
||||
/// [`WorldQueryFilter`]: crate::query::WorldQueryFilter
|
||||
/// [`QueryData`]: crate::query::QueryData
|
||||
/// [`QueryFilter`]: crate::query::QueryFilter
|
||||
pub unsafe trait WorldQuery {
|
||||
/// The item returned by this [`WorldQuery`]
|
||||
/// For `WorldQueryData` 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 `QueryData` this will be the item returned by the query.
|
||||
/// 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>;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
prelude::{FromWorld, QueryState},
|
||||
query::{WorldQueryData, 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> = <P as ExclusiveSystemParam>::Item<'s>;
|
||||
|
||||
impl<'a, Q: WorldQueryData + 'static, F: WorldQueryFilter + 'static> ExclusiveSystemParam
|
||||
impl<'a, Q: QueryData + 'static, F: QueryFilter + 'static> ExclusiveSystemParam
|
||||
for &'a mut QueryState<Q, F>
|
||||
{
|
||||
type State = QueryState<Q, F>;
|
||||
|
|
|
@ -2,9 +2,9 @@ use crate::{
|
|||
component::{Component, Tick},
|
||||
entity::Entity,
|
||||
query::{
|
||||
BatchingStrategy, QueryCombinationIter, QueryComponentError, QueryEntityError, QueryIter,
|
||||
QueryManyIter, QueryParIter, QuerySingleError, QueryState, ROQueryItem,
|
||||
ReadOnlyWorldQueryData, WorldQueryData, WorldQueryFilter,
|
||||
BatchingStrategy, QueryCombinationIter, QueryComponentError, QueryData, QueryEntityError,
|
||||
QueryFilter, QueryIter, QueryManyIter, QueryParIter, QuerySingleError, QueryState,
|
||||
ROQueryItem, ReadOnlyQueryData,
|
||||
},
|
||||
world::{unsafe_world_cell::UnsafeWorldCell, Mut},
|
||||
};
|
||||
|
@ -21,10 +21,10 @@ use std::{any::TypeId, borrow::Borrow};
|
|||
/// - **`Q` (query fetch).**
|
||||
/// The type of data contained in the query item.
|
||||
/// Only entities that match the requested data will generate an item.
|
||||
/// Must implement the [`WorldQueryData`] trait.
|
||||
/// 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);
|
||||
/// ```
|
||||
///
|
||||
/// ## `WorldQueryData` 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: WorldQueryData, 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<Q, F>,
|
||||
|
@ -339,7 +339,7 @@ pub struct Query<'world, 'state, Q: WorldQueryData, F: WorldQueryFilter = ()> {
|
|||
force_read_only_component_access: bool,
|
||||
}
|
||||
|
||||
impl<Q: WorldQueryData, F: WorldQueryFilter> std::fmt::Debug for Query<'_, '_, Q, F> {
|
||||
impl<Q: QueryData, F: QueryFilter> 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<Q: WorldQueryData, F: WorldQueryFilter> std::fmt::Debug for Query<'_, '_, Q
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> Query<'w, 's, Q, F> {
|
||||
impl<'w, 's, Q: QueryData, F: QueryFilter> Query<'w, 's, Q, F> {
|
||||
/// Creates a new query.
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -1433,7 +1433,7 @@ impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> Query<'w, 's, Q, F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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>;
|
||||
|
||||
|
@ -1442,7 +1442,7 @@ impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> IntoIterator for &'w Query<
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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>;
|
||||
|
||||
|
@ -1451,7 +1451,7 @@ impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> IntoIterator for &'w mut Qu
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: ReadOnlyWorldQueryData, 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
|
||||
|
|
|
@ -6,8 +6,8 @@ use crate::{
|
|||
component::{ComponentId, ComponentTicks, Components, Tick},
|
||||
entity::Entities,
|
||||
query::{
|
||||
Access, FilteredAccess, FilteredAccessSet, QueryState, ReadOnlyWorldQueryData,
|
||||
WorldQueryData, 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> = <P as SystemParam>::Item<'w, 's>;
|
||||
|
||||
// SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
|
||||
unsafe impl<'w, 's, Q: ReadOnlyWorldQueryData + '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<Q: WorldQueryData + 'static, F: WorldQueryFilter + 'static> SystemParam
|
||||
for Query<'_, '_, Q, F>
|
||||
{
|
||||
unsafe impl<Q: QueryData + 'static, F: QueryFilter + 'static> SystemParam for Query<'_, '_, Q, F> {
|
||||
type State = QueryState<Q, F>;
|
||||
type Item<'w, 's> = Query<'w, 's, Q, F>;
|
||||
|
||||
|
@ -1568,8 +1566,8 @@ mod tests {
|
|||
pub struct SpecialQuery<
|
||||
'w,
|
||||
's,
|
||||
Q: WorldQueryData + Send + Sync + 'static,
|
||||
F: WorldQueryFilter + Send + Sync + 'static = (),
|
||||
Q: QueryData + Send + Sync + 'static,
|
||||
F: QueryFilter + Send + Sync + 'static = (),
|
||||
> {
|
||||
_query: Query<'w, 's, Q, F>,
|
||||
}
|
||||
|
@ -1690,7 +1688,7 @@ mod tests {
|
|||
#[derive(SystemParam)]
|
||||
pub struct WhereParam<'w, 's, Q>
|
||||
where
|
||||
Q: 'static + WorldQueryData,
|
||||
Q: 'static + QueryData,
|
||||
{
|
||||
_q: Query<'w, 's, Q, ()>,
|
||||
}
|
||||
|
|
|
@ -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, QueryEntityError, QueryState, WorldQueryData, WorldQueryFilter},
|
||||
query::{DebugCheckedUnwrap, QueryData, QueryEntityError, QueryFilter, QueryState},
|
||||
removal_detection::RemovedComponentEvents,
|
||||
schedule::{Schedule, ScheduleLabel, Schedules},
|
||||
storage::{ResourceData, Storages},
|
||||
|
@ -928,7 +928,7 @@ impl World {
|
|||
self.last_change_tick = self.increment_change_tick();
|
||||
}
|
||||
|
||||
/// Returns [`QueryState`] for the given [`WorldQueryData`], which is used to efficiently
|
||||
/// Returns [`QueryState`] for the given [`QueryData`], which is used to efficiently
|
||||
/// run queries on the [`World`] by storing and reusing the [`QueryState`].
|
||||
/// ```
|
||||
/// use bevy_ecs::{component::Component, entity::Entity, world::World};
|
||||
|
@ -991,11 +991,11 @@ impl World {
|
|||
/// ]);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn query<Q: WorldQueryData>(&mut self) -> QueryState<Q, ()> {
|
||||
pub fn query<Q: QueryData>(&mut self) -> QueryState<Q, ()> {
|
||||
self.query_filtered::<Q, ()>()
|
||||
}
|
||||
|
||||
/// Returns [`QueryState`] for the given filtered [`WorldQueryData`], which is used to efficiently
|
||||
/// Returns [`QueryState`] for the given filtered [`QueryData`], which is used to efficiently
|
||||
/// run queries on the [`World`] by storing and reusing the [`QueryState`].
|
||||
/// ```
|
||||
/// use bevy_ecs::{component::Component, entity::Entity, world::World, query::With};
|
||||
|
@ -1015,7 +1015,7 @@ impl World {
|
|||
/// assert_eq!(matching_entities, vec![e2]);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn query_filtered<Q: WorldQueryData, F: WorldQueryFilter>(&mut self) -> QueryState<Q, F> {
|
||||
pub fn query_filtered<Q: QueryData, F: QueryFilter>(&mut self) -> QueryState<Q, F> {
|
||||
QueryState::new(self)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
error[E0277]: the trait bound `&mut A: ReadOnlyWorldQueryData` is not satisfied
|
||||
error[E0277]: the trait bound `&mut A: ReadOnlyQueryData` is not satisfied
|
||||
--> tests/ui/query_iter_combinations_mut_iterator_safety.rs:10:17
|
||||
|
|
||||
10 | is_iterator(iter)
|
||||
| ----------- ^^^^ the trait `ReadOnlyWorldQueryData` is not implemented for `&mut A`
|
||||
| ----------- ^^^^ the trait `ReadOnlyQueryData` is not implemented for `&mut A`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the following other types implement trait `ReadOnlyWorldQueryData`:
|
||||
= help: the following other types implement trait `ReadOnlyQueryData`:
|
||||
bevy_ecs::change_detection::Ref<'__w, T>
|
||||
Has<T>
|
||||
AnyOf<()>
|
||||
|
@ -16,7 +16,7 @@ error[E0277]: the trait bound `&mut A: ReadOnlyWorldQueryData` is not satisfied
|
|||
AnyOf<(F0, F1, F2, F3)>
|
||||
AnyOf<(F0, F1, F2, F3, F4)>
|
||||
and $N others
|
||||
= note: `ReadOnlyWorldQueryData` is implemented for `&A`, but not for `&mut A`
|
||||
= note: `ReadOnlyQueryData` is implemented for `&A`, but not for `&mut A`
|
||||
= note: required for `QueryCombinationIter<'_, '_, &mut A, (), _>` to implement `Iterator`
|
||||
note: required by a bound in `is_iterator`
|
||||
--> tests/ui/query_iter_combinations_mut_iterator_safety.rs:13:19
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
error[E0277]: the trait bound `&mut A: ReadOnlyWorldQueryData` is not satisfied
|
||||
error[E0277]: the trait bound `&mut A: ReadOnlyQueryData` is not satisfied
|
||||
--> tests/ui/query_iter_many_mut_iterator_safety.rs:10:17
|
||||
|
|
||||
10 | is_iterator(iter)
|
||||
| ----------- ^^^^ the trait `ReadOnlyWorldQueryData` is not implemented for `&mut A`
|
||||
| ----------- ^^^^ the trait `ReadOnlyQueryData` is not implemented for `&mut A`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the following other types implement trait `ReadOnlyWorldQueryData`:
|
||||
= help: the following other types implement trait `ReadOnlyQueryData`:
|
||||
bevy_ecs::change_detection::Ref<'__w, T>
|
||||
Has<T>
|
||||
AnyOf<()>
|
||||
|
@ -16,7 +16,7 @@ error[E0277]: the trait bound `&mut A: ReadOnlyWorldQueryData` is not satisfied
|
|||
AnyOf<(F0, F1, F2, F3)>
|
||||
AnyOf<(F0, F1, F2, F3, F4)>
|
||||
and $N others
|
||||
= note: `ReadOnlyWorldQueryData` is implemented for `&A`, but not for `&mut A`
|
||||
= note: `ReadOnlyQueryData` is implemented for `&A`, but not for `&mut A`
|
||||
= note: required for `QueryManyIter<'_, '_, &mut A, (), std::array::IntoIter<bevy_ecs::entity::Entity, 1>>` to implement `Iterator`
|
||||
note: required by a bound in `is_iterator`
|
||||
--> tests/ui/query_iter_many_mut_iterator_safety.rs:13:19
|
||||
|
|
|
@ -6,13 +6,13 @@ warning: unused import: `SystemState`
|
|||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
||||
|
||||
error[E0277]: the trait bound `&'static mut Foo: ReadOnlyWorldQueryData` is not satisfied
|
||||
error[E0277]: the trait bound `&'static mut Foo: ReadOnlyQueryData` is not satisfied
|
||||
--> tests/ui/system_param_derive_readonly.rs:18:23
|
||||
|
|
||||
18 | assert_readonly::<Mutable>();
|
||||
| ^^^^^^^ the trait `ReadOnlyWorldQueryData` is not implemented for `&'static mut Foo`
|
||||
| ^^^^^^^ the trait `ReadOnlyQueryData` is not implemented for `&'static mut Foo`
|
||||
|
|
||||
= help: the following other types implement trait `ReadOnlyWorldQueryData`:
|
||||
= help: the following other types implement trait `ReadOnlyQueryData`:
|
||||
bevy_ecs::change_detection::Ref<'__w, T>
|
||||
Has<T>
|
||||
AnyOf<()>
|
||||
|
@ -22,7 +22,7 @@ error[E0277]: the trait bound `&'static mut Foo: ReadOnlyWorldQueryData` is not
|
|||
AnyOf<(F0, F1, F2, F3)>
|
||||
AnyOf<(F0, F1, F2, F3, F4)>
|
||||
and $N others
|
||||
= note: `ReadOnlyWorldQueryData` is implemented for `&'static Foo`, but not for `&'static mut Foo`
|
||||
= note: `ReadOnlyQueryData` is implemented for `&'static Foo`, but not for `&'static mut Foo`
|
||||
= note: required for `bevy_ecs::system::Query<'_, '_, &'static mut Foo>` to implement `ReadOnlySystemParam`
|
||||
= note: 1 redundant requirement hidden
|
||||
= note: required for `Mutable<'_, '_>` to implement `ReadOnlySystemParam`
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
use bevy_ecs::prelude::*;
|
||||
use bevy_ecs::query::WorldQueryData;
|
||||
use bevy_ecs::query::QueryData;
|
||||
|
||||
#[derive(Component)]
|
||||
struct Foo;
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
struct MutableUnmarked {
|
||||
a: &'static mut Foo,
|
||||
}
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(mutable)]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(mutable)]
|
||||
struct MutableMarked {
|
||||
a: &'static mut Foo,
|
||||
}
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[derive(QueryData)]
|
||||
struct NestedMutableUnmarked {
|
||||
a: MutableMarked,
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
error[E0277]: the trait bound `&'static mut Foo: ReadOnlyWorldQueryData` is not satisfied
|
||||
error[E0277]: the trait bound `&'static mut Foo: ReadOnlyQueryData` is not satisfied
|
||||
--> tests/ui/world_query_derive.rs:9:8
|
||||
|
|
||||
9 | a: &'static mut Foo,
|
||||
| ^^^^^^^^^^^^^^^^ the trait `ReadOnlyWorldQueryData` is not implemented for `&'static mut Foo`
|
||||
| ^^^^^^^^^^^^^^^^ the trait `ReadOnlyQueryData` is not implemented for `&'static mut Foo`
|
||||
|
|
||||
= help: the following other types implement trait `ReadOnlyWorldQueryData`:
|
||||
= help: the following other types implement trait `ReadOnlyQueryData`:
|
||||
MutableUnmarked
|
||||
MutableMarkedReadOnly
|
||||
NestedMutableUnmarked
|
||||
|
@ -17,17 +17,17 @@ error[E0277]: the trait bound `&'static mut Foo: ReadOnlyWorldQueryData` is not
|
|||
note: required by a bound in `_::assert_readonly`
|
||||
--> tests/ui/world_query_derive.rs:7:10
|
||||
|
|
||||
7 | #[derive(WorldQueryData)]
|
||||
| ^^^^^^^^^^^^^^ required by this bound in `assert_readonly`
|
||||
= note: this error originates in the derive macro `WorldQueryData` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
7 | #[derive(QueryData)]
|
||||
| ^^^^^^^^^ required by this bound in `assert_readonly`
|
||||
= note: this error originates in the derive macro `QueryData` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0277]: the trait bound `MutableMarked: ReadOnlyWorldQueryData` is not satisfied
|
||||
error[E0277]: the trait bound `MutableMarked: ReadOnlyQueryData` is not satisfied
|
||||
--> tests/ui/world_query_derive.rs:20:8
|
||||
|
|
||||
20 | a: MutableMarked,
|
||||
| ^^^^^^^^^^^^^ the trait `ReadOnlyWorldQueryData` is not implemented for `MutableMarked`
|
||||
| ^^^^^^^^^^^^^ the trait `ReadOnlyQueryData` is not implemented for `MutableMarked`
|
||||
|
|
||||
= help: the following other types implement trait `ReadOnlyWorldQueryData`:
|
||||
= help: the following other types implement trait `ReadOnlyQueryData`:
|
||||
MutableUnmarked
|
||||
MutableMarkedReadOnly
|
||||
NestedMutableUnmarked
|
||||
|
@ -40,6 +40,6 @@ error[E0277]: the trait bound `MutableMarked: ReadOnlyWorldQueryData` is not sat
|
|||
note: required by a bound in `_::assert_readonly`
|
||||
--> tests/ui/world_query_derive.rs:18:10
|
||||
|
|
||||
18 | #[derive(WorldQueryData)]
|
||||
| ^^^^^^^^^^^^^^ required by this bound in `assert_readonly`
|
||||
= note: this error originates in the derive macro `WorldQueryData` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
18 | #[derive(QueryData)]
|
||||
| ^^^^^^^^^ required by this bound in `assert_readonly`
|
||||
= note: this error originates in the derive macro `QueryData` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
|
|
@ -431,15 +431,15 @@ fn prepare_line_gizmo_bind_group(
|
|||
|
||||
struct SetLineGizmoBindGroup<const I: usize>;
|
||||
impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetLineGizmoBindGroup<I> {
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<DynamicUniformIndex<LineGizmoUniform>>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<DynamicUniformIndex<LineGizmoUniform>>;
|
||||
type Param = SRes<LineGizmoUniformBindgroup>;
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
_view: ROQueryItem<'w, Self::ViewWorldQuery>,
|
||||
uniform_index: ROQueryItem<'w, Self::ItemWorldQuery>,
|
||||
_view: ROQueryItem<'w, Self::ViewData>,
|
||||
uniform_index: ROQueryItem<'w, Self::ItemData>,
|
||||
bind_group: SystemParamItem<'w, '_, Self::Param>,
|
||||
pass: &mut TrackedRenderPass<'w>,
|
||||
) -> RenderCommandResult {
|
||||
|
@ -454,15 +454,15 @@ impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetLineGizmoBindGroup<I>
|
|||
|
||||
struct DrawLineGizmo;
|
||||
impl<P: PhaseItem> RenderCommand<P> for DrawLineGizmo {
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<Handle<LineGizmo>>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<Handle<LineGizmo>>;
|
||||
type Param = SRes<RenderAssets<LineGizmo>>;
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
_view: ROQueryItem<'w, Self::ViewWorldQuery>,
|
||||
handle: ROQueryItem<'w, Self::ItemWorldQuery>,
|
||||
_view: ROQueryItem<'w, Self::ViewData>,
|
||||
handle: ROQueryItem<'w, Self::ItemData>,
|
||||
line_gizmos: SystemParamItem<'w, '_, Self::Param>,
|
||||
pass: &mut TrackedRenderPass<'w>,
|
||||
) -> RenderCommandResult {
|
||||
|
|
|
@ -2,14 +2,14 @@ use std::collections::VecDeque;
|
|||
|
||||
use bevy_ecs::{
|
||||
entity::Entity,
|
||||
query::{WorldQuery, WorldQueryData, 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: WorldQueryData, 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: WorldQueryData, F: WorldQueryFilter> {
|
|||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Parent>;
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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<Item<'w> = &'w Children>,
|
||||
|
@ -78,7 +76,7 @@ impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> HierarchyQueryExt<'w, 's, Q
|
|||
/// An [`Iterator`] of [`Entity`]s over the descendants of an [`Entity`].
|
||||
///
|
||||
/// Traverses the hierarchy breadth-first.
|
||||
pub struct DescendantIter<'w, 's, Q: WorldQueryData, F: WorldQueryFilter>
|
||||
pub struct DescendantIter<'w, 's, Q: QueryData, F: QueryFilter>
|
||||
where
|
||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Children>,
|
||||
{
|
||||
|
@ -86,7 +84,7 @@ where
|
|||
vecdeque: VecDeque<Entity>,
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> DescendantIter<'w, 's, Q, F>
|
||||
impl<'w, 's, Q: QueryData, F: QueryFilter> DescendantIter<'w, 's, Q, F>
|
||||
where
|
||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Children>,
|
||||
{
|
||||
|
@ -104,7 +102,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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<Item<'w> = &'w Children>,
|
||||
{
|
||||
|
@ -122,7 +120,7 @@ where
|
|||
}
|
||||
|
||||
/// An [`Iterator`] of [`Entity`]s over the ancestors of an [`Entity`].
|
||||
pub struct AncestorIter<'w, 's, Q: WorldQueryData, F: WorldQueryFilter>
|
||||
pub struct AncestorIter<'w, 's, Q: QueryData, F: QueryFilter>
|
||||
where
|
||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,
|
||||
{
|
||||
|
@ -130,7 +128,7 @@ where
|
|||
next: Option<Entity>,
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> AncestorIter<'w, 's, Q, F>
|
||||
impl<'w, 's, Q: QueryData, F: QueryFilter> AncestorIter<'w, 's, Q, F>
|
||||
where
|
||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,
|
||||
{
|
||||
|
@ -143,7 +141,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, Q: WorldQueryData, 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<Item<'w> = &'w Parent>,
|
||||
{
|
||||
|
|
|
@ -149,7 +149,7 @@ pub const DEFERRED_LIGHTING_PASS: &str = "deferred_opaque_pbr_lighting_pass_3d";
|
|||
pub struct DeferredOpaquePass3dPbrLightingNode;
|
||||
|
||||
impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ViewUniformOffset,
|
||||
&'static ViewLightsUniformOffset,
|
||||
&'static ViewFogUniformOffset,
|
||||
|
@ -173,7 +173,7 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
|
|||
deferred_lighting_id_depth_texture,
|
||||
camera_3d,
|
||||
deferred_lighting_pipeline,
|
||||
): QueryItem<Self::ViewQuery>,
|
||||
): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let pipeline_cache = world.resource::<PipelineCache>();
|
||||
|
|
|
@ -377,8 +377,8 @@ type DrawMaterial<M> = (
|
|||
pub struct SetMaterialBindGroup<M: Material, const I: usize>(PhantomData<M>);
|
||||
impl<P: PhaseItem, M: Material, const I: usize> RenderCommand<P> for SetMaterialBindGroup<M, I> {
|
||||
type Param = (SRes<RenderMaterials<M>>, SRes<RenderMaterialInstances<M>>);
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = ();
|
||||
type ItemData = ();
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
|
|
@ -874,11 +874,11 @@ pub fn queue_prepass_material_meshes<M: Material>(
|
|||
pub struct SetPrepassViewBindGroup<const I: usize>;
|
||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetPrepassViewBindGroup<I> {
|
||||
type Param = SRes<PrepassViewBindGroup>;
|
||||
type ViewWorldQuery = (
|
||||
type ViewData = (
|
||||
Read<ViewUniformOffset>,
|
||||
Option<Read<PreviousViewProjectionUniformOffset>>,
|
||||
);
|
||||
type ItemWorldQuery = ();
|
||||
type ItemData = ();
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
|
|
@ -448,14 +448,14 @@ impl MeshPipeline {
|
|||
|
||||
impl GetBatchData for MeshPipeline {
|
||||
type Param = SRes<RenderMeshInstances>;
|
||||
type Query = Entity;
|
||||
type QueryFilter = With<Mesh3d>;
|
||||
type Data = Entity;
|
||||
type Filter = With<Mesh3d>;
|
||||
type CompareData = (MaterialBindGroupId, AssetId<Mesh>);
|
||||
type BufferData = MeshUniform;
|
||||
|
||||
fn get_batch_data(
|
||||
mesh_instances: &SystemParamItem<Self::Param>,
|
||||
entity: &QueryItem<Self::Query>,
|
||||
entity: &QueryItem<Self::Data>,
|
||||
) -> (Self::BufferData, Option<Self::CompareData>) {
|
||||
let mesh_instance = mesh_instances
|
||||
.get(entity)
|
||||
|
@ -981,20 +981,20 @@ pub fn prepare_mesh_bind_group(
|
|||
pub struct SetMeshViewBindGroup<const I: usize>;
|
||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshViewBindGroup<I> {
|
||||
type Param = ();
|
||||
type ViewWorldQuery = (
|
||||
type ViewData = (
|
||||
Read<ViewUniformOffset>,
|
||||
Read<ViewLightsUniformOffset>,
|
||||
Read<ViewFogUniformOffset>,
|
||||
Read<MeshViewBindGroup>,
|
||||
);
|
||||
type ItemWorldQuery = ();
|
||||
type ItemData = ();
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
(view_uniform, view_lights, view_fog, mesh_view_bind_group): ROQueryItem<
|
||||
'w,
|
||||
Self::ViewWorldQuery,
|
||||
Self::ViewData,
|
||||
>,
|
||||
_entity: (),
|
||||
_: SystemParamItem<'w, '_, Self::Param>,
|
||||
|
@ -1018,8 +1018,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshBindGroup<I> {
|
|||
SRes<SkinIndices>,
|
||||
SRes<MorphIndices>,
|
||||
);
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = ();
|
||||
type ItemData = ();
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
@ -1081,8 +1081,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshBindGroup<I> {
|
|||
pub struct DrawMesh;
|
||||
impl<P: PhaseItem> RenderCommand<P> for DrawMesh {
|
||||
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMeshInstances>);
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = ();
|
||||
type ItemData = ();
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
item: &P,
|
||||
|
|
|
@ -199,7 +199,7 @@ impl ScreenSpaceAmbientOcclusionQualityLevel {
|
|||
struct SsaoNode {}
|
||||
|
||||
impl ViewNode for SsaoNode {
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ExtractedCamera,
|
||||
&'static SsaoPipelineId,
|
||||
&'static SsaoBindGroups,
|
||||
|
@ -210,7 +210,7 @@ impl ViewNode for SsaoNode {
|
|||
&self,
|
||||
_graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(camera, pipeline_id, bind_groups, view_uniform_offset): QueryItem<Self::ViewQuery>,
|
||||
(camera, pipeline_id, bind_groups, view_uniform_offset): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let pipelines = world.resource::<SsaoPipelines>();
|
||||
|
|
|
@ -38,12 +38,12 @@ pub fn derive_extract_component(input: TokenStream) -> TokenStream {
|
|||
|
||||
TokenStream::from(quote! {
|
||||
impl #impl_generics #bevy_render_path::extract_component::ExtractComponent for #struct_name #type_generics #where_clause {
|
||||
type Query = &'static Self;
|
||||
type Data = &'static Self;
|
||||
|
||||
type Filter = #filter;
|
||||
type Out = Self;
|
||||
|
||||
fn extract_component(item: #bevy_ecs_path::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
|
||||
fn extract_component(item: #bevy_ecs_path::query::QueryItem<'_, Self::Data>) -> Option<Self::Out> {
|
||||
Some(item.clone())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bevy_ecs::{
|
||||
component::Component,
|
||||
prelude::Res,
|
||||
query::{QueryItem, ReadOnlyWorldQueryData, WorldQueryFilter},
|
||||
query::{QueryFilter, QueryItem, ReadOnlyQueryData},
|
||||
system::{Query, ResMut, StaticSystemParam, SystemParam, SystemParamItem},
|
||||
};
|
||||
use bevy_utils::nonmax::NonMaxU32;
|
||||
|
@ -57,8 +57,8 @@ impl<T: PartialEq> BatchMeta<T> {
|
|||
/// items.
|
||||
pub trait GetBatchData {
|
||||
type Param: SystemParam + 'static;
|
||||
type Query: ReadOnlyWorldQueryData;
|
||||
type QueryFilter: WorldQueryFilter;
|
||||
type Data: ReadOnlyQueryData;
|
||||
type Filter: 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.
|
||||
|
@ -72,7 +72,7 @@ pub trait GetBatchData {
|
|||
/// for the `CompareData`.
|
||||
fn get_batch_data(
|
||||
param: &SystemParamItem<Self::Param>,
|
||||
query_item: &QueryItem<Self::Query>,
|
||||
query_item: &QueryItem<Self::Data>,
|
||||
) -> (Self::BufferData, Option<Self::CompareData>);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ pub trait GetBatchData {
|
|||
pub fn batch_and_prepare_render_phase<I: CachedRenderPipelinePhaseItem, F: GetBatchData>(
|
||||
gpu_array_buffer: ResMut<GpuArrayBuffer<F::BufferData>>,
|
||||
mut views: Query<&mut RenderPhase<I>>,
|
||||
query: Query<F::Query, F::QueryFilter>,
|
||||
query: Query<F::Data, F::Filter>,
|
||||
param: StaticSystemParam<F::Param>,
|
||||
) {
|
||||
let gpu_array_buffer = gpu_array_buffer.into_inner();
|
||||
|
|
|
@ -9,7 +9,7 @@ use bevy_asset::{Asset, Handle};
|
|||
use bevy_ecs::{
|
||||
component::Component,
|
||||
prelude::*,
|
||||
query::{QueryItem, ReadOnlyWorldQueryData, WorldQueryFilter},
|
||||
query::{QueryFilter, QueryItem, ReadOnlyQueryData},
|
||||
system::lifetimeless::Read,
|
||||
};
|
||||
use std::{marker::PhantomData, ops::Deref};
|
||||
|
@ -35,10 +35,10 @@ impl<C: Component> DynamicUniformIndex<C> {
|
|||
/// Therefore the component is transferred from the "app world" into the "render world"
|
||||
/// in the [`ExtractSchedule`] step.
|
||||
pub trait ExtractComponent: Component {
|
||||
/// ECS [`ReadOnlyWorldQueryData`] to fetch the components to extract.
|
||||
type Query: ReadOnlyWorldQueryData;
|
||||
/// ECS [`ReadOnlyQueryData`] to fetch the components to extract.
|
||||
type Data: ReadOnlyQueryData;
|
||||
/// Filters the entities with additional constraints.
|
||||
type Filter: WorldQueryFilter;
|
||||
type Filter: QueryFilter;
|
||||
|
||||
/// The output from extraction.
|
||||
///
|
||||
|
@ -58,7 +58,7 @@ pub trait ExtractComponent: Component {
|
|||
// type Out: Component = Self;
|
||||
|
||||
/// Defines how the component is transferred into the "render world".
|
||||
fn extract_component(item: QueryItem<'_, Self::Query>) -> Option<Self::Out>;
|
||||
fn extract_component(item: QueryItem<'_, Self::Data>) -> Option<Self::Out>;
|
||||
}
|
||||
|
||||
/// This plugin prepares the components of the corresponding type for the GPU
|
||||
|
@ -195,12 +195,12 @@ impl<C: ExtractComponent> Plugin for ExtractComponentPlugin<C> {
|
|||
}
|
||||
|
||||
impl<T: Asset> ExtractComponent for Handle<T> {
|
||||
type Query = Read<Handle<T>>;
|
||||
type Data = Read<Handle<T>>;
|
||||
type Filter = ();
|
||||
type Out = Handle<T>;
|
||||
|
||||
#[inline]
|
||||
fn extract_component(handle: QueryItem<'_, Self::Query>) -> Option<Self::Out> {
|
||||
fn extract_component(handle: QueryItem<'_, Self::Data>) -> Option<Self::Out> {
|
||||
Some(handle.clone_weak())
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ impl<T: Asset> ExtractComponent for Handle<T> {
|
|||
fn extract_components<C: ExtractComponent>(
|
||||
mut commands: Commands,
|
||||
mut previous_len: Local<usize>,
|
||||
query: Extract<Query<(Entity, C::Query), C::Filter>>,
|
||||
query: Extract<Query<(Entity, C::Data), C::Filter>>,
|
||||
) {
|
||||
let mut values = Vec::with_capacity(*previous_len);
|
||||
for (entity, query_item) in &query {
|
||||
|
@ -225,7 +225,7 @@ fn extract_components<C: ExtractComponent>(
|
|||
fn extract_visible_components<C: ExtractComponent>(
|
||||
mut commands: Commands,
|
||||
mut previous_len: Local<usize>,
|
||||
query: Extract<Query<(Entity, &ViewVisibility, C::Query), C::Filter>>,
|
||||
query: Extract<Query<(Entity, &ViewVisibility, C::Data), C::Filter>>,
|
||||
) {
|
||||
let mut values = Vec::with_capacity(*previous_len);
|
||||
for (entity, view_visibility, query_item) in &query {
|
||||
|
|
|
@ -11,7 +11,7 @@ use bevy_asset::{Asset, AssetId, Handle};
|
|||
use bevy_derive::{Deref, DerefMut};
|
||||
use bevy_ecs::{
|
||||
prelude::Entity,
|
||||
query::{QueryItem, ReadOnlyWorldQueryData, WorldQueryFilter},
|
||||
query::{QueryFilter, QueryItem, ReadOnlyQueryData},
|
||||
system::{lifetimeless::Read, Query, ResMut, Resource},
|
||||
};
|
||||
use bevy_utils::EntityHashMap;
|
||||
|
@ -28,13 +28,13 @@ use crate::{prelude::ViewVisibility, Extract, ExtractSchedule, RenderApp};
|
|||
/// [`ExtractComponent`](crate::extract_component::ExtractComponent), but
|
||||
/// higher-performance because it avoids the ECS overhead.
|
||||
pub trait ExtractInstance: Send + Sync + Sized + 'static {
|
||||
/// ECS [`ReadOnlyWorldQueryData`] to fetch the components to extract.
|
||||
type Query: ReadOnlyWorldQueryData;
|
||||
/// ECS [`ReadOnlyQueryData`] to fetch the components to extract.
|
||||
type Data: 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<Self>;
|
||||
fn extract(item: QueryItem<'_, Self::Data>) -> Option<Self>;
|
||||
}
|
||||
|
||||
/// This plugin extracts one or more components into the "render world" as
|
||||
|
@ -107,7 +107,7 @@ where
|
|||
|
||||
fn extract_all<EI>(
|
||||
mut extracted_instances: ResMut<ExtractedInstances<EI>>,
|
||||
query: Extract<Query<(Entity, EI::Query), EI::Filter>>,
|
||||
query: Extract<Query<(Entity, EI::Data), EI::Filter>>,
|
||||
) where
|
||||
EI: ExtractInstance,
|
||||
{
|
||||
|
@ -121,7 +121,7 @@ fn extract_all<EI>(
|
|||
|
||||
fn extract_visible<EI>(
|
||||
mut extracted_instances: ResMut<ExtractedInstances<EI>>,
|
||||
query: Extract<Query<(Entity, &ViewVisibility, EI::Query), EI::Filter>>,
|
||||
query: Extract<Query<(Entity, &ViewVisibility, EI::Data), EI::Filter>>,
|
||||
) where
|
||||
EI: ExtractInstance,
|
||||
{
|
||||
|
@ -139,10 +139,10 @@ impl<A> ExtractInstance for AssetId<A>
|
|||
where
|
||||
A: Asset,
|
||||
{
|
||||
type Query = Read<Handle<A>>;
|
||||
type Data = Read<Handle<A>>;
|
||||
type Filter = ();
|
||||
|
||||
fn extract(item: QueryItem<'_, Self::Query>) -> Option<Self> {
|
||||
fn extract(item: QueryItem<'_, Self::Data>) -> Option<Self> {
|
||||
Some(item.id())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
renderer::RenderContext,
|
||||
};
|
||||
use bevy_ecs::{
|
||||
query::{QueryItem, QueryState, ReadOnlyWorldQueryData},
|
||||
query::{QueryItem, QueryState, ReadOnlyQueryData},
|
||||
world::{FromWorld, World},
|
||||
};
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
|
@ -342,7 +342,7 @@ impl Node for RunGraphOnViewNode {
|
|||
pub trait ViewNode {
|
||||
/// The query that will be used on the view entity.
|
||||
/// It is guaranteed to run on the view entity, so there's no need for a filter
|
||||
type ViewQuery: ReadOnlyWorldQueryData;
|
||||
type ViewData: ReadOnlyQueryData;
|
||||
|
||||
/// Updates internal node state using the current render [`World`] prior to the run method.
|
||||
fn update(&mut self, _world: &mut World) {}
|
||||
|
@ -354,7 +354,7 @@ pub trait ViewNode {
|
|||
&self,
|
||||
graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
view_query: QueryItem<Self::ViewQuery>,
|
||||
view_query: QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError>;
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ pub trait ViewNode {
|
|||
///
|
||||
/// This [`Node`] exists to help reduce boilerplate when making a render node that runs on a view.
|
||||
pub struct ViewNodeRunner<N: ViewNode> {
|
||||
view_query: QueryState<N::ViewQuery>,
|
||||
view_query: QueryState<N::ViewData>,
|
||||
node: N,
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::render_phase::{PhaseItem, TrackedRenderPass};
|
|||
use bevy_app::App;
|
||||
use bevy_ecs::{
|
||||
entity::Entity,
|
||||
query::{QueryState, ROQueryItem, ReadOnlyWorldQueryData},
|
||||
query::{QueryState, ROQueryItem, ReadOnlyQueryData},
|
||||
system::{ReadOnlySystemParam, Resource, SystemParam, SystemParamItem, SystemState},
|
||||
world::World,
|
||||
};
|
||||
|
@ -142,8 +142,8 @@ impl<P: PhaseItem> DrawFunctions<P> {
|
|||
/// Compared to the draw function the required ECS data is fetched automatically
|
||||
/// (by the [`RenderCommandState`]) from the render world.
|
||||
/// Therefore the three types [`Param`](RenderCommand::Param),
|
||||
/// [`ViewWorldQuery`](RenderCommand::ViewWorldQuery) and
|
||||
/// [`ItemWorldQuery`](RenderCommand::ItemWorldQuery) are used.
|
||||
/// [`ViewData`](RenderCommand::ViewData) and
|
||||
/// [`ItemData`](RenderCommand::ItemData) are used.
|
||||
/// They specify which information is required to execute the render command.
|
||||
///
|
||||
/// Multiple render commands can be combined together by wrapping them in a tuple.
|
||||
|
@ -179,19 +179,19 @@ pub trait RenderCommand<P: PhaseItem> {
|
|||
/// The view entity refers to the camera, or shadow-casting light, etc. from which the phase
|
||||
/// item will be rendered from.
|
||||
/// All components have to be accessed read only.
|
||||
type ViewWorldQuery: ReadOnlyWorldQueryData;
|
||||
type ViewData: ReadOnlyQueryData;
|
||||
/// Specifies the ECS data of the item entity required by [`RenderCommand::render`].
|
||||
///
|
||||
/// The item is the entity that will be rendered for the corresponding view.
|
||||
/// All components have to be accessed read only.
|
||||
type ItemWorldQuery: ReadOnlyWorldQueryData;
|
||||
type ItemData: ReadOnlyQueryData;
|
||||
|
||||
/// Renders a [`PhaseItem`] by recording commands (e.g. setting pipelines, binding bind groups,
|
||||
/// issuing draw calls, etc.) via the [`TrackedRenderPass`].
|
||||
fn render<'w>(
|
||||
item: &P,
|
||||
view: ROQueryItem<'w, Self::ViewWorldQuery>,
|
||||
entity: ROQueryItem<'w, Self::ItemWorldQuery>,
|
||||
view: ROQueryItem<'w, Self::ViewData>,
|
||||
entity: ROQueryItem<'w, Self::ItemData>,
|
||||
param: SystemParamItem<'w, '_, Self::Param>,
|
||||
pass: &mut TrackedRenderPass<'w>,
|
||||
) -> RenderCommandResult;
|
||||
|
@ -207,14 +207,14 @@ macro_rules! render_command_tuple_impl {
|
|||
($(($name: ident, $view: ident, $entity: ident)),*) => {
|
||||
impl<P: PhaseItem, $($name: RenderCommand<P>),*> RenderCommand<P> for ($($name,)*) {
|
||||
type Param = ($($name::Param,)*);
|
||||
type ViewWorldQuery = ($($name::ViewWorldQuery,)*);
|
||||
type ItemWorldQuery = ($($name::ItemWorldQuery,)*);
|
||||
type ViewData = ($($name::ViewData,)*);
|
||||
type ItemData = ($($name::ItemData,)*);
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
($($view,)*): ROQueryItem<'w, Self::ViewWorldQuery>,
|
||||
($($entity,)*): ROQueryItem<'w, Self::ItemWorldQuery>,
|
||||
($($view,)*): ROQueryItem<'w, Self::ViewData>,
|
||||
($($entity,)*): ROQueryItem<'w, Self::ItemData>,
|
||||
($($name,)*): SystemParamItem<'w, '_, Self::Param>,
|
||||
_pass: &mut TrackedRenderPass<'w>,
|
||||
) -> RenderCommandResult {
|
||||
|
@ -231,12 +231,12 @@ all_tuples!(render_command_tuple_impl, 0, 15, C, V, E);
|
|||
|
||||
/// Wraps a [`RenderCommand`] into a state so that it can be used as a [`Draw`] function.
|
||||
///
|
||||
/// The [`RenderCommand::Param`], [`RenderCommand::ViewWorldQuery`] and
|
||||
/// [`RenderCommand::ItemWorldQuery`] are fetched from the ECS and passed to the command.
|
||||
/// The [`RenderCommand::Param`], [`RenderCommand::ViewData`] and
|
||||
/// [`RenderCommand::ItemData`] are fetched from the ECS and passed to the command.
|
||||
pub struct RenderCommandState<P: PhaseItem + 'static, C: RenderCommand<P>> {
|
||||
state: SystemState<C::Param>,
|
||||
view: QueryState<C::ViewWorldQuery>,
|
||||
entity: QueryState<C::ItemWorldQuery>,
|
||||
view: QueryState<C::ViewData>,
|
||||
entity: QueryState<C::ItemData>,
|
||||
}
|
||||
|
||||
impl<P: PhaseItem, C: RenderCommand<P>> RenderCommandState<P, C> {
|
||||
|
|
|
@ -196,8 +196,8 @@ pub struct SetItemPipeline;
|
|||
|
||||
impl<P: CachedRenderPipelinePhaseItem> RenderCommand<P> for SetItemPipeline {
|
||||
type Param = SRes<PipelineCache>;
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = ();
|
||||
type ItemData = ();
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
item: &P,
|
||||
|
|
|
@ -330,8 +330,8 @@ impl<P: PhaseItem, M: Material2d, const I: usize> RenderCommand<P>
|
|||
SRes<RenderMaterials2d<M>>,
|
||||
SRes<RenderMaterial2dInstances<M>>,
|
||||
);
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = ();
|
||||
type ItemData = ();
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
|
|
@ -339,14 +339,14 @@ impl Mesh2dPipeline {
|
|||
|
||||
impl GetBatchData for Mesh2dPipeline {
|
||||
type Param = SRes<RenderMesh2dInstances>;
|
||||
type Query = Entity;
|
||||
type QueryFilter = With<Mesh2d>;
|
||||
type Data = Entity;
|
||||
type Filter = With<Mesh2d>;
|
||||
type CompareData = (Material2dBindGroupId, AssetId<Mesh>);
|
||||
type BufferData = Mesh2dUniform;
|
||||
|
||||
fn get_batch_data(
|
||||
mesh_instances: &SystemParamItem<Self::Param>,
|
||||
entity: &QueryItem<Self::Query>,
|
||||
entity: &QueryItem<Self::Data>,
|
||||
) -> (Self::BufferData, Option<Self::CompareData>) {
|
||||
let mesh_instance = mesh_instances
|
||||
.get(entity)
|
||||
|
@ -617,13 +617,13 @@ pub fn prepare_mesh2d_view_bind_groups(
|
|||
pub struct SetMesh2dViewBindGroup<const I: usize>;
|
||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dViewBindGroup<I> {
|
||||
type Param = ();
|
||||
type ViewWorldQuery = (Read<ViewUniformOffset>, Read<Mesh2dViewBindGroup>);
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = (Read<ViewUniformOffset>, Read<Mesh2dViewBindGroup>);
|
||||
type ItemData = ();
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
(view_uniform, mesh2d_view_bind_group): ROQueryItem<'w, Self::ViewWorldQuery>,
|
||||
(view_uniform, mesh2d_view_bind_group): ROQueryItem<'w, Self::ViewData>,
|
||||
_view: (),
|
||||
_param: SystemParamItem<'w, '_, Self::Param>,
|
||||
pass: &mut TrackedRenderPass<'w>,
|
||||
|
@ -637,8 +637,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dViewBindGroup<I
|
|||
pub struct SetMesh2dBindGroup<const I: usize>;
|
||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dBindGroup<I> {
|
||||
type Param = SRes<Mesh2dBindGroup>;
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = ();
|
||||
type ItemData = ();
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
@ -666,8 +666,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dBindGroup<I> {
|
|||
pub struct DrawMesh2d;
|
||||
impl<P: PhaseItem> RenderCommand<P> for DrawMesh2d {
|
||||
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMesh2dInstances>);
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = ();
|
||||
type ItemData = ();
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
|
|
@ -766,8 +766,8 @@ pub type DrawSprite = (
|
|||
pub struct SetSpriteViewBindGroup<const I: usize>;
|
||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteViewBindGroup<I> {
|
||||
type Param = SRes<SpriteMeta>;
|
||||
type ViewWorldQuery = Read<ViewUniformOffset>;
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = Read<ViewUniformOffset>;
|
||||
type ItemData = ();
|
||||
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
|
@ -787,8 +787,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteViewBindGroup<I
|
|||
pub struct SetSpriteTextureBindGroup<const I: usize>;
|
||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteTextureBindGroup<I> {
|
||||
type Param = SRes<ImageBindGroups>;
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<SpriteBatch>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<SpriteBatch>;
|
||||
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
|
@ -814,8 +814,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteTextureBindGrou
|
|||
pub struct DrawSpriteBatch;
|
||||
impl<P: PhaseItem> RenderCommand<P> for DrawSpriteBatch {
|
||||
type Param = SRes<SpriteMeta>;
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<SpriteBatch>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<SpriteBatch>;
|
||||
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy_ecs::{
|
|||
change_detection::DetectChangesMut,
|
||||
entity::Entity,
|
||||
prelude::{Component, With},
|
||||
query::WorldQueryData,
|
||||
query::QueryData,
|
||||
reflect::ReflectComponent,
|
||||
system::{Local, Query, Res},
|
||||
};
|
||||
|
@ -105,8 +105,8 @@ pub struct State {
|
|||
}
|
||||
|
||||
/// Main query for [`ui_focus_system`]
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(mutable)]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(mutable)]
|
||||
pub struct NodeQuery {
|
||||
entity: Entity,
|
||||
node: &'static Node,
|
||||
|
|
|
@ -157,8 +157,8 @@ pub type DrawUi = (
|
|||
pub struct SetUiViewBindGroup<const I: usize>;
|
||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiViewBindGroup<I> {
|
||||
type Param = SRes<UiMeta>;
|
||||
type ViewWorldQuery = Read<ViewUniformOffset>;
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = Read<ViewUniformOffset>;
|
||||
type ItemData = ();
|
||||
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
|
@ -178,8 +178,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiViewBindGroup<I> {
|
|||
pub struct SetUiTextureBindGroup<const I: usize>;
|
||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiTextureBindGroup<I> {
|
||||
type Param = SRes<UiImageBindGroups>;
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<UiBatch>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<UiBatch>;
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
@ -197,8 +197,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiTextureBindGroup<I>
|
|||
pub struct DrawUiNode;
|
||||
impl<P: PhaseItem> RenderCommand<P> for DrawUiNode {
|
||||
type Param = SRes<UiMeta>;
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<UiBatch>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<UiBatch>;
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
|
|
@ -263,8 +263,8 @@ pub type DrawUiMaterial<M> = (
|
|||
pub struct SetMatUiViewBindGroup<M: UiMaterial, const I: usize>(PhantomData<M>);
|
||||
impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P> for SetMatUiViewBindGroup<M, I> {
|
||||
type Param = SRes<UiMaterialMeta<M>>;
|
||||
type ViewWorldQuery = Read<ViewUniformOffset>;
|
||||
type ItemWorldQuery = ();
|
||||
type ViewData = Read<ViewUniformOffset>;
|
||||
type ItemData = ();
|
||||
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
|
@ -287,13 +287,13 @@ impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P>
|
|||
for SetUiMaterialBindGroup<M, I>
|
||||
{
|
||||
type Param = SRes<RenderUiMaterials<M>>;
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<UiMaterialBatch<M>>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<UiMaterialBatch<M>>;
|
||||
|
||||
fn render<'w>(
|
||||
_item: &P,
|
||||
_view: (),
|
||||
material_handle: ROQueryItem<'_, Self::ItemWorldQuery>,
|
||||
material_handle: ROQueryItem<'_, Self::ItemData>,
|
||||
materials: SystemParamItem<'w, '_, Self::Param>,
|
||||
pass: &mut TrackedRenderPass<'w>,
|
||||
) -> RenderCommandResult {
|
||||
|
@ -308,8 +308,8 @@ impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P>
|
|||
pub struct DrawUiMaterialNode<M>(PhantomData<M>);
|
||||
impl<P: PhaseItem, M: UiMaterial> RenderCommand<P> for DrawUiMaterialNode<M> {
|
||||
type Param = SRes<UiMaterialMeta<M>>;
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<UiMaterialBatch<M>>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<UiMaterialBatch<M>>;
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//! For more details on the `WorldQuery` derive macro, see the trait documentation.
|
||||
|
||||
use bevy::{
|
||||
ecs::query::{WorldQueryData, WorldQueryFilter},
|
||||
ecs::query::{QueryData, QueryFilter},
|
||||
prelude::*,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
@ -45,8 +45,8 @@ struct ComponentD;
|
|||
#[derive(Component, Debug)]
|
||||
struct ComponentZ;
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(derive(Debug))]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(derive(Debug))]
|
||||
struct ReadOnlyCustomQuery<T: Component + Debug, P: Component + Debug> {
|
||||
entity: Entity,
|
||||
a: &'static ComponentA,
|
||||
|
@ -59,7 +59,10 @@ struct ReadOnlyCustomQuery<T: Component + Debug, P: Component + Debug> {
|
|||
}
|
||||
|
||||
fn print_components_read_only(
|
||||
query: Query<ReadOnlyCustomQuery<ComponentC, ComponentD>, QueryFilter<ComponentC, ComponentD>>,
|
||||
query: Query<
|
||||
ReadOnlyCustomQuery<ComponentC, ComponentD>,
|
||||
CustomQueryFilter<ComponentC, ComponentD>,
|
||||
>,
|
||||
) {
|
||||
println!("Print components (read_only):");
|
||||
for e in &query {
|
||||
|
@ -79,8 +82,8 @@ fn print_components_read_only(
|
|||
// suffix.
|
||||
// Note: if you want to use derive macros with read-only query variants, you need to pass them with
|
||||
// using the `derive` attribute.
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(mutable, derive(Debug))]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(mutable, derive(Debug))]
|
||||
struct CustomQuery<T: Component + Debug, P: Component + Debug> {
|
||||
entity: Entity,
|
||||
a: &'static mut ComponentA,
|
||||
|
@ -93,27 +96,27 @@ struct CustomQuery<T: Component + Debug, P: Component + Debug> {
|
|||
}
|
||||
|
||||
// This is a valid query as well, which would iterate over every entity.
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(derive(Debug))]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(derive(Debug))]
|
||||
struct EmptyQuery {
|
||||
empty: (),
|
||||
}
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(derive(Debug))]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(derive(Debug))]
|
||||
struct NestedQuery {
|
||||
c: &'static ComponentC,
|
||||
d: Option<&'static ComponentD>,
|
||||
}
|
||||
|
||||
#[derive(WorldQueryData)]
|
||||
#[world_query_data(derive(Debug))]
|
||||
#[derive(QueryData)]
|
||||
#[query_data(derive(Debug))]
|
||||
struct GenericQuery<T: Component, P: Component> {
|
||||
generic: (&'static T, &'static P),
|
||||
}
|
||||
|
||||
#[derive(WorldQueryFilter)]
|
||||
struct QueryFilter<T: Component, P: Component> {
|
||||
#[derive(QueryFilter)]
|
||||
struct CustomQueryFilter<T: Component, P: Component> {
|
||||
_c: With<ComponentC>,
|
||||
_d: With<ComponentD>,
|
||||
_or: Or<(Added<ComponentC>, Changed<ComponentD>, Without<ComponentZ>)>,
|
||||
|
@ -125,7 +128,10 @@ fn spawn(mut commands: Commands) {
|
|||
}
|
||||
|
||||
fn print_components_iter_mut(
|
||||
mut query: Query<CustomQuery<ComponentC, ComponentD>, QueryFilter<ComponentC, ComponentD>>,
|
||||
mut query: Query<
|
||||
CustomQuery<ComponentC, ComponentD>,
|
||||
CustomQueryFilter<ComponentC, ComponentD>,
|
||||
>,
|
||||
) {
|
||||
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<CustomQuery<ComponentC, ComponentD>, QueryFilter<ComponentC, ComponentD>>,
|
||||
query: Query<CustomQuery<ComponentC, ComponentD>, CustomQueryFilter<ComponentC, ComponentD>>,
|
||||
) {
|
||||
println!("Print components (iter):");
|
||||
for e in &query {
|
||||
|
|
|
@ -116,7 +116,7 @@ impl ViewNode for PostProcessNode {
|
|||
// but it's not a normal system so we need to define it manually.
|
||||
//
|
||||
// This query will only run on the view entity
|
||||
type ViewQuery = (
|
||||
type ViewData = (
|
||||
&'static ViewTarget,
|
||||
// This makes sure the node only runs on cameras with the PostProcessSettings component
|
||||
&'static PostProcessSettings,
|
||||
|
@ -133,7 +133,7 @@ impl ViewNode for PostProcessNode {
|
|||
&self,
|
||||
_graph: &mut RenderGraphContext,
|
||||
render_context: &mut RenderContext,
|
||||
(view_target, _post_process_settings): QueryItem<Self::ViewQuery>,
|
||||
(view_target, _post_process_settings): QueryItem<Self::ViewData>,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
// Get the pipeline resource that contains the global data we need
|
||||
|
|
|
@ -68,11 +68,11 @@ fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
|
|||
struct InstanceMaterialData(Vec<InstanceData>);
|
||||
|
||||
impl ExtractComponent for InstanceMaterialData {
|
||||
type Query = &'static InstanceMaterialData;
|
||||
type Data = &'static InstanceMaterialData;
|
||||
type Filter = ();
|
||||
type Out = Self;
|
||||
|
||||
fn extract_component(item: QueryItem<'_, Self::Query>) -> Option<Self> {
|
||||
fn extract_component(item: QueryItem<'_, Self::Data>) -> Option<Self> {
|
||||
Some(InstanceMaterialData(item.0.clone()))
|
||||
}
|
||||
}
|
||||
|
@ -237,8 +237,8 @@ pub struct DrawMeshInstanced;
|
|||
|
||||
impl<P: PhaseItem> RenderCommand<P> for DrawMeshInstanced {
|
||||
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMeshInstances>);
|
||||
type ViewWorldQuery = ();
|
||||
type ItemWorldQuery = Read<InstanceBuffer>;
|
||||
type ViewData = ();
|
||||
type ItemData = Read<InstanceBuffer>;
|
||||
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
|
|
Loading…
Reference in a new issue