Skip to content

Commit 18745e6

Browse files
committed
Migrated Chain from using Commands to using Builder
Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
1 parent 667fb16 commit 18745e6

File tree

3 files changed

+37
-38
lines changed

3 files changed

+37
-38
lines changed

src/chain.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
8282
pub fn then<P: Provider<Request = T>>(
8383
self,
8484
provider: P,
85-
) -> Chain<'w, 's, 'a, P::Response>
85+
) -> Chain<'w, 's, 'a, 'b, P::Response>
8686
where
8787
P::Response: 'static + Send + Sync,
8888
{
8989
let source = self.target;
90-
let target = self.commands.spawn(UnusedTarget).id();
91-
provider.connect(source, target, self.commands);
92-
Chain::new(self.scope, target, self.commands)
90+
let target = self.builder.commands.spawn(UnusedTarget).id();
91+
provider.connect(source, target, self.builder.commands);
92+
Chain::new(target, self.builder)
9393
}
9494

9595
/// Connect the response in the chain into a new provider. Get the node
@@ -103,15 +103,15 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
103103
P::Streams: StreamPack,
104104
{
105105
let source = self.target;
106-
let target = self.commands.spawn(UnusedTarget).id();
107-
provider.connect(source, target, self.commands);
106+
let target = self.builder.commands.spawn(UnusedTarget).id();
107+
provider.connect(source, target, self.builder.commands);
108108
let (bundle, streams) = <P::Streams as StreamPack>::spawn_node_streams(
109-
self.scope, self.commands,
109+
self.builder.scope, self.builder.commands,
110110
);
111-
self.commands.entity(source).insert(bundle);
111+
self.builder.commands.entity(source).insert(bundle);
112112
Node {
113-
input: InputSlot::new(self.scope, source),
114-
output: Output::new(self.scope, target),
113+
input: InputSlot::new(self.builder.scope, source),
114+
output: Output::new(self.builder.scope, target),
115115
streams,
116116
}
117117
}
@@ -121,7 +121,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
121121
pub fn map<M, F: AsMap<M>>(
122122
self,
123123
f: F,
124-
) -> Chain<'w, 's, 'a, <F::MapType as ProvideOnce>::Response>
124+
) -> Chain<'w, 's, 'a, 'b, <F::MapType as ProvideOnce>::Response>
125125
where
126126
F::MapType: Provider<Request=T>,
127127
<F::MapType as ProvideOnce>::Response: 'static + Send + Sync,
@@ -152,7 +152,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
152152
pub fn map_block<U>(
153153
self,
154154
f: impl FnMut(T) -> U + 'static + Send + Sync,
155-
) -> Chain<'w, 's, 'a, U>
155+
) -> Chain<'w, 's, 'a, 'b, U>
156156
where
157157
U: 'static + Send + Sync,
158158
{
@@ -177,7 +177,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
177177
pub fn map_async<Task>(
178178
self,
179179
f: impl FnMut(T) -> Task + 'static + Send + Sync,
180-
) -> Chain<'w, 's, 'a, Task::Output>
180+
) -> Chain<'w, 's, 'a, 'b, Task::Output>
181181
where
182182
Task: Future + 'static + Send + Sync,
183183
Task::Output: 'static + Send + Sync,
@@ -208,7 +208,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
208208
pub fn cancellation_filter<ThenResponse, F>(
209209
self,
210210
filter_provider: F
211-
) -> Chain<'w, 's, 'a, ThenResponse>
211+
) -> Chain<'w, 's, 'a, 'b, ThenResponse>
212212
where
213213
ThenResponse: 'static + Send + Sync,
214214
F: Provider<Request = T, Response = Option<ThenResponse>>,
@@ -245,16 +245,16 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
245245
pub fn fork_clone(
246246
self,
247247
build: impl FnOnce(Chain<T>),
248-
) -> Chain<'w, 's, 'a, T>
248+
) -> Chain<'w, 's, 'a, 'b, T>
249249
where
250250
T: Clone,
251251
{
252-
Chain::<'w, 's, '_, T>::new(
253-
self.scope, self.target, self.commands,
254-
).fork_clone_zip((
255-
|chain: Chain<T>| chain.output(),
256-
build
257-
)).0.chain(self.commands)
252+
Chain::<T>::new(self.target, self.builder)
253+
.fork_clone_zip((
254+
|chain: Chain<T>| chain.output(),
255+
build,
256+
)).0
257+
.chain(self.builder)
258258
}
259259

