mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Optional .system()
, part 4 (run criteria) (#2431)
# Objective - Continue work of #2398 and friends. - Make `.system()` optional in run criteria APIs. ## Solution - Slight change to `RunCriteriaDescriptorCoercion` signature and implementors. - Implement `IntoRunCriteria` for `IntoSystem` rather than `System`. - Remove some usages of `.system()` with run criteria in tests of `stage.rs`, to verify the implementation.
This commit is contained in:
parent
bc3f80fb85
commit
11485decca
2 changed files with 18 additions and 16 deletions
|
@ -3,7 +3,7 @@ use crate::{
|
|||
component::ComponentId,
|
||||
query::Access,
|
||||
schedule::{BoxedRunCriteriaLabel, GraphNode, RunCriteriaLabel},
|
||||
system::{BoxedSystem, System, SystemId},
|
||||
system::{BoxedSystem, IntoSystem, System, SystemId},
|
||||
world::World,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
|
@ -197,12 +197,14 @@ impl IntoRunCriteria<BoxedSystem<(), ShouldRun>> for BoxedSystem<(), ShouldRun>
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> IntoRunCriteria<BoxedSystem<(), ShouldRun>> for S
|
||||
impl<S, Param> IntoRunCriteria<(BoxedSystem<(), ShouldRun>, Param)> for S
|
||||
where
|
||||
S: System<In = (), Out = ShouldRun>,
|
||||
S: IntoSystem<(), ShouldRun, Param>,
|
||||
{
|
||||
fn into(self) -> RunCriteriaDescriptorOrLabel {
|
||||
RunCriteriaDescriptorOrLabel::Descriptor(new_run_criteria_descriptor(Box::new(self)))
|
||||
RunCriteriaDescriptorOrLabel::Descriptor(new_run_criteria_descriptor(Box::new(
|
||||
self.system(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,7 +229,7 @@ impl IntoRunCriteria<RunCriteria> for RunCriteria {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait RunCriteriaDescriptorCoercion {
|
||||
pub trait RunCriteriaDescriptorCoercion<Param> {
|
||||
/// Assigns a label to the criteria. Must be unique.
|
||||
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor;
|
||||
|
||||
|
@ -242,7 +244,7 @@ pub trait RunCriteriaDescriptorCoercion {
|
|||
fn after(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor;
|
||||
}
|
||||
|
||||
impl RunCriteriaDescriptorCoercion for RunCriteriaDescriptor {
|
||||
impl RunCriteriaDescriptorCoercion<()> for RunCriteriaDescriptor {
|
||||
fn label(mut self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
|
||||
self.label = Some(Box::new(label));
|
||||
self.duplicate_label_strategy = DuplicateLabelStrategy::Panic;
|
||||
|
@ -276,7 +278,7 @@ fn new_run_criteria_descriptor(system: BoxedSystem<(), ShouldRun>) -> RunCriteri
|
|||
}
|
||||
}
|
||||
|
||||
impl RunCriteriaDescriptorCoercion for BoxedSystem<(), ShouldRun> {
|
||||
impl RunCriteriaDescriptorCoercion<()> for BoxedSystem<(), ShouldRun> {
|
||||
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
|
||||
new_run_criteria_descriptor(self).label(label)
|
||||
}
|
||||
|
@ -294,24 +296,24 @@ impl RunCriteriaDescriptorCoercion for BoxedSystem<(), ShouldRun> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> RunCriteriaDescriptorCoercion for S
|
||||
impl<S, Param> RunCriteriaDescriptorCoercion<Param> for S
|
||||
where
|
||||
S: System<In = (), Out = ShouldRun>,
|
||||
S: IntoSystem<(), ShouldRun, Param>,
|
||||
{
|
||||
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
|
||||
new_run_criteria_descriptor(Box::new(self)).label(label)
|
||||
new_run_criteria_descriptor(Box::new(self.system())).label(label)
|
||||
}
|
||||
|
||||
fn label_discard_if_duplicate(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
|
||||
new_run_criteria_descriptor(Box::new(self)).label_discard_if_duplicate(label)
|
||||
new_run_criteria_descriptor(Box::new(self.system())).label_discard_if_duplicate(label)
|
||||
}
|
||||
|
||||
fn before(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
|
||||
new_run_criteria_descriptor(Box::new(self)).before(label)
|
||||
new_run_criteria_descriptor(Box::new(self.system())).before(label)
|
||||
}
|
||||
|
||||
fn after(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
|
||||
new_run_criteria_descriptor(Box::new(self)).after(label)
|
||||
new_run_criteria_descriptor(Box::new(self.system())).after(label)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1170,7 +1170,7 @@ mod tests {
|
|||
.with_system(make_exclusive(0).exclusive_system().before("1"))
|
||||
.with_system_set(
|
||||
SystemSet::new()
|
||||
.with_run_criteria(every_other_time.system())
|
||||
.with_run_criteria(every_other_time)
|
||||
.with_system(make_exclusive(1).exclusive_system().label("1")),
|
||||
)
|
||||
.with_system(make_exclusive(2).exclusive_system().after("1"));
|
||||
|
@ -1392,7 +1392,7 @@ mod tests {
|
|||
make_parallel!(0)
|
||||
.system()
|
||||
.label("0")
|
||||
.with_run_criteria(every_other_time.system()),
|
||||
.with_run_criteria(every_other_time),
|
||||
)
|
||||
.with_system(make_parallel!(1).system().after("0"));
|
||||
stage.run(&mut world);
|
||||
|
@ -1427,7 +1427,7 @@ mod tests {
|
|||
// Reusing criteria.
|
||||
world.get_resource_mut::<Vec<usize>>().unwrap().clear();
|
||||
let mut stage = SystemStage::parallel()
|
||||
.with_system_run_criteria(every_other_time.system().label("every other time"))
|
||||
.with_system_run_criteria(every_other_time.label("every other time"))
|
||||
.with_system(make_parallel!(0).system().before("1"))
|
||||
.with_system(
|
||||
make_parallel!(1)
|
||||
|
|
Loading…
Reference in a new issue