Skip to content

Commit 5d9ca62

Browse files
committed
added cursed tuple systems
1 parent 7641ceb commit 5d9ca62

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

crates/bevy_ecs/src/system/combinator.rs

+78
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,84 @@ impl<Func, A, B> CombinatorSystem<Func, A, B> {
125125
}
126126
}
127127

128+
impl<In, A, B> System for (A, B)
129+
where
130+
In: Copy,
131+
A: System<In = In>,
132+
B: System<In = In>,
133+
{
134+
type In = In;
135+
type Out = (A::Out, B::Out);
136+
137+
fn name(&self) -> Cow<'static, str> {
138+
Cow::Owned(format!("Join({}, {})", self.0.name().clone(), self.1.name().clone()))
139+
}
140+
141+
fn type_id(&self) -> std::any::TypeId {
142+
std::any::TypeId::of::<Self>()
143+
}
144+
145+
fn component_access(&self) -> &Access<ComponentId> {
146+
self.0.component_access() // needs to add component access of .1
147+
}
148+
149+
fn archetype_component_access(&self) -> &Access<ArchetypeComponentId> {
150+
self.0.archetype_component_access() // idem
151+
}
152+
153+
fn is_send(&self) -> bool {
154+
self.0.is_send() && self.1.is_send()
155+
}
156+
157+
fn is_exclusive(&self) -> bool {
158+
self.0.is_exclusive() || self.1.is_exclusive()
159+
}
160+
161+
unsafe fn run_unsafe(&mut self, input: Self::In, world: UnsafeWorldCell) -> Self::Out {
162+
(self.0.run_unsafe(input, world), self.1.run_unsafe(input, world))
163+
}
164+
165+
fn run<'w>(&mut self, input: Self::In, world: &'w mut World) -> Self::Out {
166+
let world: &'w UnsafeCell<World> = unsafe { std::mem::transmute(world) };
167+
(self.0.run(input, unsafe { world.deref_mut() }), self.1.run(input, unsafe { world.deref_mut() }))
168+
}
169+
170+
fn apply_buffers(&mut self, world: &mut World) {
171+
self.0.apply_buffers(world);
172+
self.1.apply_buffers(world);
173+
}
174+
175+
fn initialize(&mut self, world: &mut World) {
176+
self.0.initialize(world);
177+
self.1.initialize(world);
178+
}
179+
180+
fn update_archetype_component_access(&mut self, world: UnsafeWorldCell) {
181+
self.0.update_archetype_component_access(world);
182+
self.1.update_archetype_component_access(world);
183+
}
184+
185+
fn check_change_tick(&mut self, change_tick: Tick) {
186+
self.0.check_change_tick(change_tick);
187+
self.1.check_change_tick(change_tick);
188+
}
189+
190+
fn get_last_run(&self) -> Tick {
191+
self.0.get_last_run()
192+
}
193+
194+
fn set_last_run(&mut self, last_run: Tick) {
195+
self.0.set_last_run(last_run);
196+
self.1.set_last_run(last_run);
197+
}
198+
199+
fn default_system_sets(&self) -> Vec<Box<dyn crate::schedule::SystemSet>> {
200+
let mut default_sets = self.0.default_system_sets();
201+
default_sets.append(&mut self.1.default_system_sets());
202+
default_sets
203+
}
204+
}
205+
128206
impl<A, B, Func> System for CombinatorSystem<Func, A, B>
129207
where
130208
Func: Combine<A, B> + 'static,

examples/ecs/system_piping.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ fn main() {
2424
warning_pipe_system.pipe(warn),
2525
parse_error_message_system.pipe(error),
2626
parse_message_system.pipe(ignore),
27-
calc1.join(calc2).pipe(read),
2827
calc1.join(calc2).join(calc3).pipe(readnew),
28+
(IntoSystem::into_system(calc1), IntoSystem::into_system(calc2)).pipe(read)
2929
),
3030
)
3131
.run();

0 commit comments

Comments
 (0)