Skip to content

Commit

Permalink
chore: use ExtractComponent derive macro for EnvironmentMapLight and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jancespivo authored Oct 19, 2023
1 parent 15c54b5 commit dcc3512
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
13 changes: 2 additions & 11 deletions crates/bevy_pbr/src/environment_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Camera3d>)]
pub struct EnvironmentMapLight {
pub diffuse_map: Handle<Image>,
pub specular_map: Handle<Image>,
Expand All @@ -60,16 +61,6 @@ impl EnvironmentMapLight {
}
}

impl ExtractComponent for EnvironmentMapLight {
type Query = &'static Self;
type Filter = With<Camera3d>;
type Out = Self;

fn extract_component(item: bevy_ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
Some(item.clone())
}
}

pub fn get_bindings<'a>(
environment_map_light: Option<&EnvironmentMapLight>,
images: &'a RenderAssets<Image>,
Expand Down
15 changes: 3 additions & 12 deletions crates/bevy_pbr/src/fog.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<Camera>)]
#[reflect(Component)]
pub struct FogSettings {
/// The color of the fog effect.
Expand Down Expand Up @@ -474,13 +475,3 @@ impl Default for FogSettings {
}
}
}

impl ExtractComponent for FogSettings {
type Query = &'static Self;
type Filter = With<Camera>;
type Out = Self;

fn extract_component(item: QueryItem<Self::Query>) -> Option<Self::Out> {
Some(item.clone())
}
}

0 comments on commit dcc3512

Please sign in to comment.