Skip to content

Commit

Permalink
Rename WorldQueryData & WorldQueryFilter to QueryData & `QueryF…
Browse files Browse the repository at this point in the history
…ilter` (#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 {
        // ...
    }
}
```
  • Loading branch information
taizu-jin authored Dec 12, 2023
1 parent 79641c7 commit 5af2f02
Show file tree
Hide file tree
Showing 57 changed files with 413 additions and 416 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_core/src/name.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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>,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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>();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/bloom/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl CopyDeferredLightingIdNode {
}

impl ViewNode for CopyDeferredLightingIdNode {
type ViewQuery = (
type ViewData = (
&'static ViewTarget,
&'static ViewPrepassTextures,
&'static DeferredLightingIdDepthTexture,
Expand All @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/deferred/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/fxaa/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct FxaaNode {
}

impl ViewNode for FxaaNode {
type ViewQuery = (
type ViewData = (
&'static ViewTarget,
&'static CameraFxaaPipeline,
&'static Fxaa,
Expand All @@ -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>();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/prepass/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/taa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/tonemapping/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct TonemappingNode {
}

impl ViewNode for TonemappingNode {
type ViewQuery = (
type ViewData = (
&'static ViewUniformOffset,
&'static ViewTarget,
&'static ViewTonemappingPipeline,
Expand All @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/upscaling/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct UpscalingNode {
}

impl ViewNode for UpscalingNode {
type ViewQuery = (
type ViewData = (
&'static ViewTarget,
&'static ViewUpscalingPipeline,
Option<&'static ExtractedCamera>,
Expand All @@ -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();
Expand Down
25 changes: 11 additions & 14 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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`.
Expand Down
Loading

0 comments on commit 5af2f02

Please sign in to comment.