mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +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_ecs::{component::Component, entity::Entity, reflect::ReflectComponent};
|
||||||
|
|
||||||
use bevy_reflect::std_traits::ReflectDefault;
|
use bevy_reflect::std_traits::ReflectDefault;
|
||||||
|
@ -102,7 +102,7 @@ impl std::fmt::Debug for Name {
|
||||||
/// }
|
/// }
|
||||||
/// # bevy_ecs::system::assert_is_system(increment_score);
|
/// # bevy_ecs::system::assert_is_system(increment_score);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
pub struct DebugName {
|
pub struct DebugName {
|
||||||
/// A [`Name`] that the entity might have that is displayed if available.
|
/// A [`Name`] that the entity might have that is displayed if available.
|
||||||
pub name: Option<&'static Name>,
|
pub name: Option<&'static Name>,
|
||||||
|
|
|
@ -113,7 +113,7 @@ impl Plugin for BloomPlugin {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct BloomNode;
|
struct BloomNode;
|
||||||
impl ViewNode for BloomNode {
|
impl ViewNode for BloomNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ExtractedCamera,
|
&'static ExtractedCamera,
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
&'static BloomTexture,
|
&'static BloomTexture,
|
||||||
|
@ -140,7 +140,7 @@ impl ViewNode for BloomNode {
|
||||||
bloom_settings,
|
bloom_settings,
|
||||||
upsampling_pipeline_ids,
|
upsampling_pipeline_ids,
|
||||||
downsampling_pipeline_ids,
|
downsampling_pipeline_ids,
|
||||||
): QueryItem<Self::ViewQuery>,
|
): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let downsampling_pipeline_res = world.resource::<BloomDownsamplingPipeline>();
|
let downsampling_pipeline_res = world.resource::<BloomDownsamplingPipeline>();
|
||||||
|
|
|
@ -182,12 +182,12 @@ pub enum BloomCompositeMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtractComponent for BloomSettings {
|
impl ExtractComponent for BloomSettings {
|
||||||
type Query = (&'static Self, &'static Camera);
|
type Data = (&'static Self, &'static Camera);
|
||||||
|
|
||||||
type Filter = ();
|
type Filter = ();
|
||||||
type Out = (Self, BloomUniforms);
|
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 (
|
match (
|
||||||
camera.physical_viewport_rect(),
|
camera.physical_viewport_rect(),
|
||||||
camera.physical_viewport_size(),
|
camera.physical_viewport_size(),
|
||||||
|
|
|
@ -77,11 +77,11 @@ pub struct CASUniform {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtractComponent for ContrastAdaptiveSharpeningSettings {
|
impl ExtractComponent for ContrastAdaptiveSharpeningSettings {
|
||||||
type Query = &'static Self;
|
type Data = &'static Self;
|
||||||
type Filter = With<Camera>;
|
type Filter = With<Camera>;
|
||||||
type Out = (DenoiseCAS, CASUniform);
|
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 {
|
if !item.enabled || item.sharpening_strength == 0.0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ use super::{AlphaMask3d, Camera3dDepthLoadOp};
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MainOpaquePass3dNode;
|
pub struct MainOpaquePass3dNode;
|
||||||
impl ViewNode for MainOpaquePass3dNode {
|
impl ViewNode for MainOpaquePass3dNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ExtractedCamera,
|
&'static ExtractedCamera,
|
||||||
&'static RenderPhase<Opaque3d>,
|
&'static RenderPhase<Opaque3d>,
|
||||||
&'static RenderPhase<AlphaMask3d>,
|
&'static RenderPhase<AlphaMask3d>,
|
||||||
|
@ -58,7 +58,7 @@ impl ViewNode for MainOpaquePass3dNode {
|
||||||
skybox_pipeline,
|
skybox_pipeline,
|
||||||
skybox_bind_group,
|
skybox_bind_group,
|
||||||
view_uniform_offset,
|
view_uniform_offset,
|
||||||
): QueryItem<Self::ViewQuery>,
|
): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let load = if deferred_prepass.is_none() {
|
let load = if deferred_prepass.is_none() {
|
||||||
|
|
|
@ -20,7 +20,7 @@ use std::ops::Range;
|
||||||
pub struct MainTransmissivePass3dNode;
|
pub struct MainTransmissivePass3dNode;
|
||||||
|
|
||||||
impl ViewNode for MainTransmissivePass3dNode {
|
impl ViewNode for MainTransmissivePass3dNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ExtractedCamera,
|
&'static ExtractedCamera,
|
||||||
&'static Camera3d,
|
&'static Camera3d,
|
||||||
&'static RenderPhase<Transmissive3d>,
|
&'static RenderPhase<Transmissive3d>,
|
||||||
|
@ -34,7 +34,7 @@ impl ViewNode for MainTransmissivePass3dNode {
|
||||||
graph: &mut RenderGraphContext,
|
graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
(camera, camera_3d, transmissive_phase, target, transmission, depth): QueryItem<
|
(camera, camera_3d, transmissive_phase, target, transmission, depth): QueryItem<
|
||||||
Self::ViewQuery,
|
Self::ViewData,
|
||||||
>,
|
>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
|
|
|
@ -16,7 +16,7 @@ use bevy_utils::tracing::info_span;
|
||||||
pub struct MainTransparentPass3dNode;
|
pub struct MainTransparentPass3dNode;
|
||||||
|
|
||||||
impl ViewNode for MainTransparentPass3dNode {
|
impl ViewNode for MainTransparentPass3dNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ExtractedCamera,
|
&'static ExtractedCamera,
|
||||||
&'static RenderPhase<Transparent3d>,
|
&'static RenderPhase<Transparent3d>,
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
|
@ -26,7 +26,7 @@ impl ViewNode for MainTransparentPass3dNode {
|
||||||
&self,
|
&self,
|
||||||
graph: &mut RenderGraphContext,
|
graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
(camera, transparent_phase, target, depth): QueryItem<Self::ViewQuery>,
|
(camera, transparent_phase, target, depth): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let view_entity = graph.view_entity();
|
let view_entity = graph.view_entity();
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl CopyDeferredLightingIdNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ViewNode for CopyDeferredLightingIdNode {
|
impl ViewNode for CopyDeferredLightingIdNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
&'static ViewPrepassTextures,
|
&'static ViewPrepassTextures,
|
||||||
&'static DeferredLightingIdDepthTexture,
|
&'static DeferredLightingIdDepthTexture,
|
||||||
|
@ -72,7 +72,7 @@ impl ViewNode for CopyDeferredLightingIdNode {
|
||||||
_graph: &mut RenderGraphContext,
|
_graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
(_view_target, view_prepass_textures, deferred_lighting_id_depth_texture): QueryItem<
|
(_view_target, view_prepass_textures, deferred_lighting_id_depth_texture): QueryItem<
|
||||||
Self::ViewQuery,
|
Self::ViewData,
|
||||||
>,
|
>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
|
|
|
@ -29,7 +29,7 @@ use super::{AlphaMask3dDeferred, Opaque3dDeferred};
|
||||||
pub struct DeferredGBufferPrepassNode;
|
pub struct DeferredGBufferPrepassNode;
|
||||||
|
|
||||||
impl ViewNode for DeferredGBufferPrepassNode {
|
impl ViewNode for DeferredGBufferPrepassNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ExtractedCamera,
|
&'static ExtractedCamera,
|
||||||
&'static RenderPhase<Opaque3dDeferred>,
|
&'static RenderPhase<Opaque3dDeferred>,
|
||||||
&'static RenderPhase<AlphaMask3dDeferred>,
|
&'static RenderPhase<AlphaMask3dDeferred>,
|
||||||
|
@ -55,7 +55,7 @@ impl ViewNode for DeferredGBufferPrepassNode {
|
||||||
depth_prepass,
|
depth_prepass,
|
||||||
normal_prepass,
|
normal_prepass,
|
||||||
motion_vector_prepass,
|
motion_vector_prepass,
|
||||||
): QueryItem<Self::ViewQuery>,
|
): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let view_entity = graph.view_entity();
|
let view_entity = graph.view_entity();
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct FxaaNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ViewNode for FxaaNode {
|
impl ViewNode for FxaaNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
&'static CameraFxaaPipeline,
|
&'static CameraFxaaPipeline,
|
||||||
&'static Fxaa,
|
&'static Fxaa,
|
||||||
|
@ -30,7 +30,7 @@ impl ViewNode for FxaaNode {
|
||||||
&self,
|
&self,
|
||||||
_graph: &mut RenderGraphContext,
|
_graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
(target, pipeline, fxaa): QueryItem<Self::ViewQuery>,
|
(target, pipeline, fxaa): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let pipeline_cache = world.resource::<PipelineCache>();
|
let pipeline_cache = world.resource::<PipelineCache>();
|
||||||
|
|
|
@ -25,7 +25,7 @@ use super::{AlphaMask3dPrepass, DeferredPrepass, Opaque3dPrepass, ViewPrepassTex
|
||||||
pub struct PrepassNode;
|
pub struct PrepassNode;
|
||||||
|
|
||||||
impl ViewNode for PrepassNode {
|
impl ViewNode for PrepassNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ExtractedCamera,
|
&'static ExtractedCamera,
|
||||||
&'static RenderPhase<Opaque3dPrepass>,
|
&'static RenderPhase<Opaque3dPrepass>,
|
||||||
&'static RenderPhase<AlphaMask3dPrepass>,
|
&'static RenderPhase<AlphaMask3dPrepass>,
|
||||||
|
@ -45,7 +45,7 @@ impl ViewNode for PrepassNode {
|
||||||
view_depth_texture,
|
view_depth_texture,
|
||||||
view_prepass_textures,
|
view_prepass_textures,
|
||||||
deferred_prepass,
|
deferred_prepass,
|
||||||
): QueryItem<Self::ViewQuery>,
|
): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let view_entity = graph.view_entity();
|
let view_entity = graph.view_entity();
|
||||||
|
|
|
@ -168,7 +168,7 @@ impl Default for TemporalAntiAliasSettings {
|
||||||
pub struct TemporalAntiAliasNode;
|
pub struct TemporalAntiAliasNode;
|
||||||
|
|
||||||
impl ViewNode for TemporalAntiAliasNode {
|
impl ViewNode for TemporalAntiAliasNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ExtractedCamera,
|
&'static ExtractedCamera,
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
&'static TemporalAntiAliasHistoryTextures,
|
&'static TemporalAntiAliasHistoryTextures,
|
||||||
|
@ -181,7 +181,7 @@ impl ViewNode for TemporalAntiAliasNode {
|
||||||
_graph: &mut RenderGraphContext,
|
_graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
(camera, view_target, taa_history_textures, prepass_textures, taa_pipeline_id): QueryItem<
|
(camera, view_target, taa_history_textures, prepass_textures, taa_pipeline_id): QueryItem<
|
||||||
Self::ViewQuery,
|
Self::ViewData,
|
||||||
>,
|
>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub struct TonemappingNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ViewNode for TonemappingNode {
|
impl ViewNode for TonemappingNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ViewUniformOffset,
|
&'static ViewUniformOffset,
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
&'static ViewTonemappingPipeline,
|
&'static ViewTonemappingPipeline,
|
||||||
|
@ -36,7 +36,7 @@ impl ViewNode for TonemappingNode {
|
||||||
_graph: &mut RenderGraphContext,
|
_graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
(view_uniform_offset, target, view_tonemapping_pipeline, tonemapping): QueryItem<
|
(view_uniform_offset, target, view_tonemapping_pipeline, tonemapping): QueryItem<
|
||||||
Self::ViewQuery,
|
Self::ViewData,
|
||||||
>,
|
>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub struct UpscalingNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ViewNode for UpscalingNode {
|
impl ViewNode for UpscalingNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
&'static ViewUpscalingPipeline,
|
&'static ViewUpscalingPipeline,
|
||||||
Option<&'static ExtractedCamera>,
|
Option<&'static ExtractedCamera>,
|
||||||
|
@ -28,7 +28,7 @@ impl ViewNode for UpscalingNode {
|
||||||
&self,
|
&self,
|
||||||
_graph: &mut RenderGraphContext,
|
_graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
(target, upscaling_target, camera): QueryItem<Self::ViewQuery>,
|
(target, upscaling_target, camera): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let pipeline_cache = world.get_resource::<PipelineCache>().unwrap();
|
let pipeline_cache = world.get_resource::<PipelineCache>().unwrap();
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
mod component;
|
mod component;
|
||||||
|
mod query_data;
|
||||||
|
mod query_filter;
|
||||||
mod states;
|
mod states;
|
||||||
mod world_query;
|
mod world_query;
|
||||||
mod world_query_data;
|
|
||||||
mod world_query_filter;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{query_data::derive_query_data_impl, query_filter::derive_query_filter_impl};
|
||||||
world_query_data::derive_world_query_data_impl,
|
|
||||||
world_query_filter::derive_world_query_filter_impl,
|
|
||||||
};
|
|
||||||
use bevy_macro_utils::{derive_label, ensure_no_collision, get_struct_fields, BevyManifest};
|
use bevy_macro_utils::{derive_label, ensure_no_collision, get_struct_fields, BevyManifest};
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2::Span;
|
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
|
/// Implement `QueryData` to use a struct as a data parameter in a query
|
||||||
#[proc_macro_derive(WorldQueryData, attributes(world_query_data))]
|
#[proc_macro_derive(QueryData, attributes(query_data))]
|
||||||
pub fn derive_world_query_data(input: TokenStream) -> TokenStream {
|
pub fn derive_query_data(input: TokenStream) -> TokenStream {
|
||||||
derive_world_query_data_impl(input)
|
derive_query_data_impl(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement `WorldQueryFilter` to use a struct as a filter parameter in a query
|
/// Implement `QueryFilter` to use a struct as a filter parameter in a query
|
||||||
#[proc_macro_derive(WorldQueryFilter, attributes(world_query_filter))]
|
#[proc_macro_derive(QueryFilter, attributes(query_filter))]
|
||||||
pub fn derive_world_query_filter(input: TokenStream) -> TokenStream {
|
pub fn derive_query_filter(input: TokenStream) -> TokenStream {
|
||||||
derive_world_query_filter_impl(input)
|
derive_query_filter_impl(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Derive macro generating an impl of the trait `ScheduleLabel`.
|
/// Derive macro generating an impl of the trait `ScheduleLabel`.
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct WorldQueryDataAttributes {
|
struct QueryDataAttributes {
|
||||||
pub is_mutable: bool,
|
pub is_mutable: bool,
|
||||||
|
|
||||||
pub derive_args: Punctuated<Meta, syn::token::Comma>,
|
pub derive_args: Punctuated<Meta, syn::token::Comma>,
|
||||||
|
@ -29,20 +29,20 @@ mod field_attr_keywords {
|
||||||
syn::custom_keyword!(ignore);
|
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 tokens = input.clone();
|
||||||
|
|
||||||
let ast = parse_macro_input!(input as DeriveInput);
|
let ast = parse_macro_input!(input as DeriveInput);
|
||||||
let visibility = ast.vis;
|
let visibility = ast.vis;
|
||||||
|
|
||||||
let mut attributes = WorldQueryDataAttributes::default();
|
let mut attributes = QueryDataAttributes::default();
|
||||||
for attr in &ast.attrs {
|
for attr in &ast.attrs {
|
||||||
if !attr
|
if !attr
|
||||||
.path()
|
.path()
|
||||||
.get_ident()
|
.get_ident()
|
||||||
.map_or(false, |ident| ident == WORLD_QUERY_DATA_ATTRIBUTE_NAME)
|
.map_or(false, |ident| ident == QUERY_DATA_ATTRIBUTE_NAME)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
Ok(())
|
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();
|
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 {
|
let Data::Struct(DataStruct { fields, .. }) = &ast.data else {
|
||||||
return syn::Error::new(
|
return syn::Error::new(
|
||||||
Span::call_site(),
|
Span::call_site(),
|
||||||
"#[derive(WorldQueryData)]` only supports structs",
|
"#[derive(QueryData)]` only supports structs",
|
||||||
)
|
)
|
||||||
.into_compile_error()
|
.into_compile_error()
|
||||||
.into();
|
.into();
|
||||||
|
@ -151,7 +151,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
||||||
let mut read_only_field_types = Vec::new();
|
let mut read_only_field_types = Vec::new();
|
||||||
for (i, field) in fields.iter().enumerate() {
|
for (i, field) in fields.iter().enumerate() {
|
||||||
let attrs = match read_world_query_field_info(field) {
|
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(),
|
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());
|
field_visibilities.push(field.vis.clone());
|
||||||
let field_ty = field.ty.clone();
|
let field_ty = field.ty.clone();
|
||||||
field_types.push(quote!(#field_ty));
|
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;
|
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 {
|
let read_only_data_impl = if attributes.is_mutable {
|
||||||
quote! {
|
quote! {
|
||||||
/// SAFETY: we assert fields are readonly below
|
/// 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 {
|
for #read_only_struct_name #user_ty_generics #user_where_clauses {
|
||||||
type ReadOnly = #read_only_struct_name #user_ty_generics;
|
type ReadOnly = #read_only_struct_name #user_ty_generics;
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
/// SAFETY: we assert fields are readonly below
|
/// 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 {
|
for #struct_name #user_ty_generics #user_where_clauses {
|
||||||
type ReadOnly = #read_only_struct_name #user_ty_generics;
|
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! {
|
let read_only_data_impl = quote! {
|
||||||
/// SAFETY: we assert fields are readonly below
|
/// 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 {}
|
for #read_only_struct_name #user_ty_generics #user_where_clauses {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_only_asserts = if attributes.is_mutable {
|
let read_only_asserts = if attributes.is_mutable {
|
||||||
quote! {
|
quote! {
|
||||||
// Double-check that the data fetched by `<_ as WorldQuery>::ReadOnly` is read-only.
|
// Double-check that the data fetched by `<_ as WorldQuery>::ReadOnly` is read-only.
|
||||||
// This is technically unnecessary as `<_ as WorldQuery>::ReadOnly: ReadOnlyWorldQueryData`
|
// This is technically unnecessary as `<_ as WorldQuery>::ReadOnly: ReadOnlyQueryData`
|
||||||
// but to protect against future mistakes we assert the assoc type implements `ReadOnlyWorldQueryData` anyway
|
// but to protect against future mistakes we assert the assoc type implements `ReadOnlyQueryData` anyway
|
||||||
#( assert_readonly::<#read_only_field_types>(); )*
|
#( assert_readonly::<#read_only_field_types>(); )*
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
// Statically checks that the safety guarantee of `ReadOnlyWorldQueryData` for `$fetch_struct_name` actually holds true.
|
// 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 `ReadOnlyWorldQueryData` if our struct contains nested `WorldQueryData`
|
// 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.:
|
// members that don't implement it. I.e.:
|
||||||
// ```
|
// ```
|
||||||
// #[derive(WorldQueryData)]
|
// #[derive(QueryData)]
|
||||||
// pub struct Foo { a: &'static mut MyComponent }
|
// pub struct Foo { a: &'static mut MyComponent }
|
||||||
// ```
|
// ```
|
||||||
#( assert_readonly::<#field_types>(); )*
|
#( assert_readonly::<#field_types>(); )*
|
||||||
|
@ -352,13 +352,13 @@ pub fn derive_world_query_data_impl(input: TokenStream) -> TokenStream {
|
||||||
const _: () = {
|
const _: () = {
|
||||||
fn assert_readonly<T>()
|
fn assert_readonly<T>()
|
||||||
where
|
where
|
||||||
T: #path::query::ReadOnlyWorldQueryData,
|
T: #path::query::ReadOnlyQueryData,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_data<T>()
|
fn assert_data<T>()
|
||||||
where
|
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 {
|
struct QueryDataFieldInfo {
|
||||||
/// All field attributes except for `world_query_data` ones.
|
/// All field attributes except for `query_data` ones.
|
||||||
attrs: Vec<Attribute>,
|
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();
|
let mut attrs = Vec::new();
|
||||||
for attr in &field.attrs {
|
for attr in &field.attrs {
|
||||||
if attr
|
if attr
|
||||||
.path()
|
.path()
|
||||||
.get_ident()
|
.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(
|
return Err(syn::Error::new_spanned(
|
||||||
attr,
|
attr,
|
||||||
"#[derive(WorldQueryData)] does not support field attributes.",
|
"#[derive(QueryData)] does not support field attributes.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
attrs.push(attr.clone());
|
attrs.push(attr.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(WorldQueryDataFieldInfo { attrs })
|
Ok(QueryDataFieldInfo { attrs })
|
||||||
}
|
}
|
|
@ -13,7 +13,7 @@ mod field_attr_keywords {
|
||||||
syn::custom_keyword!(ignore);
|
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 tokens = input.clone();
|
||||||
|
|
||||||
let ast = parse_macro_input!(input as DeriveInput);
|
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! {
|
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 {
|
for #struct_name #user_ty_generics #user_where_clauses {
|
||||||
const IS_ARCHETYPAL: bool = true #(&& <#field_types>::IS_ARCHETYPAL)*;
|
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>()
|
fn assert_filter<T>()
|
||||||
where
|
where
|
||||||
T: #path::query::WorldQueryFilter,
|
T: #path::query::QueryFilter,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ mod tests {
|
||||||
change_detection::Ref,
|
change_detection::Ref,
|
||||||
component::{Component, ComponentId},
|
component::{Component, ComponentId},
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
query::{Added, Changed, FilteredAccess, With, Without, WorldQueryFilter},
|
query::{Added, Changed, FilteredAccess, QueryFilter, With, Without},
|
||||||
system::Resource,
|
system::Resource,
|
||||||
world::{EntityRef, Mut, World},
|
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
|
world
|
||||||
.query_filtered::<Entity, F>()
|
.query_filtered::<Entity, F>()
|
||||||
.iter(world)
|
.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
|
world
|
||||||
.query_filtered::<Entity, F>()
|
.query_filtered::<Entity, F>()
|
||||||
.iter(world)
|
.iter(world)
|
||||||
|
|
|
@ -17,8 +17,8 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
///
|
///
|
||||||
/// - **Component references.**
|
/// - **Component references.**
|
||||||
/// Fetches a component by reference (immutably or mutably).
|
/// Fetches a component by reference (immutably or mutably).
|
||||||
/// - **`WorldQueryData` tuples.**
|
/// - **`QueryData` tuples.**
|
||||||
/// If every element of a tuple implements `WorldQueryData`, then the tuple itself also implements the same trait.
|
/// 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.
|
/// 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,
|
/// 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.
|
/// but nesting of tuples allows infinite `WorldQuery`s.
|
||||||
|
@ -39,8 +39,8 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
///
|
///
|
||||||
/// # Trait derivation
|
/// # Trait derivation
|
||||||
///
|
///
|
||||||
/// Query design can be easily structured by deriving `WorldQueryData` for custom types.
|
/// Query design can be easily structured by deriving `QueryData` for custom types.
|
||||||
/// Despite the added complexity, this approach has several advantages over using `WorldQueryData` tuples.
|
/// Despite the added complexity, this approach has several advantages over using `QueryData` tuples.
|
||||||
/// The most relevant improvements are:
|
/// The most relevant improvements are:
|
||||||
///
|
///
|
||||||
/// - Reusability across multiple systems.
|
/// - Reusability across multiple systems.
|
||||||
|
@ -49,18 +49,18 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
/// - Methods can be implemented for the query items.
|
/// - Methods can be implemented for the query items.
|
||||||
/// - There is no hardcoded limit on the number of elements.
|
/// - 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::prelude::*;
|
||||||
/// use bevy_ecs::query::WorldQueryData;
|
/// use bevy_ecs::query::QueryData;
|
||||||
/// #
|
/// #
|
||||||
/// # #[derive(Component)]
|
/// # #[derive(Component)]
|
||||||
/// # struct ComponentA;
|
/// # struct ComponentA;
|
||||||
/// # #[derive(Component)]
|
/// # #[derive(Component)]
|
||||||
/// # struct ComponentB;
|
/// # struct ComponentB;
|
||||||
///
|
///
|
||||||
/// #[derive(WorldQueryData)]
|
/// #[derive(QueryData)]
|
||||||
/// struct MyQuery {
|
/// struct MyQuery {
|
||||||
/// entity: Entity,
|
/// entity: Entity,
|
||||||
/// // It is required that all reference lifetimes are explicitly annotated, just like in any
|
/// // 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
|
/// ## 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
|
/// ```compile_fail
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_ecs::query::WorldQueryData;
|
/// # use bevy_ecs::query::QueryData;
|
||||||
/// #
|
/// #
|
||||||
/// # #[derive(Component)]
|
/// # #[derive(Component)]
|
||||||
/// # struct ComponentA;
|
/// # struct ComponentA;
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(WorldQueryData)]
|
/// #[derive(QueryData)]
|
||||||
/// struct CustomQuery {
|
/// struct CustomQuery {
|
||||||
/// component_a: &'static mut ComponentA,
|
/// 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).
|
/// 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::prelude::*;
|
||||||
/// # use bevy_ecs::query::WorldQueryData;
|
/// # use bevy_ecs::query::QueryData;
|
||||||
/// #
|
/// #
|
||||||
/// # #[derive(Component)]
|
/// # #[derive(Component)]
|
||||||
/// # struct ComponentA;
|
/// # struct ComponentA;
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(WorldQueryData)]
|
/// #[derive(QueryData)]
|
||||||
/// #[world_query_data(mutable)]
|
/// #[query_data(mutable)]
|
||||||
/// struct CustomQuery {
|
/// struct CustomQuery {
|
||||||
/// component_a: &'static mut ComponentA,
|
/// component_a: &'static mut ComponentA,
|
||||||
/// }
|
/// }
|
||||||
|
@ -130,7 +130,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_ecs::query::WorldQueryData;
|
/// # use bevy_ecs::query::QueryData;
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(Component)]
|
/// #[derive(Component)]
|
||||||
/// struct Health(f32);
|
/// struct Health(f32);
|
||||||
|
@ -138,8 +138,8 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
/// #[derive(Component)]
|
/// #[derive(Component)]
|
||||||
/// struct Buff(f32);
|
/// struct Buff(f32);
|
||||||
///
|
///
|
||||||
/// #[derive(WorldQueryData)]
|
/// #[derive(QueryData)]
|
||||||
/// #[world_query_data(mutable)]
|
/// #[query_data(mutable)]
|
||||||
/// struct HealthQuery {
|
/// struct HealthQuery {
|
||||||
/// health: &'static mut Health,
|
/// health: &'static mut Health,
|
||||||
/// buff: Option<&'static mut Buff>,
|
/// buff: Option<&'static mut Buff>,
|
||||||
|
@ -179,19 +179,19 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
///
|
///
|
||||||
/// ## Deriving traits for query items
|
/// ## Deriving traits for query items
|
||||||
///
|
///
|
||||||
/// The `WorldQueryData` derive macro does not automatically implement the traits of the struct to the query item types.
|
/// 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 `#[world_query_data(derive(...))]` attribute.
|
/// Something similar can be done by using the `#[query_data(derive(...))]` attribute.
|
||||||
/// This will apply the listed derivable traits to the query item structs.
|
/// This will apply the listed derivable traits to the query item structs.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_ecs::query::WorldQueryData;
|
/// # use bevy_ecs::query::QueryData;
|
||||||
/// #
|
/// #
|
||||||
/// # #[derive(Component, Debug)]
|
/// # #[derive(Component, Debug)]
|
||||||
/// # struct ComponentA;
|
/// # struct ComponentA;
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(WorldQueryData)]
|
/// #[derive(QueryData)]
|
||||||
/// #[world_query_data(mutable, derive(Debug))]
|
/// #[query_data(mutable, derive(Debug))]
|
||||||
/// struct CustomQuery {
|
/// struct CustomQuery {
|
||||||
/// component_a: &'static ComponentA,
|
/// component_a: &'static ComponentA,
|
||||||
/// }
|
/// }
|
||||||
|
@ -205,12 +205,12 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
///
|
///
|
||||||
/// ## Query composition
|
/// ## Query composition
|
||||||
///
|
///
|
||||||
/// It is possible to use any `WorldQueryData` as a field of another one.
|
/// It is possible to use any `QueryData` as a field of another one.
|
||||||
/// This means that a `WorldQueryData` can also be used as a subquery, potentially in multiple places.
|
/// This means that a `QueryData` can also be used as a subquery, potentially in multiple places.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # use bevy_ecs::query::WorldQueryData;
|
/// # use bevy_ecs::query::QueryData;
|
||||||
/// #
|
/// #
|
||||||
/// # #[derive(Component)]
|
/// # #[derive(Component)]
|
||||||
/// # struct ComponentA;
|
/// # struct ComponentA;
|
||||||
|
@ -219,13 +219,13 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
/// # #[derive(Component)]
|
/// # #[derive(Component)]
|
||||||
/// # struct ComponentC;
|
/// # struct ComponentC;
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(WorldQueryData)]
|
/// #[derive(QueryData)]
|
||||||
/// struct SubQuery {
|
/// struct SubQuery {
|
||||||
/// component_a: &'static ComponentA,
|
/// component_a: &'static ComponentA,
|
||||||
/// component_b: &'static ComponentB,
|
/// component_b: &'static ComponentB,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// #[derive(WorldQueryData)]
|
/// #[derive(QueryData)]
|
||||||
/// struct MyQuery {
|
/// struct MyQuery {
|
||||||
/// subquery: SubQuery,
|
/// subquery: SubQuery,
|
||||||
/// component_c: &'static ComponentC,
|
/// component_c: &'static ComponentC,
|
||||||
|
@ -235,13 +235,13 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
/// # Generic Queries
|
/// # Generic Queries
|
||||||
///
|
///
|
||||||
/// When writing generic code, it is often necessary to use [`PhantomData`]
|
/// 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.
|
/// `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;
|
/// # use std::marker::PhantomData;
|
||||||
/// #[derive(WorldQueryData)]
|
/// #[derive(QueryData)]
|
||||||
/// pub struct GenericQuery<T> {
|
/// pub struct GenericQuery<T> {
|
||||||
/// id: Entity,
|
/// id: Entity,
|
||||||
/// marker: PhantomData<T>,
|
/// marker: PhantomData<T>,
|
||||||
|
@ -257,22 +257,22 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
///
|
///
|
||||||
/// [`Query`]: crate::system::Query
|
/// [`Query`]: crate::system::Query
|
||||||
/// [`ReadOnly`]: Self::ReadOnly
|
/// [`ReadOnly`]: Self::ReadOnly
|
||||||
pub unsafe trait WorldQueryData: WorldQuery {
|
pub unsafe trait QueryData: WorldQuery {
|
||||||
/// The read-only variant of this [`WorldQueryData`], which satisfies the [`ReadOnlyWorldQueryData`] trait.
|
/// The read-only variant of this [`QueryData`], which satisfies the [`ReadOnlyQueryData`] trait.
|
||||||
type ReadOnly: ReadOnlyWorldQueryData<State = <Self as WorldQuery>::State>;
|
type ReadOnly: ReadOnlyQueryData<State = <Self as WorldQuery>::State>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`WorldQueryData`] that is read only.
|
/// A [`QueryData`] that is read only.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// This must only be implemented for read-only [`WorldQueryData`]'s.
|
/// This must only be implemented for read-only [`QueryData`]'s.
|
||||||
pub unsafe trait ReadOnlyWorldQueryData: WorldQueryData<ReadOnly = Self> {}
|
pub unsafe trait ReadOnlyQueryData: QueryData<ReadOnly = Self> {}
|
||||||
|
|
||||||
/// The item type returned when a [`WorldQuery`] is iterated over
|
/// The item type returned when a [`WorldQuery`] is iterated over
|
||||||
pub type QueryItem<'w, Q> = <Q as WorldQuery>::Item<'w>;
|
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
|
/// 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 WorldQueryData>::ReadOnly>;
|
pub type ROQueryItem<'w, Q> = QueryItem<'w, <Q as QueryData>::ReadOnly>;
|
||||||
|
|
||||||
/// SAFETY:
|
/// SAFETY:
|
||||||
/// `update_component_access` and `update_archetype_component_access` do nothing.
|
/// `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`
|
/// SAFETY: `Self` is the same as `Self::ReadOnly`
|
||||||
unsafe impl WorldQueryData for Entity {
|
unsafe impl QueryData for Entity {
|
||||||
type ReadOnly = Self;
|
type ReadOnly = Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: access is read only
|
/// SAFETY: access is read only
|
||||||
unsafe impl ReadOnlyWorldQueryData for Entity {}
|
unsafe impl ReadOnlyQueryData for Entity {}
|
||||||
|
|
||||||
/// SAFETY:
|
/// SAFETY:
|
||||||
/// `fetch` accesses all components in a readonly way.
|
/// `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`
|
/// 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;
|
type ReadOnly = Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: access is read only
|
/// 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`
|
/// SAFETY: The accesses of `Self::ReadOnly` are a subset of the accesses of `Self`
|
||||||
unsafe impl<'a> WorldQuery for EntityMut<'a> {
|
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`
|
/// 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>;
|
type ReadOnly = EntityRef<'a>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,12 +651,12 @@ unsafe impl<T: Component> WorldQuery for &T {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: `Self` is the same as `Self::ReadOnly`
|
/// 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;
|
type ReadOnly = Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: access is read only
|
/// SAFETY: access is read only
|
||||||
unsafe impl<T: Component> ReadOnlyWorldQueryData for &T {}
|
unsafe impl<T: Component> ReadOnlyQueryData for &T {}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct RefFetch<'w, T> {
|
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`
|
/// 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;
|
type ReadOnly = Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: access is read only
|
/// 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)]
|
#[doc(hidden)]
|
||||||
pub struct WriteFetch<'w, T> {
|
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`
|
/// 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;
|
type ReadOnly = &'__w T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1102,12 +1102,12 @@ unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFETY: defers to soundness of `T: WorldQuery` impl
|
// 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>;
|
type ReadOnly = Option<T::ReadOnly>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: [`OptionFetch`] is read only because `T` is read only
|
/// 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`.
|
/// 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`
|
/// 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;
|
type ReadOnly = Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: [`Has`] is read only
|
/// 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.
|
/// 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`.
|
/// Entities are guaranteed to have at least one of the components in `T`.
|
||||||
pub struct AnyOf<T>(PhantomData<T>);
|
pub struct AnyOf<T>(PhantomData<T>);
|
||||||
|
|
||||||
macro_rules! impl_tuple_world_query_data {
|
macro_rules! impl_tuple_query_data {
|
||||||
($(($name: ident, $state: ident)),*) => {
|
($(($name: ident, $state: ident)),*) => {
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[allow(clippy::unused_unit)]
|
#[allow(clippy::unused_unit)]
|
||||||
// SAFETY: defers to soundness `$name: WorldQuery` impl
|
// 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,)*);
|
type ReadOnly = ($($name::ReadOnly,)*);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: each item in the tuple is read only
|
/// 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(non_snake_case)]
|
||||||
#[allow(clippy::unused_unit)]
|
#[allow(clippy::unused_unit)]
|
||||||
// SAFETY: defers to soundness of `$name: WorldQuery` impl
|
// 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,)*)>;
|
type ReadOnly = AnyOf<($($name::ReadOnly,)*)>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: each item in the tuple is read only
|
/// 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);
|
all_tuples!(impl_anytuple_fetch, 0, 15, F, S);
|
||||||
|
|
||||||
/// [`WorldQuery`] used to nullify queries by turning `Query<Q>` into `Query<NopWorldQuery<Q>>`
|
/// [`WorldQuery`] used to nullify queries by turning `Query<Q>` into `Query<NopWorldQuery<Q>>`
|
||||||
///
|
///
|
||||||
/// This will rarely be useful to consumers of `bevy_ecs`.
|
/// 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:
|
/// SAFETY:
|
||||||
/// `update_component_access` and `update_archetype_component_access` do nothing.
|
/// `update_component_access` and `update_archetype_component_access` do nothing.
|
||||||
/// This is sound because `fetch` does not access components.
|
/// 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 Fetch<'w> = ();
|
||||||
type Item<'w> = ();
|
type Item<'w> = ();
|
||||||
type State = Q::State;
|
type State = Q::State;
|
||||||
|
@ -1467,12 +1467,12 @@ unsafe impl<Q: WorldQueryData> WorldQuery for NopWorldQuery<Q> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: `Self::ReadOnly` is `Self`
|
/// SAFETY: `Self::ReadOnly` is `Self`
|
||||||
unsafe impl<Q: WorldQueryData> WorldQueryData for NopWorldQuery<Q> {
|
unsafe impl<Q: QueryData> QueryData for NopWorldQuery<Q> {
|
||||||
type ReadOnly = Self;
|
type ReadOnly = Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: `NopFetch` never accesses any data
|
/// SAFETY: `NopFetch` never accesses any data
|
||||||
unsafe impl<Q: WorldQueryData> ReadOnlyWorldQueryData for NopWorldQuery<Q> {}
|
unsafe impl<Q: QueryData> ReadOnlyQueryData for NopWorldQuery<Q> {}
|
||||||
|
|
||||||
/// SAFETY:
|
/// SAFETY:
|
||||||
/// `update_component_access` and `update_archetype_component_access` do nothing.
|
/// `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`
|
/// SAFETY: `Self::ReadOnly` is `Self`
|
||||||
unsafe impl<T: ?Sized> WorldQueryData for PhantomData<T> {
|
unsafe impl<T: ?Sized> QueryData for PhantomData<T> {
|
||||||
type ReadOnly = Self;
|
type ReadOnly = Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: `PhantomData` never accesses any world data.
|
/// 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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use bevy_ecs_macros::WorldQueryData;
|
use bevy_ecs_macros::QueryData;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -1561,16 +1561,16 @@ mod tests {
|
||||||
// Tests that each variant of struct can be used as a `WorldQuery`.
|
// Tests that each variant of struct can be used as a `WorldQuery`.
|
||||||
#[test]
|
#[test]
|
||||||
fn world_query_struct_variants() {
|
fn world_query_struct_variants() {
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
pub struct NamedQuery {
|
pub struct NamedQuery {
|
||||||
id: Entity,
|
id: Entity,
|
||||||
a: &'static A,
|
a: &'static A,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
pub struct TupleQuery(&'static A, &'static B);
|
pub struct TupleQuery(&'static A, &'static B);
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
pub struct UnitQuery;
|
pub struct UnitQuery;
|
||||||
|
|
||||||
fn my_system(_: Query<(NamedQuery, TupleQuery, UnitQuery)>) {}
|
fn my_system(_: Query<(NamedQuery, TupleQuery, UnitQuery)>) {}
|
||||||
|
@ -1581,7 +1581,7 @@ mod tests {
|
||||||
// Compile test for https://github.com/bevyengine/bevy/pull/8030.
|
// Compile test for https://github.com/bevyengine/bevy/pull/8030.
|
||||||
#[test]
|
#[test]
|
||||||
fn world_query_phantom_data() {
|
fn world_query_phantom_data() {
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
pub struct IgnoredQuery<Marker> {
|
pub struct IgnoredQuery<Marker> {
|
||||||
id: Entity,
|
id: Entity,
|
||||||
_marker: PhantomData<Marker>,
|
_marker: PhantomData<Marker>,
|
||||||
|
@ -1599,8 +1599,8 @@ mod tests {
|
||||||
mod private {
|
mod private {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(mutable)]
|
#[query_data(mutable)]
|
||||||
pub struct Q {
|
pub struct Q {
|
||||||
pub a: &'static mut A,
|
pub a: &'static mut A,
|
||||||
}
|
}
|
||||||
|
@ -1624,7 +1624,7 @@ mod tests {
|
||||||
fn world_query_metadata_collision() {
|
fn world_query_metadata_collision() {
|
||||||
// The metadata types generated would be named `ClientState` and `ClientFetch`,
|
// The metadata types generated would be named `ClientState` and `ClientFetch`,
|
||||||
// but they should rename themselves to avoid conflicts.
|
// but they should rename themselves to avoid conflicts.
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
pub struct Client<S: ClientState> {
|
pub struct Client<S: ClientState> {
|
||||||
pub state: &'static S,
|
pub state: &'static S,
|
||||||
pub fetch: &'static ClientFetch,
|
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.
|
/// [`With`] and [`Without`] filters can be applied to check if the queried entity does or does not contain a particular component.
|
||||||
/// - **Change detection filters.**
|
/// - **Change detection filters.**
|
||||||
/// [`Added`] and [`Changed`] filters can be applied to detect component changes to an entity.
|
/// [`Added`] and [`Changed`] filters can be applied to detect component changes to an entity.
|
||||||
/// - **`WorldQueryFilter` tuples.**
|
/// - **`QueryFilter` tuples.**
|
||||||
/// If every element of a tuple implements `WorldQueryFilter`, then the tuple itself also implements the same trait.
|
/// 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.
|
/// 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,
|
/// 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.**
|
/// - **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.
|
/// 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.
|
/// 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.
|
/// 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.
|
/// Query design can be easily structured by deriving `QueryFilter` for custom types.
|
||||||
/// Despite the added complexity, this approach has several advantages over using `WorldQueryFilter` tuples.
|
/// Despite the added complexity, this approach has several advantages over using `QueryFilter` tuples.
|
||||||
/// The most relevant improvements are:
|
/// The most relevant improvements are:
|
||||||
///
|
///
|
||||||
/// - Reusability across multiple systems.
|
/// - Reusability across multiple systems.
|
||||||
/// - Filters can be composed together to create a more complex filter.
|
/// - 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::prelude::*;
|
||||||
/// # use bevy_ecs::{query::WorldQueryFilter, component::Component};
|
/// # use bevy_ecs::{query::QueryFilter, component::Component};
|
||||||
/// #
|
/// #
|
||||||
/// # #[derive(Component)]
|
/// # #[derive(Component)]
|
||||||
/// # struct ComponentA;
|
/// # struct ComponentA;
|
||||||
|
@ -52,7 +52,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
/// # #[derive(Component)]
|
/// # #[derive(Component)]
|
||||||
/// # struct ComponentE;
|
/// # struct ComponentE;
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(WorldQueryFilter)]
|
/// #[derive(QueryFilter)]
|
||||||
/// struct MyFilter<T: Component, P: Component> {
|
/// struct MyFilter<T: Component, P: Component> {
|
||||||
/// // Field names are not relevant, since they are never manually accessed.
|
/// // Field names are not relevant, since they are never manually accessed.
|
||||||
/// with_a: With<ComponentA>,
|
/// with_a: With<ComponentA>,
|
||||||
|
@ -73,7 +73,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
/// [`update_archetype_component_access`]: Self::update_archetype_component_access
|
/// [`update_archetype_component_access`]: Self::update_archetype_component_access
|
||||||
/// [`update_component_access`]: Self::update_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
|
/// Returns true if (and only if) this Filter relies strictly on archetypes to limit which
|
||||||
/// components are accessed by the Query.
|
/// 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;
|
const IS_ARCHETYPAL: bool = true;
|
||||||
|
|
||||||
#[inline(always)]
|
#[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;
|
const IS_ARCHETYPAL: bool = true;
|
||||||
|
|
||||||
#[inline(always)]
|
#[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.
|
/// 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.
|
/// `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.
|
/// 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 Fetch<'w> = ($(OrFetch<'w, $filter>,)*);
|
||||||
type Item<'w> = bool;
|
type Item<'w> = bool;
|
||||||
type State = ($($filter::State,)*);
|
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)*;
|
const IS_ARCHETYPAL: bool = true $(&& $filter::IS_ARCHETYPAL)*;
|
||||||
|
|
||||||
#[inline(always)]
|
#[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),*) => {
|
($($name: ident),*) => {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[allow(clippy::unused_unit)]
|
#[allow(clippy::unused_unit)]
|
||||||
|
|
||||||
impl<$($name: WorldQueryFilter),*> WorldQueryFilter for ($($name,)*) {
|
impl<$($name: QueryFilter),*> QueryFilter for ($($name,)*) {
|
||||||
const IS_ARCHETYPAL: bool = true $(&& $name::IS_ARCHETYPAL)*;
|
const IS_ARCHETYPAL: bool = true $(&& $name::IS_ARCHETYPAL)*;
|
||||||
|
|
||||||
#[inline(always)]
|
#[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);
|
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.
|
/// 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;
|
const IS_ARCHETYPAL: bool = false;
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn filter_fetch(
|
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;
|
const IS_ARCHETYPAL: bool = false;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -864,14 +864,14 @@ impl<T: Component> WorldQueryFilter for Changed<T> {
|
||||||
/// This is needed to implement [`ExactSizeIterator`] for
|
/// This is needed to implement [`ExactSizeIterator`] for
|
||||||
/// [`QueryIter`](crate::query::QueryIter) that contains archetype-level filters.
|
/// [`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.
|
/// 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
|
/// [Tuples](prim@tuple) and [`Or`] filters are automatically implemented with the trait only if its containing types
|
||||||
/// also implement the same trait.
|
/// also implement the same trait.
|
||||||
///
|
///
|
||||||
/// [`Added`] and [`Changed`] works with entities, and therefore are not archetypal. As such
|
/// [`Added`] and [`Changed`] works with entities, and therefore are not archetypal. As such
|
||||||
/// they do not implement [`ArchetypeFilter`].
|
/// 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 With<T> {}
|
||||||
impl<T: Component> ArchetypeFilter for Without<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 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).
|
/// An [`Iterator`] over query results of a [`Query`](crate::system::Query).
|
||||||
///
|
///
|
||||||
/// This struct is created by the [`Query::iter`](crate::system::Query::iter) and
|
/// This struct is created by the [`Query::iter`](crate::system::Query::iter) and
|
||||||
/// [`Query::iter_mut`](crate::system::Query::iter_mut) methods.
|
/// [`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,
|
tables: &'w Tables,
|
||||||
archetypes: &'w Archetypes,
|
archetypes: &'w Archetypes,
|
||||||
query_state: &'s QueryState<Q, F>,
|
query_state: &'s QueryState<Q, F>,
|
||||||
cursor: QueryIterationCursor<'w, 's, 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
|
/// # Safety
|
||||||
/// - `world` must have permission to access any of the components registered in `query_state`.
|
/// - `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`.
|
/// - `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>;
|
type Item = Q::Item<'w>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[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.
|
// 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.
|
/// 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.
|
/// 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.
|
/// 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
|
where
|
||||||
I::Item: Borrow<Entity>,
|
I::Item: Borrow<Entity>,
|
||||||
{
|
{
|
||||||
|
@ -280,7 +280,7 @@ where
|
||||||
query_state: &'s QueryState<Q, F>,
|
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
|
where
|
||||||
I::Item: Borrow<Entity>,
|
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>
|
for QueryManyIter<'w, 's, Q, F, I>
|
||||||
where
|
where
|
||||||
I::Item: Borrow<Entity>,
|
I::Item: Borrow<Entity>,
|
||||||
|
@ -396,7 +396,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is correct as [`QueryManyIter`] always returns `None` once exhausted.
|
// 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>
|
for QueryManyIter<'w, 's, Q, F, I>
|
||||||
where
|
where
|
||||||
I::Item: Borrow<Entity>,
|
I::Item: Borrow<Entity>,
|
||||||
|
@ -466,16 +466,14 @@ where
|
||||||
/// [`Query`]: crate::system::Query
|
/// [`Query`]: crate::system::Query
|
||||||
/// [`Query::iter_combinations`]: crate::system::Query::iter_combinations
|
/// [`Query::iter_combinations`]: crate::system::Query::iter_combinations
|
||||||
/// [`Query::iter_combinations_mut`]: crate::system::Query::iter_combinations_mut
|
/// [`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,
|
tables: &'w Tables,
|
||||||
archetypes: &'w Archetypes,
|
archetypes: &'w Archetypes,
|
||||||
query_state: &'s QueryState<Q, F>,
|
query_state: &'s QueryState<Q, F>,
|
||||||
cursors: [QueryIterationCursor<'w, 's, Q, F>; K],
|
cursors: [QueryIterationCursor<'w, 's, Q, F>; K],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter, const K: usize>
|
impl<'w, 's, Q: QueryData, F: QueryFilter, const K: usize> QueryCombinationIter<'w, 's, Q, F, K> {
|
||||||
QueryCombinationIter<'w, 's, Q, F, K>
|
|
||||||
{
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// - `world` must have permission to access any of the components registered in `query_state`.
|
/// - `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`.
|
/// - `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.
|
// Iterator type is intentionally implemented only for read-only access.
|
||||||
// Doing so for mutable references would be unsound, because calling `next`
|
// Doing so for mutable references would be unsound, because calling `next`
|
||||||
// multiple times would allow multiple owned references to the same data to exist.
|
// 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>
|
for QueryCombinationIter<'w, 's, Q, F, K>
|
||||||
{
|
{
|
||||||
type Item = [Q::Item<'w>; 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
|
where
|
||||||
F: ArchetypeFilter,
|
F: ArchetypeFilter,
|
||||||
{
|
{
|
||||||
|
@ -633,12 +631,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is correct as [`QueryCombinationIter`] always returns `None` once exhausted.
|
// 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>
|
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>,
|
table_id_iter: std::slice::Iter<'s, TableId>,
|
||||||
archetype_id_iter: std::slice::Iter<'s, ArchetypeId>,
|
archetype_id_iter: std::slice::Iter<'s, ArchetypeId>,
|
||||||
table_entities: &'w [Entity],
|
table_entities: &'w [Entity],
|
||||||
|
@ -651,7 +649,7 @@ struct QueryIterationCursor<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> {
|
||||||
current_row: usize,
|
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 {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
table_id_iter: self.table_id_iter.clone(),
|
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;
|
const IS_DENSE: bool = Q::IS_DENSE && F::IS_DENSE;
|
||||||
|
|
||||||
unsafe fn init_empty(
|
unsafe fn init_empty(
|
||||||
|
|
|
@ -10,7 +10,7 @@ mod state;
|
||||||
mod world_query;
|
mod world_query;
|
||||||
|
|
||||||
pub use access::*;
|
pub use access::*;
|
||||||
pub use bevy_ecs_macros::{WorldQueryData, WorldQueryFilter};
|
pub use bevy_ecs_macros::{QueryData, QueryFilter};
|
||||||
pub use error::*;
|
pub use error::*;
|
||||||
pub use fetch::*;
|
pub use fetch::*;
|
||||||
pub use filter::*;
|
pub use filter::*;
|
||||||
|
@ -67,10 +67,10 @@ impl<T> DebugCheckedUnwrap for Option<T> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
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::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::schedule::{IntoSystemConfigs, Schedule};
|
||||||
use crate::system::{IntoSystem, Query, System, SystemState};
|
use crate::system::{IntoSystem, Query, System, SystemState};
|
||||||
use crate::{self as bevy_ecs, component::Component, world::World};
|
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)
|
fn assert_combination<Q, F, const K: usize>(world: &mut World, expected_size: usize)
|
||||||
where
|
where
|
||||||
Q: ReadOnlyWorldQueryData,
|
Q: ReadOnlyQueryData,
|
||||||
F: ArchetypeFilter,
|
F: ArchetypeFilter,
|
||||||
{
|
{
|
||||||
let mut query = world.query_filtered::<Q, F>();
|
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)
|
fn assert_all_sizes_equal<Q, F>(world: &mut World, expected_size: usize)
|
||||||
where
|
where
|
||||||
Q: ReadOnlyWorldQueryData,
|
Q: ReadOnlyQueryData,
|
||||||
F: ArchetypeFilter,
|
F: ArchetypeFilter,
|
||||||
{
|
{
|
||||||
let mut query = world.query_filtered::<Q, F>();
|
let mut query = world.query_filtered::<Q, F>();
|
||||||
|
@ -501,8 +501,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic = "&mut bevy_ecs::query::tests::A conflicts with a previous access in this query."]
|
#[should_panic = "&mut bevy_ecs::query::tests::A conflicts with a previous access in this query."]
|
||||||
fn self_conflicting_worldquery() {
|
fn self_conflicting_worldquery() {
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(mutable)]
|
#[query_data(mutable)]
|
||||||
struct SelfConflicting {
|
struct SelfConflicting {
|
||||||
a: &'static mut A,
|
a: &'static mut A,
|
||||||
b: &'static mut A,
|
b: &'static mut A,
|
||||||
|
@ -538,7 +538,7 @@ mod tests {
|
||||||
world.spawn_empty();
|
world.spawn_empty();
|
||||||
|
|
||||||
{
|
{
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
struct CustomAB {
|
struct CustomAB {
|
||||||
a: &'static A,
|
a: &'static A,
|
||||||
b: &'static B,
|
b: &'static B,
|
||||||
|
@ -558,7 +558,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
struct FancyParam {
|
struct FancyParam {
|
||||||
e: Entity,
|
e: Entity,
|
||||||
b: &'static B,
|
b: &'static B,
|
||||||
|
@ -579,11 +579,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
struct MaybeBSparse {
|
struct MaybeBSparse {
|
||||||
blah: Option<(&'static B, &'static Sparse)>,
|
blah: Option<(&'static B, &'static Sparse)>,
|
||||||
}
|
}
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
struct MatchEverything {
|
struct MatchEverything {
|
||||||
abcs: AnyOf<(&'static A, &'static B, &'static C)>,
|
abcs: AnyOf<(&'static A, &'static B, &'static C)>,
|
||||||
opt_bsparse: MaybeBSparse,
|
opt_bsparse: MaybeBSparse,
|
||||||
|
@ -618,11 +618,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#[derive(WorldQueryFilter)]
|
#[derive(QueryFilter)]
|
||||||
struct AOrBFilter {
|
struct AOrBFilter {
|
||||||
a: Or<(With<A>, With<B>)>,
|
a: Or<(With<A>, With<B>)>,
|
||||||
}
|
}
|
||||||
#[derive(WorldQueryFilter)]
|
#[derive(QueryFilter)]
|
||||||
struct NoSparseThatsSlow {
|
struct NoSparseThatsSlow {
|
||||||
no: Without<Sparse>,
|
no: Without<Sparse>,
|
||||||
}
|
}
|
||||||
|
@ -639,7 +639,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#[derive(WorldQueryFilter)]
|
#[derive(QueryFilter)]
|
||||||
struct CSparseFilter {
|
struct CSparseFilter {
|
||||||
tuple_structs_pls: With<C>,
|
tuple_structs_pls: With<C>,
|
||||||
ugh: With<Sparse>,
|
ugh: With<Sparse>,
|
||||||
|
@ -657,7 +657,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#[derive(WorldQueryFilter)]
|
#[derive(QueryFilter)]
|
||||||
struct WithoutComps {
|
struct WithoutComps {
|
||||||
_1: Without<A>,
|
_1: Without<A>,
|
||||||
_2: Without<B>,
|
_2: Without<B>,
|
||||||
|
@ -676,7 +676,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
struct IterCombAB {
|
struct IterCombAB {
|
||||||
a: &'static A,
|
a: &'static A,
|
||||||
b: &'static B,
|
b: &'static B,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{component::Tick, world::unsafe_world_cell::UnsafeWorldCell};
|
use crate::{component::Tick, world::unsafe_world_cell::UnsafeWorldCell};
|
||||||
use std::ops::Range;
|
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
|
/// Dictates how a parallel query chunks up large tables/archetypes
|
||||||
/// during iteration.
|
/// during iteration.
|
||||||
|
@ -82,7 +82,7 @@ impl BatchingStrategy {
|
||||||
///
|
///
|
||||||
/// This struct is created by the [`Query::par_iter`](crate::system::Query::par_iter) and
|
/// 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.
|
/// [`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) world: UnsafeWorldCell<'w>,
|
||||||
pub(crate) state: &'s QueryState<Q, F>,
|
pub(crate) state: &'s QueryState<Q, F>,
|
||||||
pub(crate) last_run: Tick,
|
pub(crate) last_run: Tick,
|
||||||
|
@ -90,7 +90,7 @@ pub struct QueryParIter<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> {
|
||||||
pub(crate) batching_strategy: BatchingStrategy,
|
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.
|
/// Changes the batching strategy used when iterating.
|
||||||
///
|
///
|
||||||
/// For more information on how this affects the resultant iteration, see
|
/// 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 std::{any::TypeId, borrow::Borrow, fmt, mem::MaybeUninit};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
NopWorldQuery, QueryComponentError, QueryEntityError, QueryManyIter, QuerySingleError,
|
NopWorldQuery, QueryComponentError, QueryData, QueryEntityError, QueryFilter, QueryManyIter,
|
||||||
ROQueryItem, WorldQueryData, WorldQueryFilter,
|
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)]
|
#[repr(C)]
|
||||||
// SAFETY NOTE:
|
// SAFETY NOTE:
|
||||||
// Do not add any new fields that use the `Q` or `F` generic parameters as this may
|
// 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.
|
// 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,
|
world_id: WorldId,
|
||||||
pub(crate) archetype_generation: ArchetypeGeneration,
|
pub(crate) archetype_generation: ArchetypeGeneration,
|
||||||
pub(crate) matched_tables: FixedBitSet,
|
pub(crate) matched_tables: FixedBitSet,
|
||||||
|
@ -43,7 +43,7 @@ pub struct QueryState<Q: WorldQueryData, F: WorldQueryFilter = ()> {
|
||||||
par_iter_span: Span,
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("QueryState")
|
f.debug_struct("QueryState")
|
||||||
.field("world_id", &self.world_id)
|
.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 {
|
fn from_world(world: &mut World) -> Self {
|
||||||
world.query_filtered()
|
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.
|
/// Converts this `QueryState` reference to a `QueryState` that does not access anything mutably.
|
||||||
pub fn as_readonly(&self) -> &QueryState<Q::ReadOnly, F> {
|
pub fn as_readonly(&self) -> &QueryState<Q::ReadOnly, F> {
|
||||||
// SAFETY: invariant on `WorldQuery` trait upholds that `Q::ReadOnly` and `F::ReadOnly`
|
// 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
|
/// `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
|
/// `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<
|
pub(crate) unsafe fn as_transmuted_state<
|
||||||
NewQ: WorldQueryData<State = Q::State>,
|
NewQ: QueryData<State = Q::State>,
|
||||||
NewF: WorldQueryFilter<State = F::State>,
|
NewF: QueryFilter<State = F::State>,
|
||||||
>(
|
>(
|
||||||
&self,
|
&self,
|
||||||
) -> &QueryState<NewQ, NewF> {
|
) -> &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()`.
|
/// Creates a new [`QueryState`] from a given [`World`] and inherits the result of `world.id()`.
|
||||||
pub fn new(world: &mut World) -> Self {
|
pub fn new(world: &mut World) -> Self {
|
||||||
let fetch_state = Q::init_state(world);
|
let fetch_state = Q::init_state(world);
|
||||||
|
@ -162,7 +162,7 @@ impl<Q: WorldQueryData, F: WorldQueryFilter> QueryState<Q, F> {
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # 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`].
|
/// - `world` must match the one used to create this [`QueryState`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) unsafe fn is_empty_unsafe_world_cell(
|
pub(crate) unsafe fn is_empty_unsafe_world_cell(
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
use bevy_utils::all_tuples;
|
use bevy_utils::all_tuples;
|
||||||
|
|
||||||
/// Types that can be used as parameters in a [`Query`].
|
/// 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
|
/// # Safety
|
||||||
///
|
///
|
||||||
|
@ -36,12 +36,12 @@ use bevy_utils::all_tuples;
|
||||||
/// [`Query`]: crate::system::Query
|
/// [`Query`]: crate::system::Query
|
||||||
/// [`update_archetype_component_access`]: Self::update_archetype_component_access
|
/// [`update_archetype_component_access`]: Self::update_archetype_component_access
|
||||||
/// [`update_component_access`]: Self::update_component_access
|
/// [`update_component_access`]: Self::update_component_access
|
||||||
/// [`WorldQueryData`]: crate::query::WorldQueryData
|
/// [`QueryData`]: crate::query::QueryData
|
||||||
/// [`WorldQueryFilter`]: crate::query::WorldQueryFilter
|
/// [`QueryFilter`]: crate::query::QueryFilter
|
||||||
pub unsafe trait WorldQuery {
|
pub unsafe trait WorldQuery {
|
||||||
/// The item returned by this [`WorldQuery`]
|
/// The item returned by this [`WorldQuery`]
|
||||||
/// For `WorldQueryData` this will be the item returned by the query.
|
/// For `QueryData` this will be the item returned by the query.
|
||||||
/// For `WorldQueryFilter` this will be either `()`, or a `bool` indicating whether the entity should be included
|
/// For `QueryFilter` this will be either `()`, or a `bool` indicating whether the entity should be included
|
||||||
/// or a tuple of such things.
|
/// or a tuple of such things.
|
||||||
type Item<'a>;
|
type Item<'a>;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
prelude::{FromWorld, QueryState},
|
prelude::{FromWorld, QueryState},
|
||||||
query::{WorldQueryData, WorldQueryFilter},
|
query::{QueryData, QueryFilter},
|
||||||
system::{Local, SystemMeta, SystemParam, SystemState},
|
system::{Local, SystemMeta, SystemParam, SystemState},
|
||||||
world::World,
|
world::World,
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@ pub trait ExclusiveSystemParam: Sized {
|
||||||
/// for a given [`ExclusiveSystemParam`].
|
/// for a given [`ExclusiveSystemParam`].
|
||||||
pub type ExclusiveSystemParamItem<'s, P> = <P as ExclusiveSystemParam>::Item<'s>;
|
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>
|
for &'a mut QueryState<Q, F>
|
||||||
{
|
{
|
||||||
type State = QueryState<Q, F>;
|
type State = QueryState<Q, F>;
|
||||||
|
|
|
@ -2,9 +2,9 @@ use crate::{
|
||||||
component::{Component, Tick},
|
component::{Component, Tick},
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
query::{
|
query::{
|
||||||
BatchingStrategy, QueryCombinationIter, QueryComponentError, QueryEntityError, QueryIter,
|
BatchingStrategy, QueryCombinationIter, QueryComponentError, QueryData, QueryEntityError,
|
||||||
QueryManyIter, QueryParIter, QuerySingleError, QueryState, ROQueryItem,
|
QueryFilter, QueryIter, QueryManyIter, QueryParIter, QuerySingleError, QueryState,
|
||||||
ReadOnlyWorldQueryData, WorldQueryData, WorldQueryFilter,
|
ROQueryItem, ReadOnlyQueryData,
|
||||||
},
|
},
|
||||||
world::{unsafe_world_cell::UnsafeWorldCell, Mut},
|
world::{unsafe_world_cell::UnsafeWorldCell, Mut},
|
||||||
};
|
};
|
||||||
|
@ -21,10 +21,10 @@ use std::{any::TypeId, borrow::Borrow};
|
||||||
/// - **`Q` (query fetch).**
|
/// - **`Q` (query fetch).**
|
||||||
/// The type of data contained in the query item.
|
/// The type of data contained in the query item.
|
||||||
/// Only entities that match the requested data will generate an 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).**
|
/// - **`F` (query filter).**
|
||||||
/// A set of conditions that determines whether query items should be kept or discarded.
|
/// 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.
|
/// This type parameter is optional.
|
||||||
///
|
///
|
||||||
/// [`World`]: crate::world::World
|
/// [`World`]: crate::world::World
|
||||||
|
@ -73,7 +73,7 @@ use std::{any::TypeId, borrow::Borrow};
|
||||||
/// # bevy_ecs::system::assert_is_system(system);
|
/// # 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.
|
/// Using tuples, each `Query` type parameter can contain multiple elements.
|
||||||
///
|
///
|
||||||
|
@ -325,7 +325,7 @@ use std::{any::TypeId, borrow::Borrow};
|
||||||
/// [`Table`]: crate::storage::Table
|
/// [`Table`]: crate::storage::Table
|
||||||
/// [`With`]: crate::query::With
|
/// [`With`]: crate::query::With
|
||||||
/// [`Without`]: crate::query::Without
|
/// [`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`.
|
// SAFETY: Must have access to the components registered in `state`.
|
||||||
world: UnsafeWorldCell<'world>,
|
world: UnsafeWorldCell<'world>,
|
||||||
state: &'state QueryState<Q, F>,
|
state: &'state QueryState<Q, F>,
|
||||||
|
@ -339,7 +339,7 @@ pub struct Query<'world, 'state, Q: WorldQueryData, F: WorldQueryFilter = ()> {
|
||||||
force_read_only_component_access: bool,
|
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 {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
f.debug_struct("Query")
|
f.debug_struct("Query")
|
||||||
.field("matched_entities", &self.iter().count())
|
.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.
|
/// Creates a new query.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # 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 Item = ROQueryItem<'w, Q>;
|
||||||
type IntoIter = QueryIter<'w, 's, Q::ReadOnly, F>;
|
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 Item = Q::Item<'w>;
|
||||||
type IntoIter = QueryIter<'w, 's, Q, F>;
|
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.
|
/// 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
|
/// In case of a nonexisting entity or mismatched component, a [`QueryEntityError`] is
|
||||||
|
|
|
@ -6,8 +6,8 @@ use crate::{
|
||||||
component::{ComponentId, ComponentTicks, Components, Tick},
|
component::{ComponentId, ComponentTicks, Components, Tick},
|
||||||
entity::Entities,
|
entity::Entities,
|
||||||
query::{
|
query::{
|
||||||
Access, FilteredAccess, FilteredAccessSet, QueryState, ReadOnlyWorldQueryData,
|
Access, FilteredAccess, FilteredAccessSet, QueryData, QueryFilter, QueryState,
|
||||||
WorldQueryData, WorldQueryFilter,
|
ReadOnlyQueryData,
|
||||||
},
|
},
|
||||||
system::{Query, SystemMeta},
|
system::{Query, SystemMeta},
|
||||||
world::{unsafe_world_cell::UnsafeWorldCell, FromWorld, World},
|
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>;
|
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.
|
// SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
|
||||||
unsafe impl<'w, 's, Q: ReadOnlyWorldQueryData + 'static, F: WorldQueryFilter + 'static>
|
unsafe impl<'w, 's, Q: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam
|
||||||
ReadOnlySystemParam for Query<'w, 's, Q, F>
|
for Query<'w, 's, Q, F>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If
|
// SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If
|
||||||
// this Query conflicts with any prior access, a panic will occur.
|
// this Query conflicts with any prior access, a panic will occur.
|
||||||
unsafe impl<Q: WorldQueryData + 'static, F: WorldQueryFilter + 'static> SystemParam
|
unsafe impl<Q: QueryData + 'static, F: QueryFilter + 'static> SystemParam for Query<'_, '_, Q, F> {
|
||||||
for Query<'_, '_, Q, F>
|
|
||||||
{
|
|
||||||
type State = QueryState<Q, F>;
|
type State = QueryState<Q, F>;
|
||||||
type Item<'w, 's> = Query<'w, 's, Q, F>;
|
type Item<'w, 's> = Query<'w, 's, Q, F>;
|
||||||
|
|
||||||
|
@ -1568,8 +1566,8 @@ mod tests {
|
||||||
pub struct SpecialQuery<
|
pub struct SpecialQuery<
|
||||||
'w,
|
'w,
|
||||||
's,
|
's,
|
||||||
Q: WorldQueryData + Send + Sync + 'static,
|
Q: QueryData + Send + Sync + 'static,
|
||||||
F: WorldQueryFilter + Send + Sync + 'static = (),
|
F: QueryFilter + Send + Sync + 'static = (),
|
||||||
> {
|
> {
|
||||||
_query: Query<'w, 's, Q, F>,
|
_query: Query<'w, 's, Q, F>,
|
||||||
}
|
}
|
||||||
|
@ -1690,7 +1688,7 @@ mod tests {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct WhereParam<'w, 's, Q>
|
pub struct WhereParam<'w, 's, Q>
|
||||||
where
|
where
|
||||||
Q: 'static + WorldQueryData,
|
Q: 'static + QueryData,
|
||||||
{
|
{
|
||||||
_q: Query<'w, 's, Q, ()>,
|
_q: Query<'w, 's, Q, ()>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
component::{Component, ComponentDescriptor, ComponentId, ComponentInfo, Components, Tick},
|
component::{Component, ComponentDescriptor, ComponentId, ComponentInfo, Components, Tick},
|
||||||
entity::{AllocAtWithoutReplacement, Entities, Entity, EntityLocation},
|
entity::{AllocAtWithoutReplacement, Entities, Entity, EntityLocation},
|
||||||
event::{Event, EventId, Events, SendBatchIds},
|
event::{Event, EventId, Events, SendBatchIds},
|
||||||
query::{DebugCheckedUnwrap, QueryEntityError, QueryState, WorldQueryData, WorldQueryFilter},
|
query::{DebugCheckedUnwrap, QueryData, QueryEntityError, QueryFilter, QueryState},
|
||||||
removal_detection::RemovedComponentEvents,
|
removal_detection::RemovedComponentEvents,
|
||||||
schedule::{Schedule, ScheduleLabel, Schedules},
|
schedule::{Schedule, ScheduleLabel, Schedules},
|
||||||
storage::{ResourceData, Storages},
|
storage::{ResourceData, Storages},
|
||||||
|
@ -928,7 +928,7 @@ impl World {
|
||||||
self.last_change_tick = self.increment_change_tick();
|
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`].
|
/// run queries on the [`World`] by storing and reusing the [`QueryState`].
|
||||||
/// ```
|
/// ```
|
||||||
/// use bevy_ecs::{component::Component, entity::Entity, world::World};
|
/// use bevy_ecs::{component::Component, entity::Entity, world::World};
|
||||||
|
@ -991,11 +991,11 @@ impl World {
|
||||||
/// ]);
|
/// ]);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn query<Q: WorldQueryData>(&mut self) -> QueryState<Q, ()> {
|
pub fn query<Q: QueryData>(&mut self) -> QueryState<Q, ()> {
|
||||||
self.query_filtered::<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`].
|
/// run queries on the [`World`] by storing and reusing the [`QueryState`].
|
||||||
/// ```
|
/// ```
|
||||||
/// use bevy_ecs::{component::Component, entity::Entity, world::World, query::With};
|
/// use bevy_ecs::{component::Component, entity::Entity, world::World, query::With};
|
||||||
|
@ -1015,7 +1015,7 @@ impl World {
|
||||||
/// assert_eq!(matching_entities, vec![e2]);
|
/// assert_eq!(matching_entities, vec![e2]);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[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)
|
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
|
--> tests/ui/query_iter_combinations_mut_iterator_safety.rs:10:17
|
||||||
|
|
|
|
||||||
10 | is_iterator(iter)
|
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
|
| 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>
|
bevy_ecs::change_detection::Ref<'__w, T>
|
||||||
Has<T>
|
Has<T>
|
||||||
AnyOf<()>
|
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)>
|
||||||
AnyOf<(F0, F1, F2, F3, F4)>
|
AnyOf<(F0, F1, F2, F3, F4)>
|
||||||
and $N others
|
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 for `QueryCombinationIter<'_, '_, &mut A, (), _>` to implement `Iterator`
|
||||||
note: required by a bound in `is_iterator`
|
note: required by a bound in `is_iterator`
|
||||||
--> tests/ui/query_iter_combinations_mut_iterator_safety.rs:13:19
|
--> 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
|
--> tests/ui/query_iter_many_mut_iterator_safety.rs:10:17
|
||||||
|
|
|
|
||||||
10 | is_iterator(iter)
|
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
|
| 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>
|
bevy_ecs::change_detection::Ref<'__w, T>
|
||||||
Has<T>
|
Has<T>
|
||||||
AnyOf<()>
|
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)>
|
||||||
AnyOf<(F0, F1, F2, F3, F4)>
|
AnyOf<(F0, F1, F2, F3, F4)>
|
||||||
and $N others
|
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 for `QueryManyIter<'_, '_, &mut A, (), std::array::IntoIter<bevy_ecs::entity::Entity, 1>>` to implement `Iterator`
|
||||||
note: required by a bound in `is_iterator`
|
note: required by a bound in `is_iterator`
|
||||||
--> tests/ui/query_iter_many_mut_iterator_safety.rs:13:19
|
--> 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
|
= 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
|
--> tests/ui/system_param_derive_readonly.rs:18:23
|
||||||
|
|
|
|
||||||
18 | assert_readonly::<Mutable>();
|
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>
|
bevy_ecs::change_detection::Ref<'__w, T>
|
||||||
Has<T>
|
Has<T>
|
||||||
AnyOf<()>
|
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)>
|
||||||
AnyOf<(F0, F1, F2, F3, F4)>
|
AnyOf<(F0, F1, F2, F3, F4)>
|
||||||
and $N others
|
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: required for `bevy_ecs::system::Query<'_, '_, &'static mut Foo>` to implement `ReadOnlySystemParam`
|
||||||
= note: 1 redundant requirement hidden
|
= note: 1 redundant requirement hidden
|
||||||
= note: required for `Mutable<'_, '_>` to implement `ReadOnlySystemParam`
|
= note: required for `Mutable<'_, '_>` to implement `ReadOnlySystemParam`
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_ecs::query::WorldQueryData;
|
use bevy_ecs::query::QueryData;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
struct MutableUnmarked {
|
struct MutableUnmarked {
|
||||||
a: &'static mut Foo,
|
a: &'static mut Foo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(mutable)]
|
#[query_data(mutable)]
|
||||||
struct MutableMarked {
|
struct MutableMarked {
|
||||||
a: &'static mut Foo,
|
a: &'static mut Foo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
struct NestedMutableUnmarked {
|
struct NestedMutableUnmarked {
|
||||||
a: MutableMarked,
|
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
|
--> tests/ui/world_query_derive.rs:9:8
|
||||||
|
|
|
|
||||||
9 | a: &'static mut Foo,
|
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
|
MutableUnmarked
|
||||||
MutableMarkedReadOnly
|
MutableMarkedReadOnly
|
||||||
NestedMutableUnmarked
|
NestedMutableUnmarked
|
||||||
|
@ -17,17 +17,17 @@ error[E0277]: the trait bound `&'static mut Foo: ReadOnlyWorldQueryData` is not
|
||||||
note: required by a bound in `_::assert_readonly`
|
note: required by a bound in `_::assert_readonly`
|
||||||
--> tests/ui/world_query_derive.rs:7:10
|
--> tests/ui/world_query_derive.rs:7:10
|
||||||
|
|
|
|
||||||
7 | #[derive(WorldQueryData)]
|
7 | #[derive(QueryData)]
|
||||||
| ^^^^^^^^^^^^^^ required by this bound in `assert_readonly`
|
| ^^^^^^^^^ 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)
|
= 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
|
--> tests/ui/world_query_derive.rs:20:8
|
||||||
|
|
|
|
||||||
20 | a: MutableMarked,
|
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
|
MutableUnmarked
|
||||||
MutableMarkedReadOnly
|
MutableMarkedReadOnly
|
||||||
NestedMutableUnmarked
|
NestedMutableUnmarked
|
||||||
|
@ -40,6 +40,6 @@ error[E0277]: the trait bound `MutableMarked: ReadOnlyWorldQueryData` is not sat
|
||||||
note: required by a bound in `_::assert_readonly`
|
note: required by a bound in `_::assert_readonly`
|
||||||
--> tests/ui/world_query_derive.rs:18:10
|
--> tests/ui/world_query_derive.rs:18:10
|
||||||
|
|
|
|
||||||
18 | #[derive(WorldQueryData)]
|
18 | #[derive(QueryData)]
|
||||||
| ^^^^^^^^^^^^^^ required by this bound in `assert_readonly`
|
| ^^^^^^^^^ 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)
|
= 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>;
|
struct SetLineGizmoBindGroup<const I: usize>;
|
||||||
impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetLineGizmoBindGroup<I> {
|
impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetLineGizmoBindGroup<I> {
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<DynamicUniformIndex<LineGizmoUniform>>;
|
type ItemData = Read<DynamicUniformIndex<LineGizmoUniform>>;
|
||||||
type Param = SRes<LineGizmoUniformBindgroup>;
|
type Param = SRes<LineGizmoUniformBindgroup>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
_view: ROQueryItem<'w, Self::ViewWorldQuery>,
|
_view: ROQueryItem<'w, Self::ViewData>,
|
||||||
uniform_index: ROQueryItem<'w, Self::ItemWorldQuery>,
|
uniform_index: ROQueryItem<'w, Self::ItemData>,
|
||||||
bind_group: SystemParamItem<'w, '_, Self::Param>,
|
bind_group: SystemParamItem<'w, '_, Self::Param>,
|
||||||
pass: &mut TrackedRenderPass<'w>,
|
pass: &mut TrackedRenderPass<'w>,
|
||||||
) -> RenderCommandResult {
|
) -> RenderCommandResult {
|
||||||
|
@ -454,15 +454,15 @@ impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetLineGizmoBindGroup<I>
|
||||||
|
|
||||||
struct DrawLineGizmo;
|
struct DrawLineGizmo;
|
||||||
impl<P: PhaseItem> RenderCommand<P> for DrawLineGizmo {
|
impl<P: PhaseItem> RenderCommand<P> for DrawLineGizmo {
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<Handle<LineGizmo>>;
|
type ItemData = Read<Handle<LineGizmo>>;
|
||||||
type Param = SRes<RenderAssets<LineGizmo>>;
|
type Param = SRes<RenderAssets<LineGizmo>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
_view: ROQueryItem<'w, Self::ViewWorldQuery>,
|
_view: ROQueryItem<'w, Self::ViewData>,
|
||||||
handle: ROQueryItem<'w, Self::ItemWorldQuery>,
|
handle: ROQueryItem<'w, Self::ItemData>,
|
||||||
line_gizmos: SystemParamItem<'w, '_, Self::Param>,
|
line_gizmos: SystemParamItem<'w, '_, Self::Param>,
|
||||||
pass: &mut TrackedRenderPass<'w>,
|
pass: &mut TrackedRenderPass<'w>,
|
||||||
) -> RenderCommandResult {
|
) -> RenderCommandResult {
|
||||||
|
|
|
@ -2,14 +2,14 @@ use std::collections::VecDeque;
|
||||||
|
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
query::{WorldQuery, WorldQueryData, WorldQueryFilter},
|
query::{QueryData, QueryFilter, WorldQuery},
|
||||||
system::Query,
|
system::Query,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{Children, Parent};
|
use crate::{Children, Parent};
|
||||||
|
|
||||||
/// An extension trait for [`Query`] that adds hierarchy related methods.
|
/// 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.
|
/// 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>`).
|
/// 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>;
|
Q::ReadOnly: WorldQuery<Item<'w> = &'w Parent>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'w, 's, Q: WorldQueryData, F: WorldQueryFilter> HierarchyQueryExt<'w, 's, Q, F>
|
impl<'w, 's, Q: QueryData, F: QueryFilter> HierarchyQueryExt<'w, 's, Q, F> for Query<'w, 's, Q, F> {
|
||||||
for Query<'w, 's, Q, F>
|
|
||||||
{
|
|
||||||
fn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, Q, F>
|
fn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, Q, F>
|
||||||
where
|
where
|
||||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Children>,
|
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`].
|
/// An [`Iterator`] of [`Entity`]s over the descendants of an [`Entity`].
|
||||||
///
|
///
|
||||||
/// Traverses the hierarchy breadth-first.
|
/// Traverses the hierarchy breadth-first.
|
||||||
pub struct DescendantIter<'w, 's, Q: WorldQueryData, F: WorldQueryFilter>
|
pub struct DescendantIter<'w, 's, Q: QueryData, F: QueryFilter>
|
||||||
where
|
where
|
||||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Children>,
|
Q::ReadOnly: WorldQuery<Item<'w> = &'w Children>,
|
||||||
{
|
{
|
||||||
|
@ -86,7 +84,7 @@ where
|
||||||
vecdeque: VecDeque<Entity>,
|
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
|
where
|
||||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Children>,
|
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
|
where
|
||||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Children>,
|
Q::ReadOnly: WorldQuery<Item<'w> = &'w Children>,
|
||||||
{
|
{
|
||||||
|
@ -122,7 +120,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An [`Iterator`] of [`Entity`]s over the ancestors of an [`Entity`].
|
/// 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
|
where
|
||||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,
|
Q::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,
|
||||||
{
|
{
|
||||||
|
@ -130,7 +128,7 @@ where
|
||||||
next: Option<Entity>,
|
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
|
where
|
||||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,
|
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
|
where
|
||||||
Q::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,
|
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;
|
pub struct DeferredOpaquePass3dPbrLightingNode;
|
||||||
|
|
||||||
impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
|
impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ViewUniformOffset,
|
&'static ViewUniformOffset,
|
||||||
&'static ViewLightsUniformOffset,
|
&'static ViewLightsUniformOffset,
|
||||||
&'static ViewFogUniformOffset,
|
&'static ViewFogUniformOffset,
|
||||||
|
@ -173,7 +173,7 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode {
|
||||||
deferred_lighting_id_depth_texture,
|
deferred_lighting_id_depth_texture,
|
||||||
camera_3d,
|
camera_3d,
|
||||||
deferred_lighting_pipeline,
|
deferred_lighting_pipeline,
|
||||||
): QueryItem<Self::ViewQuery>,
|
): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let pipeline_cache = world.resource::<PipelineCache>();
|
let pipeline_cache = world.resource::<PipelineCache>();
|
||||||
|
|
|
@ -377,8 +377,8 @@ type DrawMaterial<M> = (
|
||||||
pub struct SetMaterialBindGroup<M: Material, const I: usize>(PhantomData<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> {
|
impl<P: PhaseItem, M: Material, const I: usize> RenderCommand<P> for SetMaterialBindGroup<M, I> {
|
||||||
type Param = (SRes<RenderMaterials<M>>, SRes<RenderMaterialInstances<M>>);
|
type Param = (SRes<RenderMaterials<M>>, SRes<RenderMaterialInstances<M>>);
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
|
|
@ -874,11 +874,11 @@ pub fn queue_prepass_material_meshes<M: Material>(
|
||||||
pub struct SetPrepassViewBindGroup<const I: usize>;
|
pub struct SetPrepassViewBindGroup<const I: usize>;
|
||||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetPrepassViewBindGroup<I> {
|
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetPrepassViewBindGroup<I> {
|
||||||
type Param = SRes<PrepassViewBindGroup>;
|
type Param = SRes<PrepassViewBindGroup>;
|
||||||
type ViewWorldQuery = (
|
type ViewData = (
|
||||||
Read<ViewUniformOffset>,
|
Read<ViewUniformOffset>,
|
||||||
Option<Read<PreviousViewProjectionUniformOffset>>,
|
Option<Read<PreviousViewProjectionUniformOffset>>,
|
||||||
);
|
);
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
|
|
@ -448,14 +448,14 @@ impl MeshPipeline {
|
||||||
|
|
||||||
impl GetBatchData for MeshPipeline {
|
impl GetBatchData for MeshPipeline {
|
||||||
type Param = SRes<RenderMeshInstances>;
|
type Param = SRes<RenderMeshInstances>;
|
||||||
type Query = Entity;
|
type Data = Entity;
|
||||||
type QueryFilter = With<Mesh3d>;
|
type Filter = With<Mesh3d>;
|
||||||
type CompareData = (MaterialBindGroupId, AssetId<Mesh>);
|
type CompareData = (MaterialBindGroupId, AssetId<Mesh>);
|
||||||
type BufferData = MeshUniform;
|
type BufferData = MeshUniform;
|
||||||
|
|
||||||
fn get_batch_data(
|
fn get_batch_data(
|
||||||
mesh_instances: &SystemParamItem<Self::Param>,
|
mesh_instances: &SystemParamItem<Self::Param>,
|
||||||
entity: &QueryItem<Self::Query>,
|
entity: &QueryItem<Self::Data>,
|
||||||
) -> (Self::BufferData, Option<Self::CompareData>) {
|
) -> (Self::BufferData, Option<Self::CompareData>) {
|
||||||
let mesh_instance = mesh_instances
|
let mesh_instance = mesh_instances
|
||||||
.get(entity)
|
.get(entity)
|
||||||
|
@ -981,20 +981,20 @@ pub fn prepare_mesh_bind_group(
|
||||||
pub struct SetMeshViewBindGroup<const I: usize>;
|
pub struct SetMeshViewBindGroup<const I: usize>;
|
||||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshViewBindGroup<I> {
|
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshViewBindGroup<I> {
|
||||||
type Param = ();
|
type Param = ();
|
||||||
type ViewWorldQuery = (
|
type ViewData = (
|
||||||
Read<ViewUniformOffset>,
|
Read<ViewUniformOffset>,
|
||||||
Read<ViewLightsUniformOffset>,
|
Read<ViewLightsUniformOffset>,
|
||||||
Read<ViewFogUniformOffset>,
|
Read<ViewFogUniformOffset>,
|
||||||
Read<MeshViewBindGroup>,
|
Read<MeshViewBindGroup>,
|
||||||
);
|
);
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
(view_uniform, view_lights, view_fog, mesh_view_bind_group): ROQueryItem<
|
(view_uniform, view_lights, view_fog, mesh_view_bind_group): ROQueryItem<
|
||||||
'w,
|
'w,
|
||||||
Self::ViewWorldQuery,
|
Self::ViewData,
|
||||||
>,
|
>,
|
||||||
_entity: (),
|
_entity: (),
|
||||||
_: SystemParamItem<'w, '_, Self::Param>,
|
_: SystemParamItem<'w, '_, Self::Param>,
|
||||||
|
@ -1018,8 +1018,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshBindGroup<I> {
|
||||||
SRes<SkinIndices>,
|
SRes<SkinIndices>,
|
||||||
SRes<MorphIndices>,
|
SRes<MorphIndices>,
|
||||||
);
|
);
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
@ -1081,8 +1081,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshBindGroup<I> {
|
||||||
pub struct DrawMesh;
|
pub struct DrawMesh;
|
||||||
impl<P: PhaseItem> RenderCommand<P> for DrawMesh {
|
impl<P: PhaseItem> RenderCommand<P> for DrawMesh {
|
||||||
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMeshInstances>);
|
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMeshInstances>);
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
item: &P,
|
item: &P,
|
||||||
|
|
|
@ -199,7 +199,7 @@ impl ScreenSpaceAmbientOcclusionQualityLevel {
|
||||||
struct SsaoNode {}
|
struct SsaoNode {}
|
||||||
|
|
||||||
impl ViewNode for SsaoNode {
|
impl ViewNode for SsaoNode {
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ExtractedCamera,
|
&'static ExtractedCamera,
|
||||||
&'static SsaoPipelineId,
|
&'static SsaoPipelineId,
|
||||||
&'static SsaoBindGroups,
|
&'static SsaoBindGroups,
|
||||||
|
@ -210,7 +210,7 @@ impl ViewNode for SsaoNode {
|
||||||
&self,
|
&self,
|
||||||
_graph: &mut RenderGraphContext,
|
_graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
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,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let pipelines = world.resource::<SsaoPipelines>();
|
let pipelines = world.resource::<SsaoPipelines>();
|
||||||
|
|
|
@ -38,12 +38,12 @@ pub fn derive_extract_component(input: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
TokenStream::from(quote! {
|
TokenStream::from(quote! {
|
||||||
impl #impl_generics #bevy_render_path::extract_component::ExtractComponent for #struct_name #type_generics #where_clause {
|
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 Filter = #filter;
|
||||||
type Out = Self;
|
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())
|
Some(item.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Component,
|
component::Component,
|
||||||
prelude::Res,
|
prelude::Res,
|
||||||
query::{QueryItem, ReadOnlyWorldQueryData, WorldQueryFilter},
|
query::{QueryFilter, QueryItem, ReadOnlyQueryData},
|
||||||
system::{Query, ResMut, StaticSystemParam, SystemParam, SystemParamItem},
|
system::{Query, ResMut, StaticSystemParam, SystemParam, SystemParamItem},
|
||||||
};
|
};
|
||||||
use bevy_utils::nonmax::NonMaxU32;
|
use bevy_utils::nonmax::NonMaxU32;
|
||||||
|
@ -57,8 +57,8 @@ impl<T: PartialEq> BatchMeta<T> {
|
||||||
/// items.
|
/// items.
|
||||||
pub trait GetBatchData {
|
pub trait GetBatchData {
|
||||||
type Param: SystemParam + 'static;
|
type Param: SystemParam + 'static;
|
||||||
type Query: ReadOnlyWorldQueryData;
|
type Data: ReadOnlyQueryData;
|
||||||
type QueryFilter: WorldQueryFilter;
|
type Filter: QueryFilter;
|
||||||
/// Data used for comparison between phase items. If the pipeline id, draw
|
/// Data used for comparison between phase items. If the pipeline id, draw
|
||||||
/// function id, per-instance data buffer dynamic offset and this data
|
/// function id, per-instance data buffer dynamic offset and this data
|
||||||
/// matches, the draws can be batched.
|
/// matches, the draws can be batched.
|
||||||
|
@ -72,7 +72,7 @@ pub trait GetBatchData {
|
||||||
/// for the `CompareData`.
|
/// for the `CompareData`.
|
||||||
fn get_batch_data(
|
fn get_batch_data(
|
||||||
param: &SystemParamItem<Self::Param>,
|
param: &SystemParamItem<Self::Param>,
|
||||||
query_item: &QueryItem<Self::Query>,
|
query_item: &QueryItem<Self::Data>,
|
||||||
) -> (Self::BufferData, Option<Self::CompareData>);
|
) -> (Self::BufferData, Option<Self::CompareData>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ pub trait GetBatchData {
|
||||||
pub fn batch_and_prepare_render_phase<I: CachedRenderPipelinePhaseItem, F: GetBatchData>(
|
pub fn batch_and_prepare_render_phase<I: CachedRenderPipelinePhaseItem, F: GetBatchData>(
|
||||||
gpu_array_buffer: ResMut<GpuArrayBuffer<F::BufferData>>,
|
gpu_array_buffer: ResMut<GpuArrayBuffer<F::BufferData>>,
|
||||||
mut views: Query<&mut RenderPhase<I>>,
|
mut views: Query<&mut RenderPhase<I>>,
|
||||||
query: Query<F::Query, F::QueryFilter>,
|
query: Query<F::Data, F::Filter>,
|
||||||
param: StaticSystemParam<F::Param>,
|
param: StaticSystemParam<F::Param>,
|
||||||
) {
|
) {
|
||||||
let gpu_array_buffer = gpu_array_buffer.into_inner();
|
let gpu_array_buffer = gpu_array_buffer.into_inner();
|
||||||
|
|
|
@ -9,7 +9,7 @@ use bevy_asset::{Asset, Handle};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Component,
|
component::Component,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
query::{QueryItem, ReadOnlyWorldQueryData, WorldQueryFilter},
|
query::{QueryFilter, QueryItem, ReadOnlyQueryData},
|
||||||
system::lifetimeless::Read,
|
system::lifetimeless::Read,
|
||||||
};
|
};
|
||||||
use std::{marker::PhantomData, ops::Deref};
|
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"
|
/// Therefore the component is transferred from the "app world" into the "render world"
|
||||||
/// in the [`ExtractSchedule`] step.
|
/// in the [`ExtractSchedule`] step.
|
||||||
pub trait ExtractComponent: Component {
|
pub trait ExtractComponent: Component {
|
||||||
/// ECS [`ReadOnlyWorldQueryData`] to fetch the components to extract.
|
/// ECS [`ReadOnlyQueryData`] to fetch the components to extract.
|
||||||
type Query: ReadOnlyWorldQueryData;
|
type Data: ReadOnlyQueryData;
|
||||||
/// Filters the entities with additional constraints.
|
/// Filters the entities with additional constraints.
|
||||||
type Filter: WorldQueryFilter;
|
type Filter: QueryFilter;
|
||||||
|
|
||||||
/// The output from extraction.
|
/// The output from extraction.
|
||||||
///
|
///
|
||||||
|
@ -58,7 +58,7 @@ pub trait ExtractComponent: Component {
|
||||||
// type Out: Component = Self;
|
// type Out: Component = Self;
|
||||||
|
|
||||||
/// Defines how the component is transferred into the "render world".
|
/// 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
|
/// 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> {
|
impl<T: Asset> ExtractComponent for Handle<T> {
|
||||||
type Query = Read<Handle<T>>;
|
type Data = Read<Handle<T>>;
|
||||||
type Filter = ();
|
type Filter = ();
|
||||||
type Out = Handle<T>;
|
type Out = Handle<T>;
|
||||||
|
|
||||||
#[inline]
|
#[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())
|
Some(handle.clone_weak())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ impl<T: Asset> ExtractComponent for Handle<T> {
|
||||||
fn extract_components<C: ExtractComponent>(
|
fn extract_components<C: ExtractComponent>(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut previous_len: Local<usize>,
|
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);
|
let mut values = Vec::with_capacity(*previous_len);
|
||||||
for (entity, query_item) in &query {
|
for (entity, query_item) in &query {
|
||||||
|
@ -225,7 +225,7 @@ fn extract_components<C: ExtractComponent>(
|
||||||
fn extract_visible_components<C: ExtractComponent>(
|
fn extract_visible_components<C: ExtractComponent>(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut previous_len: Local<usize>,
|
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);
|
let mut values = Vec::with_capacity(*previous_len);
|
||||||
for (entity, view_visibility, query_item) in &query {
|
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_derive::{Deref, DerefMut};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
prelude::Entity,
|
prelude::Entity,
|
||||||
query::{QueryItem, ReadOnlyWorldQueryData, WorldQueryFilter},
|
query::{QueryFilter, QueryItem, ReadOnlyQueryData},
|
||||||
system::{lifetimeless::Read, Query, ResMut, Resource},
|
system::{lifetimeless::Read, Query, ResMut, Resource},
|
||||||
};
|
};
|
||||||
use bevy_utils::EntityHashMap;
|
use bevy_utils::EntityHashMap;
|
||||||
|
@ -28,13 +28,13 @@ use crate::{prelude::ViewVisibility, Extract, ExtractSchedule, RenderApp};
|
||||||
/// [`ExtractComponent`](crate::extract_component::ExtractComponent), but
|
/// [`ExtractComponent`](crate::extract_component::ExtractComponent), but
|
||||||
/// higher-performance because it avoids the ECS overhead.
|
/// higher-performance because it avoids the ECS overhead.
|
||||||
pub trait ExtractInstance: Send + Sync + Sized + 'static {
|
pub trait ExtractInstance: Send + Sync + Sized + 'static {
|
||||||
/// ECS [`ReadOnlyWorldQueryData`] to fetch the components to extract.
|
/// ECS [`ReadOnlyQueryData`] to fetch the components to extract.
|
||||||
type Query: ReadOnlyWorldQueryData;
|
type Data: ReadOnlyQueryData;
|
||||||
/// Filters the entities with additional constraints.
|
/// Filters the entities with additional constraints.
|
||||||
type Filter: WorldQueryFilter;
|
type Filter: QueryFilter;
|
||||||
|
|
||||||
/// Defines how the component is transferred into the "render world".
|
/// 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
|
/// This plugin extracts one or more components into the "render world" as
|
||||||
|
@ -107,7 +107,7 @@ where
|
||||||
|
|
||||||
fn extract_all<EI>(
|
fn extract_all<EI>(
|
||||||
mut extracted_instances: ResMut<ExtractedInstances<EI>>,
|
mut extracted_instances: ResMut<ExtractedInstances<EI>>,
|
||||||
query: Extract<Query<(Entity, EI::Query), EI::Filter>>,
|
query: Extract<Query<(Entity, EI::Data), EI::Filter>>,
|
||||||
) where
|
) where
|
||||||
EI: ExtractInstance,
|
EI: ExtractInstance,
|
||||||
{
|
{
|
||||||
|
@ -121,7 +121,7 @@ fn extract_all<EI>(
|
||||||
|
|
||||||
fn extract_visible<EI>(
|
fn extract_visible<EI>(
|
||||||
mut extracted_instances: ResMut<ExtractedInstances<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
|
) where
|
||||||
EI: ExtractInstance,
|
EI: ExtractInstance,
|
||||||
{
|
{
|
||||||
|
@ -139,10 +139,10 @@ impl<A> ExtractInstance for AssetId<A>
|
||||||
where
|
where
|
||||||
A: Asset,
|
A: Asset,
|
||||||
{
|
{
|
||||||
type Query = Read<Handle<A>>;
|
type Data = Read<Handle<A>>;
|
||||||
type Filter = ();
|
type Filter = ();
|
||||||
|
|
||||||
fn extract(item: QueryItem<'_, Self::Query>) -> Option<Self> {
|
fn extract(item: QueryItem<'_, Self::Data>) -> Option<Self> {
|
||||||
Some(item.id())
|
Some(item.id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
renderer::RenderContext,
|
renderer::RenderContext,
|
||||||
};
|
};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
query::{QueryItem, QueryState, ReadOnlyWorldQueryData},
|
query::{QueryItem, QueryState, ReadOnlyQueryData},
|
||||||
world::{FromWorld, World},
|
world::{FromWorld, World},
|
||||||
};
|
};
|
||||||
use downcast_rs::{impl_downcast, Downcast};
|
use downcast_rs::{impl_downcast, Downcast};
|
||||||
|
@ -342,7 +342,7 @@ impl Node for RunGraphOnViewNode {
|
||||||
pub trait ViewNode {
|
pub trait ViewNode {
|
||||||
/// The query that will be used on the view entity.
|
/// 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
|
/// 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.
|
/// Updates internal node state using the current render [`World`] prior to the run method.
|
||||||
fn update(&mut self, _world: &mut World) {}
|
fn update(&mut self, _world: &mut World) {}
|
||||||
|
@ -354,7 +354,7 @@ pub trait ViewNode {
|
||||||
&self,
|
&self,
|
||||||
graph: &mut RenderGraphContext,
|
graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
view_query: QueryItem<Self::ViewQuery>,
|
view_query: QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError>;
|
) -> 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.
|
/// This [`Node`] exists to help reduce boilerplate when making a render node that runs on a view.
|
||||||
pub struct ViewNodeRunner<N: ViewNode> {
|
pub struct ViewNodeRunner<N: ViewNode> {
|
||||||
view_query: QueryState<N::ViewQuery>,
|
view_query: QueryState<N::ViewData>,
|
||||||
node: N,
|
node: N,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::render_phase::{PhaseItem, TrackedRenderPass};
|
||||||
use bevy_app::App;
|
use bevy_app::App;
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
query::{QueryState, ROQueryItem, ReadOnlyWorldQueryData},
|
query::{QueryState, ROQueryItem, ReadOnlyQueryData},
|
||||||
system::{ReadOnlySystemParam, Resource, SystemParam, SystemParamItem, SystemState},
|
system::{ReadOnlySystemParam, Resource, SystemParam, SystemParamItem, SystemState},
|
||||||
world::World,
|
world::World,
|
||||||
};
|
};
|
||||||
|
@ -142,8 +142,8 @@ impl<P: PhaseItem> DrawFunctions<P> {
|
||||||
/// Compared to the draw function the required ECS data is fetched automatically
|
/// Compared to the draw function the required ECS data is fetched automatically
|
||||||
/// (by the [`RenderCommandState`]) from the render world.
|
/// (by the [`RenderCommandState`]) from the render world.
|
||||||
/// Therefore the three types [`Param`](RenderCommand::Param),
|
/// Therefore the three types [`Param`](RenderCommand::Param),
|
||||||
/// [`ViewWorldQuery`](RenderCommand::ViewWorldQuery) and
|
/// [`ViewData`](RenderCommand::ViewData) and
|
||||||
/// [`ItemWorldQuery`](RenderCommand::ItemWorldQuery) are used.
|
/// [`ItemData`](RenderCommand::ItemData) are used.
|
||||||
/// They specify which information is required to execute the render command.
|
/// They specify which information is required to execute the render command.
|
||||||
///
|
///
|
||||||
/// Multiple render commands can be combined together by wrapping them in a tuple.
|
/// 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
|
/// The view entity refers to the camera, or shadow-casting light, etc. from which the phase
|
||||||
/// item will be rendered from.
|
/// item will be rendered from.
|
||||||
/// All components have to be accessed read only.
|
/// 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`].
|
/// 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.
|
/// The item is the entity that will be rendered for the corresponding view.
|
||||||
/// All components have to be accessed read only.
|
/// 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,
|
/// Renders a [`PhaseItem`] by recording commands (e.g. setting pipelines, binding bind groups,
|
||||||
/// issuing draw calls, etc.) via the [`TrackedRenderPass`].
|
/// issuing draw calls, etc.) via the [`TrackedRenderPass`].
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
item: &P,
|
item: &P,
|
||||||
view: ROQueryItem<'w, Self::ViewWorldQuery>,
|
view: ROQueryItem<'w, Self::ViewData>,
|
||||||
entity: ROQueryItem<'w, Self::ItemWorldQuery>,
|
entity: ROQueryItem<'w, Self::ItemData>,
|
||||||
param: SystemParamItem<'w, '_, Self::Param>,
|
param: SystemParamItem<'w, '_, Self::Param>,
|
||||||
pass: &mut TrackedRenderPass<'w>,
|
pass: &mut TrackedRenderPass<'w>,
|
||||||
) -> RenderCommandResult;
|
) -> RenderCommandResult;
|
||||||
|
@ -207,14 +207,14 @@ macro_rules! render_command_tuple_impl {
|
||||||
($(($name: ident, $view: ident, $entity: ident)),*) => {
|
($(($name: ident, $view: ident, $entity: ident)),*) => {
|
||||||
impl<P: PhaseItem, $($name: RenderCommand<P>),*> RenderCommand<P> for ($($name,)*) {
|
impl<P: PhaseItem, $($name: RenderCommand<P>),*> RenderCommand<P> for ($($name,)*) {
|
||||||
type Param = ($($name::Param,)*);
|
type Param = ($($name::Param,)*);
|
||||||
type ViewWorldQuery = ($($name::ViewWorldQuery,)*);
|
type ViewData = ($($name::ViewData,)*);
|
||||||
type ItemWorldQuery = ($($name::ItemWorldQuery,)*);
|
type ItemData = ($($name::ItemData,)*);
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
($($view,)*): ROQueryItem<'w, Self::ViewWorldQuery>,
|
($($view,)*): ROQueryItem<'w, Self::ViewData>,
|
||||||
($($entity,)*): ROQueryItem<'w, Self::ItemWorldQuery>,
|
($($entity,)*): ROQueryItem<'w, Self::ItemData>,
|
||||||
($($name,)*): SystemParamItem<'w, '_, Self::Param>,
|
($($name,)*): SystemParamItem<'w, '_, Self::Param>,
|
||||||
_pass: &mut TrackedRenderPass<'w>,
|
_pass: &mut TrackedRenderPass<'w>,
|
||||||
) -> RenderCommandResult {
|
) -> 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.
|
/// Wraps a [`RenderCommand`] into a state so that it can be used as a [`Draw`] function.
|
||||||
///
|
///
|
||||||
/// The [`RenderCommand::Param`], [`RenderCommand::ViewWorldQuery`] and
|
/// The [`RenderCommand::Param`], [`RenderCommand::ViewData`] and
|
||||||
/// [`RenderCommand::ItemWorldQuery`] are fetched from the ECS and passed to the command.
|
/// [`RenderCommand::ItemData`] are fetched from the ECS and passed to the command.
|
||||||
pub struct RenderCommandState<P: PhaseItem + 'static, C: RenderCommand<P>> {
|
pub struct RenderCommandState<P: PhaseItem + 'static, C: RenderCommand<P>> {
|
||||||
state: SystemState<C::Param>,
|
state: SystemState<C::Param>,
|
||||||
view: QueryState<C::ViewWorldQuery>,
|
view: QueryState<C::ViewData>,
|
||||||
entity: QueryState<C::ItemWorldQuery>,
|
entity: QueryState<C::ItemData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: PhaseItem, C: RenderCommand<P>> RenderCommandState<P, C> {
|
impl<P: PhaseItem, C: RenderCommand<P>> RenderCommandState<P, C> {
|
||||||
|
|
|
@ -196,8 +196,8 @@ pub struct SetItemPipeline;
|
||||||
|
|
||||||
impl<P: CachedRenderPipelinePhaseItem> RenderCommand<P> for SetItemPipeline {
|
impl<P: CachedRenderPipelinePhaseItem> RenderCommand<P> for SetItemPipeline {
|
||||||
type Param = SRes<PipelineCache>;
|
type Param = SRes<PipelineCache>;
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
item: &P,
|
item: &P,
|
||||||
|
|
|
@ -330,8 +330,8 @@ impl<P: PhaseItem, M: Material2d, const I: usize> RenderCommand<P>
|
||||||
SRes<RenderMaterials2d<M>>,
|
SRes<RenderMaterials2d<M>>,
|
||||||
SRes<RenderMaterial2dInstances<M>>,
|
SRes<RenderMaterial2dInstances<M>>,
|
||||||
);
|
);
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
|
|
@ -339,14 +339,14 @@ impl Mesh2dPipeline {
|
||||||
|
|
||||||
impl GetBatchData for Mesh2dPipeline {
|
impl GetBatchData for Mesh2dPipeline {
|
||||||
type Param = SRes<RenderMesh2dInstances>;
|
type Param = SRes<RenderMesh2dInstances>;
|
||||||
type Query = Entity;
|
type Data = Entity;
|
||||||
type QueryFilter = With<Mesh2d>;
|
type Filter = With<Mesh2d>;
|
||||||
type CompareData = (Material2dBindGroupId, AssetId<Mesh>);
|
type CompareData = (Material2dBindGroupId, AssetId<Mesh>);
|
||||||
type BufferData = Mesh2dUniform;
|
type BufferData = Mesh2dUniform;
|
||||||
|
|
||||||
fn get_batch_data(
|
fn get_batch_data(
|
||||||
mesh_instances: &SystemParamItem<Self::Param>,
|
mesh_instances: &SystemParamItem<Self::Param>,
|
||||||
entity: &QueryItem<Self::Query>,
|
entity: &QueryItem<Self::Data>,
|
||||||
) -> (Self::BufferData, Option<Self::CompareData>) {
|
) -> (Self::BufferData, Option<Self::CompareData>) {
|
||||||
let mesh_instance = mesh_instances
|
let mesh_instance = mesh_instances
|
||||||
.get(entity)
|
.get(entity)
|
||||||
|
@ -617,13 +617,13 @@ pub fn prepare_mesh2d_view_bind_groups(
|
||||||
pub struct SetMesh2dViewBindGroup<const I: usize>;
|
pub struct SetMesh2dViewBindGroup<const I: usize>;
|
||||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dViewBindGroup<I> {
|
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dViewBindGroup<I> {
|
||||||
type Param = ();
|
type Param = ();
|
||||||
type ViewWorldQuery = (Read<ViewUniformOffset>, Read<Mesh2dViewBindGroup>);
|
type ViewData = (Read<ViewUniformOffset>, Read<Mesh2dViewBindGroup>);
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
(view_uniform, mesh2d_view_bind_group): ROQueryItem<'w, Self::ViewWorldQuery>,
|
(view_uniform, mesh2d_view_bind_group): ROQueryItem<'w, Self::ViewData>,
|
||||||
_view: (),
|
_view: (),
|
||||||
_param: SystemParamItem<'w, '_, Self::Param>,
|
_param: SystemParamItem<'w, '_, Self::Param>,
|
||||||
pass: &mut TrackedRenderPass<'w>,
|
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>;
|
pub struct SetMesh2dBindGroup<const I: usize>;
|
||||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dBindGroup<I> {
|
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dBindGroup<I> {
|
||||||
type Param = SRes<Mesh2dBindGroup>;
|
type Param = SRes<Mesh2dBindGroup>;
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
@ -666,8 +666,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMesh2dBindGroup<I> {
|
||||||
pub struct DrawMesh2d;
|
pub struct DrawMesh2d;
|
||||||
impl<P: PhaseItem> RenderCommand<P> for DrawMesh2d {
|
impl<P: PhaseItem> RenderCommand<P> for DrawMesh2d {
|
||||||
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMesh2dInstances>);
|
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMesh2dInstances>);
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
|
|
@ -766,8 +766,8 @@ pub type DrawSprite = (
|
||||||
pub struct SetSpriteViewBindGroup<const I: usize>;
|
pub struct SetSpriteViewBindGroup<const I: usize>;
|
||||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteViewBindGroup<I> {
|
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteViewBindGroup<I> {
|
||||||
type Param = SRes<SpriteMeta>;
|
type Param = SRes<SpriteMeta>;
|
||||||
type ViewWorldQuery = Read<ViewUniformOffset>;
|
type ViewData = Read<ViewUniformOffset>;
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
|
@ -787,8 +787,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteViewBindGroup<I
|
||||||
pub struct SetSpriteTextureBindGroup<const I: usize>;
|
pub struct SetSpriteTextureBindGroup<const I: usize>;
|
||||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteTextureBindGroup<I> {
|
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteTextureBindGroup<I> {
|
||||||
type Param = SRes<ImageBindGroups>;
|
type Param = SRes<ImageBindGroups>;
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<SpriteBatch>;
|
type ItemData = Read<SpriteBatch>;
|
||||||
|
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
|
@ -814,8 +814,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetSpriteTextureBindGrou
|
||||||
pub struct DrawSpriteBatch;
|
pub struct DrawSpriteBatch;
|
||||||
impl<P: PhaseItem> RenderCommand<P> for DrawSpriteBatch {
|
impl<P: PhaseItem> RenderCommand<P> for DrawSpriteBatch {
|
||||||
type Param = SRes<SpriteMeta>;
|
type Param = SRes<SpriteMeta>;
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<SpriteBatch>;
|
type ItemData = Read<SpriteBatch>;
|
||||||
|
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use bevy_ecs::{
|
||||||
change_detection::DetectChangesMut,
|
change_detection::DetectChangesMut,
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
prelude::{Component, With},
|
prelude::{Component, With},
|
||||||
query::WorldQueryData,
|
query::QueryData,
|
||||||
reflect::ReflectComponent,
|
reflect::ReflectComponent,
|
||||||
system::{Local, Query, Res},
|
system::{Local, Query, Res},
|
||||||
};
|
};
|
||||||
|
@ -105,8 +105,8 @@ pub struct State {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Main query for [`ui_focus_system`]
|
/// Main query for [`ui_focus_system`]
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(mutable)]
|
#[query_data(mutable)]
|
||||||
pub struct NodeQuery {
|
pub struct NodeQuery {
|
||||||
entity: Entity,
|
entity: Entity,
|
||||||
node: &'static Node,
|
node: &'static Node,
|
||||||
|
|
|
@ -157,8 +157,8 @@ pub type DrawUi = (
|
||||||
pub struct SetUiViewBindGroup<const I: usize>;
|
pub struct SetUiViewBindGroup<const I: usize>;
|
||||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiViewBindGroup<I> {
|
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiViewBindGroup<I> {
|
||||||
type Param = SRes<UiMeta>;
|
type Param = SRes<UiMeta>;
|
||||||
type ViewWorldQuery = Read<ViewUniformOffset>;
|
type ViewData = Read<ViewUniformOffset>;
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
|
@ -178,8 +178,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiViewBindGroup<I> {
|
||||||
pub struct SetUiTextureBindGroup<const I: usize>;
|
pub struct SetUiTextureBindGroup<const I: usize>;
|
||||||
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiTextureBindGroup<I> {
|
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiTextureBindGroup<I> {
|
||||||
type Param = SRes<UiImageBindGroups>;
|
type Param = SRes<UiImageBindGroups>;
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<UiBatch>;
|
type ItemData = Read<UiBatch>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
@ -197,8 +197,8 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetUiTextureBindGroup<I>
|
||||||
pub struct DrawUiNode;
|
pub struct DrawUiNode;
|
||||||
impl<P: PhaseItem> RenderCommand<P> for DrawUiNode {
|
impl<P: PhaseItem> RenderCommand<P> for DrawUiNode {
|
||||||
type Param = SRes<UiMeta>;
|
type Param = SRes<UiMeta>;
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<UiBatch>;
|
type ItemData = Read<UiBatch>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
|
|
@ -263,8 +263,8 @@ pub type DrawUiMaterial<M> = (
|
||||||
pub struct SetMatUiViewBindGroup<M: UiMaterial, const I: usize>(PhantomData<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> {
|
impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P> for SetMatUiViewBindGroup<M, I> {
|
||||||
type Param = SRes<UiMaterialMeta<M>>;
|
type Param = SRes<UiMaterialMeta<M>>;
|
||||||
type ViewWorldQuery = Read<ViewUniformOffset>;
|
type ViewData = Read<ViewUniformOffset>;
|
||||||
type ItemWorldQuery = ();
|
type ItemData = ();
|
||||||
|
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
|
@ -287,13 +287,13 @@ impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P>
|
||||||
for SetUiMaterialBindGroup<M, I>
|
for SetUiMaterialBindGroup<M, I>
|
||||||
{
|
{
|
||||||
type Param = SRes<RenderUiMaterials<M>>;
|
type Param = SRes<RenderUiMaterials<M>>;
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<UiMaterialBatch<M>>;
|
type ItemData = Read<UiMaterialBatch<M>>;
|
||||||
|
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
_item: &P,
|
_item: &P,
|
||||||
_view: (),
|
_view: (),
|
||||||
material_handle: ROQueryItem<'_, Self::ItemWorldQuery>,
|
material_handle: ROQueryItem<'_, Self::ItemData>,
|
||||||
materials: SystemParamItem<'w, '_, Self::Param>,
|
materials: SystemParamItem<'w, '_, Self::Param>,
|
||||||
pass: &mut TrackedRenderPass<'w>,
|
pass: &mut TrackedRenderPass<'w>,
|
||||||
) -> RenderCommandResult {
|
) -> RenderCommandResult {
|
||||||
|
@ -308,8 +308,8 @@ impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P>
|
||||||
pub struct DrawUiMaterialNode<M>(PhantomData<M>);
|
pub struct DrawUiMaterialNode<M>(PhantomData<M>);
|
||||||
impl<P: PhaseItem, M: UiMaterial> RenderCommand<P> for DrawUiMaterialNode<M> {
|
impl<P: PhaseItem, M: UiMaterial> RenderCommand<P> for DrawUiMaterialNode<M> {
|
||||||
type Param = SRes<UiMaterialMeta<M>>;
|
type Param = SRes<UiMaterialMeta<M>>;
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<UiMaterialBatch<M>>;
|
type ItemData = Read<UiMaterialBatch<M>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//! For more details on the `WorldQuery` derive macro, see the trait documentation.
|
//! For more details on the `WorldQuery` derive macro, see the trait documentation.
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
ecs::query::{WorldQueryData, WorldQueryFilter},
|
ecs::query::{QueryData, QueryFilter},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
@ -45,8 +45,8 @@ struct ComponentD;
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
struct ComponentZ;
|
struct ComponentZ;
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(derive(Debug))]
|
#[query_data(derive(Debug))]
|
||||||
struct ReadOnlyCustomQuery<T: Component + Debug, P: Component + Debug> {
|
struct ReadOnlyCustomQuery<T: Component + Debug, P: Component + Debug> {
|
||||||
entity: Entity,
|
entity: Entity,
|
||||||
a: &'static ComponentA,
|
a: &'static ComponentA,
|
||||||
|
@ -59,7 +59,10 @@ struct ReadOnlyCustomQuery<T: Component + Debug, P: Component + Debug> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_components_read_only(
|
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):");
|
println!("Print components (read_only):");
|
||||||
for e in &query {
|
for e in &query {
|
||||||
|
@ -79,8 +82,8 @@ fn print_components_read_only(
|
||||||
// suffix.
|
// suffix.
|
||||||
// Note: if you want to use derive macros with read-only query variants, you need to pass them with
|
// Note: if you want to use derive macros with read-only query variants, you need to pass them with
|
||||||
// using the `derive` attribute.
|
// using the `derive` attribute.
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(mutable, derive(Debug))]
|
#[query_data(mutable, derive(Debug))]
|
||||||
struct CustomQuery<T: Component + Debug, P: Component + Debug> {
|
struct CustomQuery<T: Component + Debug, P: Component + Debug> {
|
||||||
entity: Entity,
|
entity: Entity,
|
||||||
a: &'static mut ComponentA,
|
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.
|
// This is a valid query as well, which would iterate over every entity.
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(derive(Debug))]
|
#[query_data(derive(Debug))]
|
||||||
struct EmptyQuery {
|
struct EmptyQuery {
|
||||||
empty: (),
|
empty: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(derive(Debug))]
|
#[query_data(derive(Debug))]
|
||||||
struct NestedQuery {
|
struct NestedQuery {
|
||||||
c: &'static ComponentC,
|
c: &'static ComponentC,
|
||||||
d: Option<&'static ComponentD>,
|
d: Option<&'static ComponentD>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(WorldQueryData)]
|
#[derive(QueryData)]
|
||||||
#[world_query_data(derive(Debug))]
|
#[query_data(derive(Debug))]
|
||||||
struct GenericQuery<T: Component, P: Component> {
|
struct GenericQuery<T: Component, P: Component> {
|
||||||
generic: (&'static T, &'static P),
|
generic: (&'static T, &'static P),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(WorldQueryFilter)]
|
#[derive(QueryFilter)]
|
||||||
struct QueryFilter<T: Component, P: Component> {
|
struct CustomQueryFilter<T: Component, P: Component> {
|
||||||
_c: With<ComponentC>,
|
_c: With<ComponentC>,
|
||||||
_d: With<ComponentD>,
|
_d: With<ComponentD>,
|
||||||
_or: Or<(Added<ComponentC>, Changed<ComponentD>, Without<ComponentZ>)>,
|
_or: Or<(Added<ComponentC>, Changed<ComponentD>, Without<ComponentZ>)>,
|
||||||
|
@ -125,7 +128,10 @@ fn spawn(mut commands: Commands) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_components_iter_mut(
|
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):");
|
println!("Print components (iter_mut):");
|
||||||
for e in &mut query {
|
for e in &mut query {
|
||||||
|
@ -143,7 +149,7 @@ fn print_components_iter_mut(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_components_iter(
|
fn print_components_iter(
|
||||||
query: Query<CustomQuery<ComponentC, ComponentD>, QueryFilter<ComponentC, ComponentD>>,
|
query: Query<CustomQuery<ComponentC, ComponentD>, CustomQueryFilter<ComponentC, ComponentD>>,
|
||||||
) {
|
) {
|
||||||
println!("Print components (iter):");
|
println!("Print components (iter):");
|
||||||
for e in &query {
|
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.
|
// but it's not a normal system so we need to define it manually.
|
||||||
//
|
//
|
||||||
// This query will only run on the view entity
|
// This query will only run on the view entity
|
||||||
type ViewQuery = (
|
type ViewData = (
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
// This makes sure the node only runs on cameras with the PostProcessSettings component
|
// This makes sure the node only runs on cameras with the PostProcessSettings component
|
||||||
&'static PostProcessSettings,
|
&'static PostProcessSettings,
|
||||||
|
@ -133,7 +133,7 @@ impl ViewNode for PostProcessNode {
|
||||||
&self,
|
&self,
|
||||||
_graph: &mut RenderGraphContext,
|
_graph: &mut RenderGraphContext,
|
||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
(view_target, _post_process_settings): QueryItem<Self::ViewQuery>,
|
(view_target, _post_process_settings): QueryItem<Self::ViewData>,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
// Get the pipeline resource that contains the global data we need
|
// 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>);
|
struct InstanceMaterialData(Vec<InstanceData>);
|
||||||
|
|
||||||
impl ExtractComponent for InstanceMaterialData {
|
impl ExtractComponent for InstanceMaterialData {
|
||||||
type Query = &'static InstanceMaterialData;
|
type Data = &'static InstanceMaterialData;
|
||||||
type Filter = ();
|
type Filter = ();
|
||||||
type Out = Self;
|
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()))
|
Some(InstanceMaterialData(item.0.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,8 +237,8 @@ pub struct DrawMeshInstanced;
|
||||||
|
|
||||||
impl<P: PhaseItem> RenderCommand<P> for DrawMeshInstanced {
|
impl<P: PhaseItem> RenderCommand<P> for DrawMeshInstanced {
|
||||||
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMeshInstances>);
|
type Param = (SRes<RenderAssets<Mesh>>, SRes<RenderMeshInstances>);
|
||||||
type ViewWorldQuery = ();
|
type ViewData = ();
|
||||||
type ItemWorldQuery = Read<InstanceBuffer>;
|
type ItemData = Read<InstanceBuffer>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render<'w>(
|
fn render<'w>(
|
||||||
|
|
Loading…
Reference in a new issue