Skip to content

Commit

Permalink
Simplify how we're computing the distances for nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
andriyDev committed Dec 12, 2024
1 parent 29850f4 commit a90ac01
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ impl ScheduleGraph {

// calculate the number of sync points each sync point is from the beginning of the graph
// use the same sync point if the distance is the same
let mut distances: HashMap<usize, Option<u32>> =
let mut distances: HashMap<usize, u32> =
HashMap::with_capacity_and_hasher(topo.len(), Default::default());
for node in &topo {
let add_sync_after = self.systems[node.index()].get().unwrap().has_deferred();
Expand All @@ -1165,20 +1165,18 @@ impl ScheduleGraph {

let weight = if add_sync_on_edge { 1 } else { 0 };

// Use whichever distance is larger, either the current distance, or the distance to
// the parent plus the weight.
let distance = distances
.get(&target.index())
.unwrap_or(&None)
.or(Some(0))
.map(|distance| {
distance.max(
distances.get(&node.index()).unwrap_or(&None).unwrap_or(0) + weight,
)
});
.copied()
.unwrap_or_default()
.max(distances.get(&node.index()).copied().unwrap_or_default() + weight);

distances.insert(target.index(), distance);

if add_sync_on_edge {
let sync_point = self.get_sync_point(distances[&target.index()].unwrap());
let sync_point = self.get_sync_point(distances[&target.index()]);
sync_point_graph.add_edge(*node, sync_point);
sync_point_graph.add_edge(sync_point, target);

Expand Down

0 comments on commit a90ac01

Please sign in to comment.