From dcc35120f955dd921149c1a9ed3b68bf3cec848e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Ce=C5=A1pivo?= Date: Thu, 19 Oct 2023 22:18:33 +0200 Subject: [PATCH] chore: use ExtractComponent derive macro for EnvironmentMapLight and FogSettings (#10191) I've done tiny cleanup when playing with code. ## Solution [derive macro](https://github.com/bevyengine/bevy/blob/main/crates/bevy_render/macros/src/extract_component.rs) with `extract_component_filter` attribute generate the same code I removed. ## Migration Guide No migration needed --- crates/bevy_pbr/src/environment_map/mod.rs | 13 ++----------- crates/bevy_pbr/src/fog.rs | 15 +++------------ 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index bc3bda5a86..f46f0309f0 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -46,7 +46,8 @@ impl Plugin for EnvironmentMapPlugin { /// The diffuse map uses the Lambertian distribution, and the specular map uses the GGX distribution. /// /// `KhronosGroup` also has several prefiltered environment maps that can be found [here](https://github.com/KhronosGroup/glTF-Sample-Environments). -#[derive(Component, Reflect, Clone)] +#[derive(Component, Reflect, Clone, ExtractComponent)] +#[extract_component_filter(With)] pub struct EnvironmentMapLight { pub diffuse_map: Handle, pub specular_map: Handle, @@ -60,16 +61,6 @@ impl EnvironmentMapLight { } } -impl ExtractComponent for EnvironmentMapLight { - type Query = &'static Self; - type Filter = With; - type Out = Self; - - fn extract_component(item: bevy_ecs::query::QueryItem<'_, Self::Query>) -> Option { - Some(item.clone()) - } -} - pub fn get_bindings<'a>( environment_map_light: Option<&EnvironmentMapLight>, images: &'a RenderAssets, diff --git a/crates/bevy_pbr/src/fog.rs b/crates/bevy_pbr/src/fog.rs index c5ad092f54..d4c3c3c77f 100644 --- a/crates/bevy_pbr/src/fog.rs +++ b/crates/bevy_pbr/src/fog.rs @@ -1,5 +1,5 @@ use crate::ReflectComponent; -use bevy_ecs::{prelude::*, query::QueryItem}; +use bevy_ecs::prelude::*; use bevy_math::Vec3; use bevy_reflect::Reflect; use bevy_render::{color::Color, extract_component::ExtractComponent, prelude::Camera}; @@ -47,7 +47,8 @@ use bevy_render::{color::Color, extract_component::ExtractComponent, prelude::Ca /// /// Once enabled for a specific camera, the fog effect can also be disabled for individual /// [`StandardMaterial`](crate::StandardMaterial) instances via the `fog_enabled` flag. -#[derive(Debug, Clone, Component, Reflect)] +#[derive(Debug, Clone, Component, Reflect, ExtractComponent)] +#[extract_component_filter(With)] #[reflect(Component)] pub struct FogSettings { /// The color of the fog effect. @@ -474,13 +475,3 @@ impl Default for FogSettings { } } } - -impl ExtractComponent for FogSettings { - type Query = &'static Self; - type Filter = With; - type Out = Self; - - fn extract_component(item: QueryItem) -> Option { - Some(item.clone()) - } -}