260260
/// When the response is delivered, we will make clones of it and

src/chain/zipped.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use crate::{
2121
BundleJoin, AddOperation,
2222
};
2323

24-
use bevy::prelude::Commands;
25-
2624
use smallvec::SmallVec;
2725

2826
/// This trait is for [`Dangling`] [`Chains`](Chain) that are "zipped" together in a tuple. The
@@ -124,15 +122,15 @@ where
124122
Chain::new(target, builder)
125123
}
126124

127-
fn build_zip<'w, 's, 'a, Builders: ZippedBuilders<'w, 's, Self>>(
125+
fn build_zip<'w, 's, 'a, 'b, Builders: ZippedBuilders<'w, 's, Self>>(
128126
self,
129-
commands: &'a mut Commands<'w, 's>,
127+
builder: &'b mut Builder<'w, 's, 'a>,
130128
builders: Builders,
131129
) -> Builders::Output
132130
where
133131
Self: Sized
134132
{
135-
builders.apply_zipped_builders(self, commands)
133+
builders.apply_zipped_builders(self, builder)
136134
}
137135
}
138136

@@ -141,7 +139,7 @@ where
141139
/// zipped together.
142140
pub trait ZippedBuilders<'w, 's, Z> {
143141
type Output;
144-
fn apply_zipped_builders<'a, 'b>(self, zip: Z, commands: &'b mut Builder<'w, 's, 'a>) -> Self::Output;
142+
fn apply_zipped_builders<'a, 'b>(self, zip: Z, builder: &'b mut Builder<'w, 's, 'a>) -> Self::Output;
145143
}
146144

147145
impl<'w, 's, A, Fa, Ua, B, Fb, Ub> ZippedBuilders<'w, 's, (Output<A>, Output<B>)> for (Fa, Fb)
@@ -210,10 +208,10 @@ pub trait BundledChains {
210208

211209
/// Join the bundle into one [`Chain`] whose response is the combined
212210
/// responses of all the chains.
213-
fn join_bundle<'w, 's, 'a>(
211+
fn join_bundle<'w, 's, 'a, 'b>(
214212
self,
215-
commands: &'a mut Commands<'w, 's>,
216-
) -> Chain<'w, 's, 'a, JoinedBundle<Self::Response>>;
213+
builder: &'b mut Builder<'w, 's, 'a>,
214+
) -> Chain<'w, 's, 'a, 'b, JoinedBundle<Self::Response>>;
217215
}
218216

219217
impl<Response, T> BundledChains for T
@@ -222,27 +220,27 @@ where
222220
T: IntoIterator<Item=Output<Response>>,
223221
{
224222
type Response = Response;
225-
fn join_bundle<'w, 's, 'a>(
223+
fn join_bundle<'w, 's, 'a, 'b>(
226224
self,
227-
commands: &'a mut Commands<'w, 's>,
228-
) -> Chain<'w, 's, 'a, JoinedBundle<Self::Response>> {
225+
builder: &'b mut Builder<'w, 's, 'a>,
226+
) -> Chain<'w, 's, 'a, 'b, JoinedBundle<Self::Response>> {
229227
let inputs = FunnelInputStorage::from_iter(
230228
self.into_iter().map(|output| output.id())
231229
);
232-
let joiner = commands.spawn(()).id();
230+
let joiner = builder.commands.spawn(()).id();
233231
for input in &inputs.0 {
234-
commands.add(AddOperation::new(
232+
builder.commands.add(AddOperation::new(
235233
*input,
236234
JoinInput::<Response>::new(joiner),
237235
));
238236
}
239237

240-
let target = commands.spawn(UnusedTarget).id();
241-
commands.add(AddOperation::new(
238+
let target = builder.commands.spawn(UnusedTarget).id();
239+
builder.commands.add(AddOperation::new(
242240
joiner,
243241
BundleJoin::<Response>::new(inputs, target),
244242
));
245243

246-
Chain::new(joiner, target, commands)
244+
Chain::new(target, builder)
247245
}
248246
}

src/stream.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub trait StreamPack: 'static + Send + Sync {
173173
type Receiver;
174174
type Channel;
175175

176+
// TODO(@mxgrey): Consider passing in Builder instead of (scope, commands)
176177
fn spawn_scope_streams(scope: Entity, commands: &mut Commands) -> (
177178
Self::StreamStorageBundle,
178179
Self::StreamInputPack,

0 commit comments

Comments
 (0)