Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions crates/bevy_render/src/extract_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<C: Component> DynamicUniformIndex<C> {
/// The marker type is only used as a way to bypass the orphan rules. To
/// implement the trait for a foreign type you can use a local type as the
/// marker, e.g. the type of the plugin that calls [`ExtractComponentPlugin`].
pub trait ExtractComponent<Marker = ()>: SyncComponent {
pub trait ExtractComponent<Marker = ()>: SyncComponent<Marker> {
/// ECS [`ReadOnlyQueryData`] to fetch the components to extract.
type QueryData: ReadOnlyQueryData;
/// Filters the entities with additional constraints.
Expand Down Expand Up @@ -174,9 +174,11 @@ impl<C, F> ExtractComponentPlugin<C, F> {
}
}

impl<C: ExtractComponent<Marker>, Marker: 'static> Plugin for ExtractComponentPlugin<C, Marker> {
impl<C: ExtractComponent<Marker> + SyncComponent<Marker>, Marker: 'static + Send + Sync> Plugin
Comment thread
Zeophlite marked this conversation as resolved.
Outdated
for ExtractComponentPlugin<C, Marker>
{
fn build(&self, app: &mut App) {
app.add_plugins(SyncComponentPlugin::<C>::default());
app.add_plugins(SyncComponentPlugin::<C, Marker>::default());

if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
if self.only_extract_visible {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_render/src/extract_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{Extract, ExtractSchedule, RenderApp};
///
/// Therefore the resource is transferred from the "main world" into the "render world"
/// in the [`ExtractSchedule`] step.
pub trait ExtractResource: Resource {
pub trait ExtractResource<Marker = ()>: Resource {
type Source: Resource;

/// Defines how the resource is transferred into the "render world".
Expand All @@ -22,18 +22,18 @@ pub trait ExtractResource: Resource {
///
/// Therefore it sets up the[`ExtractSchedule`] step
/// for the specified [`Resource`].
pub struct ExtractResourcePlugin<R: ExtractResource>(PhantomData<R>);
pub struct ExtractResourcePlugin<R: ExtractResource<M>, M = ()>(PhantomData<(R, M)>);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExtractComponent uses F for the marker, i think for "Foreign type" it would be nice to be consistent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called them Marker just to spell out that it isn't used for anything. I think F is probably fine as well, but M is used in too many places for Material.


impl<R: ExtractResource> Default for ExtractResourcePlugin<R> {
impl<R: ExtractResource<M>, M> Default for ExtractResourcePlugin<R, M> {
fn default() -> Self {
Self(PhantomData)
}
}

impl<R: ExtractResource> Plugin for ExtractResourcePlugin<R> {
impl<R: ExtractResource<M>, M: 'static + Send + Sync> Plugin for ExtractResourcePlugin<R, M> {
fn build(&self, app: &mut App) {
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
render_app.add_systems(ExtractSchedule, extract_resource::<R>);
render_app.add_systems(ExtractSchedule, extract_resource::<R, M>);
} else {
once!(bevy_log::error!(
"Render app did not exist when trying to add `extract_resource` for <{}>.",
Expand All @@ -44,7 +44,7 @@ impl<R: ExtractResource> Plugin for ExtractResourcePlugin<R> {
}

/// This system extracts the resource of the corresponding [`Resource`] type
pub fn extract_resource<R: ExtractResource>(
pub fn extract_resource<R: ExtractResource<M>, M>(
mut commands: Commands,
main_resource: Extract<Option<Res<R::Source>>>,
target_resource: Option<ResMut<R>>,
Expand Down