Skip to content

Commit 849bb1a

Browse files
committed
Add a system set for the condition coming from conditional_render_set.
1 parent 3a91f1a commit 849bb1a

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

crates/bevy_render/src/lib.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,12 @@ pub fn conditional_render_set<S: SystemSet + Clone, M>(
725725
}
726726
});
727727
render_app
728-
.add_systems(RenderStartup, condition.before(system_set.clone()))
728+
.add_systems(
729+
RenderStartup,
730+
condition
731+
.in_set(ConditionalRenderSetCondition::<S>(PhantomData))
732+
.before(system_set.clone()),
733+
)
729734
.configure_sets(
730735
RenderStartup,
731736
system_set
@@ -743,3 +748,39 @@ pub fn conditional_render_set<S: SystemSet + Clone, M>(
743748
system_set.run_if(resource_exists::<EnabledRenderSet<S>>),
744749
);
745750
}
751+
752+
/// A system set for the condition used in `conditional_render_set`.
753+
///
754+
/// This allows the condition to be ordered after its dependencies for example.
755+
#[derive(SystemSet)]
756+
pub struct ConditionalRenderSetCondition<S: SystemSet>(pub PhantomData<fn() -> S>);
757+
758+
// Manual impls of SystemSet required traits to prevent needing `S` to implement those traits.
759+
760+
impl<S: SystemSet> Clone for ConditionalRenderSetCondition<S> {
761+
fn clone(&self) -> Self {
762+
Self(self.0.clone())
763+
}
764+
}
765+
766+
impl<S: SystemSet> core::fmt::Debug for ConditionalRenderSetCondition<S> {
767+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
768+
f.debug_tuple("ConditionalRenderSetCondition")
769+
.field(&self.0)
770+
.finish()
771+
}
772+
}
773+
774+
impl<S: SystemSet> core::hash::Hash for ConditionalRenderSetCondition<S> {
775+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
776+
self.0.hash(state);
777+
}
778+
}
779+
780+
impl<S: SystemSet> Eq for ConditionalRenderSetCondition<S> {}
781+
782+
impl<S: SystemSet> PartialEq for ConditionalRenderSetCondition<S> {
783+
fn eq(&self, other: &Self) -> bool {
784+
self.0 == other.0
785+
}
786+
}

0 commit comments

Comments
 (0)