Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify system piping and make it more flexible #8377

Merged
merged 6 commits into from
Apr 17, 2023
Merged
Changes from 5 commits
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
33 changes: 12 additions & 21 deletions crates/bevy_ecs/src/system/system_piping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,24 @@ where
/// This trait is blanket implemented for all system pairs that fulfill the type requirements.
///
/// See [`PipeSystem`].
pub trait IntoPipeSystem<ParamA, Payload, SystemB, ParamB, Out>:
IntoSystem<(), Payload, ParamA> + Sized
where
SystemB: IntoSystem<Payload, Out, ParamB>,
{
pub trait IntoPipeSystem<In, Payload, Marker>: IntoSystem<In, Payload, Marker> + Sized {
/// Pass the output of this system `A` into a second system `B`, creating a new compound system.
fn pipe(self, system: SystemB) -> PipeSystem<Self::System, SystemB::System>;
}

impl<SystemA, ParamA, Payload, SystemB, ParamB, Out>
IntoPipeSystem<ParamA, Payload, SystemB, ParamB, Out> for SystemA
where
SystemA: IntoSystem<(), Payload, ParamA>,
SystemB: IntoSystem<Payload, Out, ParamB>,
{
fn pipe(self, system: SystemB) -> PipeSystem<SystemA::System, SystemB::System> {
fn pipe<B, Out, MarkerB>(self, system: B) -> PipeSystem<Self::System, B::System>
where
B: IntoSystem<Payload, Out, MarkerB>,
{
JoJoJet marked this conversation as resolved.
Show resolved Hide resolved
let system_a = IntoSystem::into_system(self);
let system_b = IntoSystem::into_system(system);
let name = format!("Pipe({}, {})", system_a.name(), system_b.name());
PipeSystem::new(system_a, system_b, Cow::Owned(name))
}
}

impl<In, Payload, Marker, Sys> IntoPipeSystem<In, Payload, Marker> for Sys where
Sys: IntoSystem<In, Payload, Marker>
{
}

/// A collection of common adapters for [piping](super::PipeSystem) the result of a system.
pub mod adapter {
use crate::system::In;
Expand Down Expand Up @@ -313,7 +308,7 @@ mod tests {
use bevy_utils::default;

use super::adapter::*;
use crate::{self as bevy_ecs, prelude::*, system::PipeSystem};
use crate::{self as bevy_ecs, prelude::*};

#[test]
fn assert_systems() {
Expand Down Expand Up @@ -384,11 +379,7 @@ mod tests {

let mut world = World::new();
world.init_resource::<Flag>();
let mut sys = PipeSystem::new(
IntoSystem::into_system(first),
IntoSystem::into_system(second),
"".into(),
);
let mut sys = first.pipe(second);
sys.initialize(&mut world);

sys.run(default(), &mut world);
Expand Down