mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 06:00:20 +00:00
Remove Handle<T>
trait implementations that are dependent on Component
(#15749)
# Objective - Another step towards #15716 - Remove trait implementations that are dependent on `Handle<T>` being a `Component` ## Solution - Remove unused `ExtractComponent` trait implementation for `Handle<T>` - Remove unused `ExtractInstance` trait implementation for `AssetId` - Although the `ExtractInstance` trait wasn't used, the `AssetId`s were being stored inside of `ExtractedInstances` which has an `ExtractInstance` trait bound on its contents. I've upgraded the `RenderMaterialInstances` type alias to be its own resource, identical to `ExtractedInstances<AssetId<M>>` to get around that with minimal breakage. ## Testing Tested `many_cubes`, rendering did not explode
This commit is contained in:
parent
123a19afa9
commit
e19c53ebbd
3 changed files with 12 additions and 30 deletions
|
@ -18,6 +18,7 @@ use bevy_core_pipeline::{
|
|||
};
|
||||
use bevy_derive::{Deref, DerefMut};
|
||||
use bevy_ecs::{
|
||||
entity::EntityHashMap,
|
||||
prelude::*,
|
||||
system::{lifetimeless::SRes, SystemParamItem},
|
||||
};
|
||||
|
@ -25,7 +26,6 @@ use bevy_reflect::std_traits::ReflectDefault;
|
|||
use bevy_reflect::Reflect;
|
||||
use bevy_render::{
|
||||
camera::TemporalJitter,
|
||||
extract_instances::ExtractedInstances,
|
||||
extract_resource::ExtractResource,
|
||||
mesh::{Mesh3d, MeshVertexBufferLayoutRef, RenderMesh},
|
||||
render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets},
|
||||
|
@ -276,7 +276,7 @@ where
|
|||
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
|
||||
render_app
|
||||
.init_resource::<DrawFunctions<Shadow>>()
|
||||
.init_resource::<ExtractedInstances<AssetId<M>>>()
|
||||
.init_resource::<RenderMaterialInstances<M>>()
|
||||
.add_render_command::<Shadow, DrawPrepass<M>>()
|
||||
.add_render_command::<Transmissive3d, DrawMaterial<M>>()
|
||||
.add_render_command::<Transparent3d, DrawMaterial<M>>()
|
||||
|
@ -490,7 +490,15 @@ impl<P: PhaseItem, M: Material, const I: usize> RenderCommand<P> for SetMaterial
|
|||
}
|
||||
}
|
||||
|
||||
pub type RenderMaterialInstances<M> = ExtractedInstances<AssetId<M>>;
|
||||
/// Stores all extracted instances of a [`Material`] in the render world.
|
||||
#[derive(Resource, Deref, DerefMut)]
|
||||
pub struct RenderMaterialInstances<M: Material>(pub EntityHashMap<AssetId<M>>);
|
||||
|
||||
impl<M: Material> Default for RenderMaterialInstances<M> {
|
||||
fn default() -> Self {
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn alpha_mode_pipeline_key(alpha_mode: AlphaMode, msaa: &Msaa) -> MeshPipelineKey {
|
||||
match alpha_mode {
|
||||
|
|
|
@ -7,12 +7,10 @@ use crate::{
|
|||
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
|
||||
};
|
||||
use bevy_app::{App, Plugin};
|
||||
use bevy_asset::{Asset, Handle};
|
||||
use bevy_ecs::{
|
||||
component::Component,
|
||||
prelude::*,
|
||||
query::{QueryFilter, QueryItem, ReadOnlyQueryData},
|
||||
system::lifetimeless::Read,
|
||||
};
|
||||
use core::{marker::PhantomData, ops::Deref};
|
||||
|
||||
|
@ -197,17 +195,6 @@ impl<C: ExtractComponent> Plugin for ExtractComponentPlugin<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Asset> ExtractComponent for Handle<T> {
|
||||
type QueryData = Read<Handle<T>>;
|
||||
type QueryFilter = ();
|
||||
type Out = Handle<T>;
|
||||
|
||||
#[inline]
|
||||
fn extract_component(handle: QueryItem<'_, Self::QueryData>) -> Option<Self::Out> {
|
||||
Some(handle.clone_weak())
|
||||
}
|
||||
}
|
||||
|
||||
/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`crate::sync_world::SyncToRenderWorld`].
|
||||
fn extract_components<C: ExtractComponent>(
|
||||
mut commands: Commands,
|
||||
|
|
|
@ -7,13 +7,12 @@
|
|||
use core::marker::PhantomData;
|
||||
|
||||
use bevy_app::{App, Plugin};
|
||||
use bevy_asset::{Asset, AssetId, Handle};
|
||||
use bevy_derive::{Deref, DerefMut};
|
||||
use bevy_ecs::{
|
||||
entity::EntityHashMap,
|
||||
prelude::Entity,
|
||||
query::{QueryFilter, QueryItem, ReadOnlyQueryData},
|
||||
system::{lifetimeless::Read, Query, ResMut, Resource},
|
||||
system::{Query, ResMut, Resource},
|
||||
};
|
||||
|
||||
use crate::{prelude::ViewVisibility, Extract, ExtractSchedule, RenderApp};
|
||||
|
@ -134,15 +133,3 @@ fn extract_visible<EI>(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> ExtractInstance for AssetId<A>
|
||||
where
|
||||
A: Asset,
|
||||
{
|
||||
type QueryData = Read<Handle<A>>;
|
||||
type QueryFilter = ();
|
||||
|
||||
fn extract(item: QueryItem<'_, Self::QueryData>) -> Option<Self> {
|
||||
Some(item.id())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue