Skip to content

Commit 7754cda

Browse files
committed
tuple methods and chaining
1 parent 3c1cdbf commit 7754cda

File tree

4 files changed

+155
-120
lines changed

4 files changed

+155
-120
lines changed

crates/bevy_ecs/src/schedule_v3/config.rs

+54-48
Original file line numberDiff line numberDiff line change
@@ -340,50 +340,51 @@ mod sealed {
340340
}
341341

342342
/// A collection of [`SystemConfig`].
343-
pub struct SystemCollection {
344-
inner: Vec<SystemConfig>,
343+
pub struct SystemConfigs {
344+
pub(super) systems: Vec<SystemConfig>,
345+
pub(super) chained: bool,
345346
}
346347

347-
/// Methods that can configure multiple systems at once.
348-
pub trait IntoSystemCollection<Params>
348+
/// Types that can convert into a [`SystemConfigs`].
349+
pub trait IntoSystemConfigs<Params>
349350
where
350351
Self: Sized,
351352
{
352-
/// Convert into a [`SystemCollection`].
353+
/// Convert into a [`SystemConfigs`].
353354
#[doc(hidden)]
354-
fn into_collection(self) -> SystemCollection;
355+
fn into_configs(self) -> SystemConfigs;
355356

356357
/// Add to `set` membership.
357-
fn in_set(self, set: impl SystemSet) -> SystemCollection {
358-
self.into_collection().in_set(set)
358+
fn in_set(self, set: impl SystemSet) -> SystemConfigs {
359+
self.into_configs().in_set(set)
359360
}
360361

361362
/// Run before all members of `set`.
362-
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemCollection {
363-
self.into_collection().before(set)
363+
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs {
364+
self.into_configs().before(set)
364365
}
365366

366367
/// Run after all members of `set`.
367-
fn after<M>(self, set: impl IntoSystemSet<M>) -> SystemCollection {
368-
self.into_collection().after(set)
368+
fn after<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs {
369+
self.into_configs().after(set)
369370
}
370371

371372
/// Treat this collection as a sequence.
372373
///
373374
/// Ordering constraints will be applied between the successive collection elements.
374-
fn chain(self) -> SystemCollection {
375-
self.into_collection().chain()
375+
fn chain(self) -> SystemConfigs {
376+
self.into_configs().chain()
376377
}
377378
}
378379

379-
impl IntoSystemCollection<()> for SystemCollection {
380-
fn into_collection(self) -> Self {
380+
impl IntoSystemConfigs<()> for SystemConfigs {
381+
fn into_configs(self) -> Self {
381382
self
382383
}
383384

384385
fn in_set(mut self, set: impl SystemSet) -> Self {
385386
assert!(!set.is_system_type(), "invalid use of system type set");
386-
for config in self.inner.iter_mut() {
387+
for config in self.systems.iter_mut() {
387388
config.graph_info.sets.insert(set.dyn_clone());
388389
}
389390

@@ -392,7 +393,7 @@ impl IntoSystemCollection<()> for SystemCollection {
392393

393394
fn before<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
394395
let set = set.into_system_set();
395-
for config in self.inner.iter_mut() {
396+
for config in self.systems.iter_mut() {
396397
config
397398
.graph_info
398399
.edges
@@ -404,7 +405,7 @@ impl IntoSystemCollection<()> for SystemCollection {
404405

405406
fn after<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
406407
let set = set.into_system_set();
407-
for config in self.inner.iter_mut() {
408+
for config in self.systems.iter_mut() {
408409
config
409410
.graph_info
410411
.edges
@@ -415,55 +416,57 @@ impl IntoSystemCollection<()> for SystemCollection {
415416
}
416417

417418
fn chain(mut self) -> Self {
418-
todo!()
419+
self.chained = true;
420+
self
419421
}
420422
}
421423

422424
/// A collection of [`SystemSetConfig`].
423-
pub struct SystemSetCollection {
424-
inner: Vec<SystemSetConfig>,
425+
pub struct SystemSetConfigs {
426+
pub(super) sets: Vec<SystemSetConfig>,
427+
pub(super) chained: bool,
425428
}
426429

427-
/// Methods that can configure multiple system sets at once.
428-
pub trait IntoSystemSetCollection
430+
/// Types that can convert into a [`SystemSetConfigs`].
431+
pub trait IntoSystemSetConfigs
429432
where
430433
Self: Sized,
431434
{
432-
/// Convert into a [`SystemSetCollection`].
435+
/// Convert into a [`SystemSetConfigs`].
433436
#[doc(hidden)]
434-
fn into_collection(self) -> SystemSetCollection;
437+
fn into_configs(self) -> SystemSetConfigs;
435438

436439
/// Add to `set` membership.
437-
fn in_set(self, set: impl SystemSet) -> SystemSetCollection {
438-
self.into_collection().in_set(set)
440+
fn in_set(self, set: impl SystemSet) -> SystemSetConfigs {
441+
self.into_configs().in_set(set)
439442
}
440443

441444
/// Run before all members of `set`.
442-
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemSetCollection {
443-
self.into_collection().before(set)
445+
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfigs {
446+
self.into_configs().before(set)
444447
}
445448

446449
/// Run after all members of `set`.
447-
fn after<M>(self, set: impl IntoSystemSet<M>) -> SystemSetCollection {
448-
self.into_collection().after(set)
450+
fn after<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfigs {
451+
self.into_configs().after(set)
449452
}
450453

451454
/// Treat this collection as a sequence.
452455
///
453456
/// Ordering constraints will be applied between the successive collection elements.
454-
fn chain(self) -> SystemSetCollection {
455-
self.into_collection().chain()
457+
fn chain(self) -> SystemSetConfigs {
458+
self.into_configs().chain()
456459
}
457460
}
458461

459-
impl IntoSystemSetCollection for SystemSetCollection {
460-
fn into_collection(self) -> Self {
462+
impl IntoSystemSetConfigs for SystemSetConfigs {
463+
fn into_configs(self) -> Self {
461464
self
462465
}
463466

464467
fn in_set(mut self, set: impl SystemSet) -> Self {
465468
assert!(!set.is_system_type(), "invalid use of system type set");
466-
for config in self.inner.iter_mut() {
469+
for config in self.sets.iter_mut() {
467470
config.graph_info.sets.insert(set.dyn_clone());
468471
}
469472

@@ -472,7 +475,7 @@ impl IntoSystemSetCollection for SystemSetCollection {
472475

473476
fn before<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
474477
let set = set.into_system_set();
475-
for config in self.inner.iter_mut() {
478+
for config in self.sets.iter_mut() {
476479
config
477480
.graph_info
478481
.edges
@@ -484,7 +487,7 @@ impl IntoSystemSetCollection for SystemSetCollection {
484487

485488
fn after<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
486489
let set = set.into_system_set();
487-
for config in self.inner.iter_mut() {
490+
for config in self.sets.iter_mut() {
488491
config
489492
.graph_info
490493
.edges
@@ -495,21 +498,23 @@ impl IntoSystemSetCollection for SystemSetCollection {
495498
}
496499

497500
fn chain(mut self) -> Self {
498-
todo!()
501+
self.chained = true;
502+
self
499503
}
500504
}
501505

502506
macro_rules! impl_system_collection {
503507
($($param: ident, $sys: ident),*) => {
504-
impl<$($param, $sys),*> IntoSystemCollection<($($param),*)> for ($($sys),*)
508+
impl<$($param, $sys),*> IntoSystemConfigs<($($param),*)> for ($($sys),*)
505509
where
506510
$($sys: IntoSystemConfig<$param>),*
507511
{
508512
#[allow(non_snake_case)]
509-
fn into_collection(self) -> SystemCollection {
513+
fn into_configs(self) -> SystemConfigs {
510514
let ($($sys,)*) = self;
511-
SystemCollection {
512-
inner: vec![$($sys.into_config(),)*],
515+
SystemConfigs {
516+
systems: vec![$($sys.into_config(),)*],
517+
chained: false,
513518
}
514519
}
515520
}
@@ -518,13 +523,14 @@ macro_rules! impl_system_collection {
518523

519524
macro_rules! impl_system_set_collection {
520525
($($set: ident),*) => {
521-
impl<$($set: IntoSystemSetConfig),*> IntoSystemSetCollection for ($($set),*)
526+
impl<$($set: IntoSystemSetConfig),*> IntoSystemSetConfigs for ($($set),*)
522527
{
523528
#[allow(non_snake_case)]
524-
fn into_collection(self) -> SystemSetCollection {
529+
fn into_configs(self) -> SystemSetConfigs {
525530
let ($($set,)*) = self;
526-
SystemSetCollection {
527-
inner: vec![$($set.into_config(),)*],
531+
SystemSetConfigs {
532+
sets: vec![$($set.into_config(),)*],
533+
chained: false,
528534
}
529535
}
530536
}

crates/bevy_ecs/src/schedule_v3/executor/mod.rs

-11
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,3 @@ pub(super) fn is_apply_system_buffers(system: &BoxedSystem) -> bool {
8383
let type_id = get_type_id(&IntoSystem::into_system(apply_system_buffers));
8484
(&*system as &dyn Any).type_id() == type_id
8585
}
86-
87-
#[cfg(test)]
88-
mod tests {
89-
90-
#[test]
91-
fn executor_parity() {
92-
// In the absence of ambiguities, the single-threaded and
93-
// multi-threaded executors must return the same results.
94-
todo!();
95-
}
96-
}

crates/bevy_ecs/src/schedule_v3/executor/multi_threaded.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl SystemExecutor for MultiThreadedExecutor {
125125
self.spawn_system_tasks(scope, schedule, world);
126126
}
127127

128-
if self.running_systems.count_ones(..) != 0 {
128+
if self.running_systems.count_ones(..) > 0 {
129129
// wait for systems to complete
130130
let index = self
131131
.receiver
@@ -271,7 +271,7 @@ impl MultiThreadedExecutor {
271271
.extend(&system_meta.archetype_component_access);
272272

273273
self.ready_systems.set(system_index, false);
274-
self.running_systems.set(system_index, true);
274+
self.running_systems.insert(system_index);
275275

276276
if system_meta.is_send {
277277
scope.spawn(task);
@@ -411,7 +411,7 @@ impl MultiThreadedExecutor {
411411
unsafe { condition.run_unsafe((), world) }
412412
});
413413

414-
self.completed_sets.set(set_idx, true);
414+
self.completed_sets.insert(set_idx);
415415

416416
if !set_conditions_met {
417417
// mark all members as completed
@@ -470,14 +470,14 @@ impl MultiThreadedExecutor {
470470
}
471471

472472
self.running_systems.set(system_index, false);
473-
self.completed_systems.set(system_index, true);
474-
self.unapplied_systems.set(system_index, true);
473+
self.completed_systems.insert(system_index);
474+
self.unapplied_systems.insert(system_index);
475475
self.signal_dependents(system_index);
476476
}
477477

478478
fn skip_system_and_signal_dependents(&mut self, system_index: usize) {
479479
self.ready_systems.set(system_index, false);
480-
self.completed_systems.set(system_index, true);
480+
self.completed_systems.insert(system_index);
481481
self.signal_dependents(system_index);
482482
}
483483

@@ -493,7 +493,7 @@ impl MultiThreadedExecutor {
493493
if (dependent_meta.dependencies_remaining == 0)
494494
&& !self.completed_systems.contains(dep_idx)
495495
{
496-
self.ready_systems.set(dep_idx, true);
496+
self.ready_systems.insert(dep_idx);
497497
}
498498
}
499499

0 commit comments

Comments
 (0)