Skip to content

Commit ba346a6

Browse files
committed
add_node_edges
1 parent 214dbd8 commit ba346a6

File tree

4 files changed

+18
-31
lines changed

4 files changed

+18
-31
lines changed

crates/bevy_core_pipeline/src/core_2d/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,14 @@ impl Plugin for Core2dPlugin {
9292
graph::node::UPSCALING,
9393
UpscalingNode::IN_VIEW,
9494
);
95-
draw_2d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
96-
draw_2d_graph.add_node_edge(
95+
96+
draw_2d_graph.add_node_edges(&[
97+
graph::node::MAIN_PASS,
9798
graph::node::TONEMAPPING,
9899
graph::node::END_MAIN_PASS_POST_PROCESSING,
99-
);
100-
draw_2d_graph.add_node_edge(
101-
graph::node::END_MAIN_PASS_POST_PROCESSING,
102100
graph::node::UPSCALING,
103-
);
101+
]);
102+
104103
graph.add_sub_graph(graph::NAME, draw_2d_graph);
105104
}
106105
}

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,15 @@ impl Plugin for Core3dPlugin {
119119
graph::node::UPSCALING,
120120
UpscalingNode::IN_VIEW,
121121
);
122-
draw_3d_graph.add_node_edge(graph::node::PREPASS, graph::node::MAIN_PASS);
123-
draw_3d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
124-
draw_3d_graph.add_node_edge(
122+
123+
draw_3d_graph.add_node_edges(&[
124+
graph::node::PREPASS,
125+
graph::node::MAIN_PASS,
125126
graph::node::TONEMAPPING,
126127
graph::node::END_MAIN_PASS_POST_PROCESSING,
127-
);
128-
draw_3d_graph.add_node_edge(
129-
graph::node::END_MAIN_PASS_POST_PROCESSING,
130128
graph::node::UPSCALING,
131-
);
129+
]);
130+
132131
graph.add_sub_graph(graph::NAME, draw_3d_graph);
133132
}
134133
}

crates/bevy_core_pipeline/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ pub fn add_node<T: Node + FromWorld>(
8686
let mut render_graph = render_app.world.resource_mut::<RenderGraph>();
8787

8888
let graph = render_graph.get_sub_graph_mut(sub_graph_name).unwrap();
89-
graph.add_node_with_edges(node_name, node, edges);
89+
graph.add_node(node_name, node);
90+
graph.add_node_edges(edges);
9091

9192
graph.add_slot_edge(graph.input_node().id, output_slot, node_name, input_slot);
9293
}

crates/bevy_render/src/render_graph/graph.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,12 @@ impl RenderGraph {
119119
id
120120
}
121121

122-
/// Adds the `node` with the `name` to the graph.
123-
/// If the name is already present replaces it instead.
124-
/// Also adds `node_edge` based on the order of the given `edges`.
125-
pub fn add_node_with_edges<T>(
126-
&mut self,
127-
name: impl Into<Cow<'static, str>>,
128-
node: T,
129-
edges: &[&'static str],
130-
) -> NodeId
131-
where
132-
T: Node,
133-
{
134-
let id = self.add_node(name, node);
122+
/// Add `node_edge` based on the order of the given `edges` array.
123+
pub fn add_node_edges(&mut self, edges: &[&'static str]) {
135124
for window in edges.windows(2) {
136125
let [a, b] = window else { break; };
137126
self.add_node_edge(*a, *b);
138127
}
139-
id
140128
}
141129

142130
/// Removes the `node` with the `name` from the graph.
@@ -855,7 +843,7 @@ mod tests {
855843
}
856844

857845
#[test]
858-
fn test_add_node_with_edges() {
846+
fn test_add_node_edges() {
859847
struct SimpleNode;
860848
impl Node for SimpleNode {
861849
fn run(
@@ -875,10 +863,10 @@ mod tests {
875863

876864
let mut graph = RenderGraph::default();
877865
let a_id = graph.add_node("A", SimpleNode);
866+
let b_id = graph.add_node("B", SimpleNode);
878867
let c_id = graph.add_node("C", SimpleNode);
879868

880-
// A and C need to exist first
881-
let b_id = graph.add_node_with_edges("B", SimpleNode, &["A", "B", "C"]);
869+
graph.add_node_edges(&["A", "B", "C"]);
882870

883871
assert!(
884872
output_nodes("A", &graph) == HashSet::from_iter(vec![b_id]),

0 commit comments

Comments
 (0)