Skip to content

Commit

Permalink
Merge problems and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed May 9, 2022
1 parent 637587f commit 533125a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
19 changes: 9 additions & 10 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,16 @@ pub fn extract_clusters(
#[allow(clippy::too_many_arguments)]
pub fn extract_lights(
mut commands: Commands,
ambient_light: Extract<Res<AmbientLight>>,
point_light_shadow_map: Extract<Res<PointLightShadowMap>>,
directional_light_shadow_map: Extract<Res<DirectionalLightShadowMap>>,
global_point_lights: Extract<Res<GlobalVisiblePointLights>>,
mut point_lights: Extract<Query<(&PointLight, &mut CubemapVisibleEntities, &GlobalTransform)>>,
mut ambient_light: Extract<Res<AmbientLight>>,
mut point_light_shadow_map: Extract<Res<PointLightShadowMap>>,
mut directional_light_shadow_map: Extract<Res<DirectionalLightShadowMap>>,
mut global_point_lights: Extract<Res<GlobalVisiblePointLights>>,
mut point_lights: Extract<Query<(&PointLight, &CubemapVisibleEntities, &GlobalTransform)>>,
mut directional_lights: Extract<
Query<(
Entity,
&DirectionalLight,
&mut VisibleEntities,
&VisibleEntities,
&GlobalTransform,
&Visibility,
)>,
Expand All @@ -457,13 +457,12 @@ pub fn extract_lights(
// https://catlikecoding.com/unity/tutorials/custom-srp/point-and-spot-shadows/
let point_light_texel_size = 2.0 / point_light_shadow_map.size as f32;

let point_lights = point_lights.value();
let mut point_lights = point_lights.value();
let mut point_lights_values = Vec::with_capacity(*previous_point_lights_len);
for entity in global_point_lights.iter().copied() {
for entity in global_point_lights.value().iter().copied() {
if let Ok((point_light, cubemap_visible_entities, transform)) = point_lights.get_mut(entity)
{
let render_cubemap_visible_entities =
std::mem::take(cubemap_visible_entities.into_inner());
let render_cubemap_visible_entities = cubemap_visible_entities.clone();
point_lights_values.push((
entity,
(
Expand Down
9 changes: 5 additions & 4 deletions crates/bevy_pbr/src/wireframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Plugin for WireframePlugin {
render_app
.add_render_command::<Opaque3d, DrawWireframes>()
.init_resource::<WireframePipeline>()
.init_resource::<WireframeConfig>()
.init_resource::<SpecializedMeshPipelines<WireframePipeline>>()
.add_system_to_stage(RenderStage::Extract, extract_wireframes)
.add_system_to_stage(RenderStage::Extract, extract_wireframe_config)
Expand All @@ -50,12 +51,12 @@ impl Plugin for WireframePlugin {
}

fn extract_wireframe_config(
mut commands: Commands,
mut config: ResMut<WireframeConfig>,
mut wireframe_config: Extract<Res<WireframeConfig>>,
) {
let wireframe_config = wireframe_config.value();
if wireframe_config.is_added() || wireframe_config.is_changed() {
commands.insert_resource(wireframe_config.into_inner().clone());
let extracted_config = wireframe_config.value();
if extracted_config.is_changed() {
*config = extracted_config.clone();
}
}

Expand Down
16 changes: 10 additions & 6 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ impl<T: Component + Default> Plugin for CameraTypePlugin<T> {
.add_startup_system_to_stage(StartupStage::PostStartup, set_active_camera::<T>)
.add_system_to_stage(CoreStage::PostUpdate, set_active_camera::<T>);
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app.add_system_to_stage(RenderStage::Extract, extract_cameras::<T>);
render_app
.init_resource::<ActiveCamera<T>>()
.add_system_to_stage(RenderStage::Extract, extract_cameras::<T>);
}
}
}
Expand Down Expand Up @@ -315,13 +317,17 @@ pub struct ExtractedCamera {

pub fn extract_cameras<M: Component + Default>(
mut commands: Commands,
mut active_camera: ResMut<ActiveCamera<M>>,
mut windows: Extract<Res<Windows>>,
mut images: Extract<Res<Assets<Image>>>,
mut active_camera: Extract<Res<ActiveCamera<M>>>,
mut extracted_active_camera: Extract<Res<ActiveCamera<M>>>,
mut query: Extract<Query<(&Camera, &GlobalTransform, &VisibleEntities), With<M>>>,
) {
let active_camera = active_camera.value();
if let Some(entity) = active_camera.get() {
let extracted_active_camera = extracted_active_camera.value();
if extracted_active_camera.is_changed() {
*active_camera = extracted_active_camera.clone();
}
if let Some(entity) = extracted_active_camera.get() {
if let Ok((camera, transform, visible_entities)) = query.value().get(entity) {
if let Some(size) = camera
.target
Expand All @@ -346,6 +352,4 @@ pub fn extract_cameras<M: Component + Default>(
}
}
}

commands.insert_resource(active_camera.clone())
}
14 changes: 9 additions & 5 deletions crates/bevy_render/src/render_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use bevy_asset::{Asset, Handle};
use bevy_ecs::{
component::Component,
prelude::*,
query::{QueryItem, ReadOnlyFetch, WorldQuery, WorldQueryGats},
system::{lifetimeless::Read, StaticSystemParam},
query::{QueryItem, WorldQuery},
system::{lifetimeless::Read, ReadOnlySystemParamFetch, StaticSystemParam, SystemParam},
};
use std::{marker::PhantomData, ops::Deref};

Expand Down Expand Up @@ -155,7 +155,11 @@ impl<C, F> ExtractComponentPlugin<C, F> {
}
}

impl<C: ExtractComponent> Plugin for ExtractComponentPlugin<C> {
impl<C: ExtractComponent> Plugin for ExtractComponentPlugin<C>
where
for<'w, 's> <Query<'w, 's, (Entity, C::Query), C::Filter> as SystemParam>::Fetch:
ReadOnlySystemParamFetch,
{
fn build(&self, app: &mut App) {
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
if self.only_extract_visible {
Expand Down Expand Up @@ -184,8 +188,8 @@ fn extract_components<C: ExtractComponent>(
mut previous_len: Local<usize>,
mut query: Extract<Query<(Entity, C::Query), C::Filter>>,
) where
<C::Filter as WorldQuery>::State: ReadOnlyFetch,
for<'x> <<C as ExtractComponent>::Query as WorldQueryGats<'x>>::Fetch: ReadOnlyFetch,
for<'w, 's> <Query<'w, 's, (Entity, C::Query), C::Filter> as SystemParam>::Fetch:
ReadOnlySystemParamFetch,
{
let mut values = Vec::with_capacity(*previous_len);
for (entity, query_item) in query.value().iter_mut() {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/view/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn extract_windows(
extracted_window.physical_height = new_height;
}
}
for closed_window in closed.iter() {
for closed_window in closed.value().iter() {
extracted_windows.remove(&closed_window.id);
}
}
Expand Down

0 comments on commit 533125a

Please sign in to comment.