Skip to content

Commit 11485de

Browse files
committed
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.
1 parent bc3f80f commit 11485de

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

crates/bevy_ecs/src/schedule/run_criteria.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
component::ComponentId,
44
query::Access,
55
schedule::{BoxedRunCriteriaLabel, GraphNode, RunCriteriaLabel},
6-
system::{BoxedSystem, System, SystemId},
6+
system::{BoxedSystem, IntoSystem, System, SystemId},
77
world::World,
88
};
99
use std::borrow::Cow;
@@ -197,12 +197,14 @@ impl IntoRunCriteria<BoxedSystem<(), ShouldRun>> for BoxedSystem<(), ShouldRun>
197197
}
198198
}
199199

200-
impl<S> IntoRunCriteria<BoxedSystem<(), ShouldRun>> for S
200+
impl<S, Param> IntoRunCriteria<(BoxedSystem<(), ShouldRun>, Param)> for S
201201
where
202-
S: System<In = (), Out = ShouldRun>,
202+
S: IntoSystem<(), ShouldRun, Param>,
203203
{
204204
fn into(self) -> RunCriteriaDescriptorOrLabel {
205-
RunCriteriaDescriptorOrLabel::Descriptor(new_run_criteria_descriptor(Box::new(self)))
205+
RunCriteriaDescriptorOrLabel::Descriptor(new_run_criteria_descriptor(Box::new(
206+
self.system(),
207+
)))
206208
}
207209
}
208210

@@ -227,7 +229,7 @@ impl IntoRunCriteria<RunCriteria> for RunCriteria {
227229
}
228230
}
229231

230-
pub trait RunCriteriaDescriptorCoercion {
232+
pub trait RunCriteriaDescriptorCoercion<Param> {
231233
/// Assigns a label to the criteria. Must be unique.
232234
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor;
233235

@@ -242,7 +244,7 @@ pub trait RunCriteriaDescriptorCoercion {
242244
fn after(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor;
243245
}
244246

245-
impl RunCriteriaDescriptorCoercion for RunCriteriaDescriptor {
247+
impl RunCriteriaDescriptorCoercion<()> for RunCriteriaDescriptor {
246248
fn label(mut self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
247249
self.label = Some(Box::new(label));
248250
self.duplicate_label_strategy = DuplicateLabelStrategy::Panic;
@@ -276,7 +278,7 @@ fn new_run_criteria_descriptor(system: BoxedSystem<(), ShouldRun>) -> RunCriteri
276278
}
277279
}
278280

279-
impl RunCriteriaDescriptorCoercion for BoxedSystem<(), ShouldRun> {
281+
impl RunCriteriaDescriptorCoercion<()> for BoxedSystem<(), ShouldRun> {
280282
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
281283
new_run_criteria_descriptor(self).label(label)
282284
}
@@ -294,24 +296,24 @@ impl RunCriteriaDescriptorCoercion for BoxedSystem<(), ShouldRun> {
294296
}
295297
}
296298

297-
impl<S> RunCriteriaDescriptorCoercion for S
299+
impl<S, Param> RunCriteriaDescriptorCoercion<Param> for S
298300
where
299-
S: System<In = (), Out = ShouldRun>,
301+
S: IntoSystem<(), ShouldRun, Param>,
300302
{
301303
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
302-
new_run_criteria_descriptor(Box::new(self)).label(label)
304+
new_run_criteria_descriptor(Box::new(self.system())).label(label)
303305
}
304306

305307
fn label_discard_if_duplicate(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
306-
new_run_criteria_descriptor(Box::new(self)).label_discard_if_duplicate(label)
308+
new_run_criteria_descriptor(Box::new(self.system())).label_discard_if_duplicate(label)
307309
}
308310

309311
fn before(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
310-
new_run_criteria_descriptor(Box::new(self)).before(label)
312+
new_run_criteria_descriptor(Box::new(self.system())).before(label)
311313
}
312314

313315
fn after(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
314-
new_run_criteria_descriptor(Box::new(self)).after(label)
316+
new_run_criteria_descriptor(Box::new(self.system())).after(label)
315317
}
316318
}
317319

crates/bevy_ecs/src/schedule/stage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ mod tests {
11701170
.with_system(make_exclusive(0).exclusive_system().before("1"))
11711171
.with_system_set(
11721172
SystemSet::new()
1173-
.with_run_criteria(every_other_time.system())
1173+
.with_run_criteria(every_other_time)
11741174
.with_system(make_exclusive(1).exclusive_system().label("1")),
11751175
)
11761176
.with_system(make_exclusive(2).exclusive_system().after("1"));
@@ -1392,7 +1392,7 @@ mod tests {
13921392
make_parallel!(0)
13931393
.system()
13941394
.label("0")
1395-
.with_run_criteria(every_other_time.system()),
1395+
.with_run_criteria(every_other_time),
13961396
)
13971397
.with_system(make_parallel!(1).system().after("0"));
13981398
stage.run(&mut world);
@@ -1427,7 +1427,7 @@ mod tests {
14271427
// Reusing criteria.
14281428
world.get_resource_mut::<Vec<usize>>().unwrap().clear();
14291429
let mut stage = SystemStage::parallel()
1430-
.with_system_run_criteria(every_other_time.system().label("every other time"))
1430+
.with_system_run_criteria(every_other_time.label("every other time"))
14311431
.with_system(make_parallel!(0).system().before("1"))
14321432
.with_system(
14331433
make_parallel!(1)

0 commit comments

Comments
 (0)