Skip to content
Merged
Changes from 1 commit
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
65 changes: 60 additions & 5 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
)]
use alloc::{
boxed::Box,
collections::{BTreeMap, BTreeSet},
collections::BTreeSet,
format,
string::{String, ToString},
vec,
Expand All @@ -17,6 +17,7 @@ use core::{
fmt::{Debug, Write},
};
use fixedbitset::FixedBitSet;
use indexmap::IndexMap;
use log::{info, warn};
use pass::ScheduleBuildPassObj;
use thiserror::Error;
Expand Down Expand Up @@ -465,7 +466,7 @@ impl Schedule {

/// Remove a custom build pass.
pub fn remove_build_pass<T: ScheduleBuildPass>(&mut self) {
self.graph.passes.remove(&TypeId::of::<T>());
self.graph.passes.shift_remove(&TypeId::of::<T>());
}

/// Changes miscellaneous build settings.
Expand Down Expand Up @@ -697,7 +698,7 @@ pub struct ScheduleGraph {
anonymous_sets: usize,
changed: bool,
settings: ScheduleBuildSettings,
passes: BTreeMap<TypeId, Box<dyn ScheduleBuildPassObj>>,
passes: IndexMap<TypeId, Box<dyn ScheduleBuildPassObj>>,
}

impl ScheduleGraph {
Expand Down Expand Up @@ -1580,14 +1581,17 @@ pub struct ScheduleNotInitialized;

#[cfg(test)]
mod tests {
use alloc::{vec, vec::Vec};
use core::any::TypeId;

use bevy_ecs_macros::ScheduleLabel;

use crate::{
error::{ignore, panic, DefaultErrorHandler, Result},
prelude::{ApplyDeferred, IntoSystemSet, Res, Resource},
schedule::{
tests::ResMut, IntoScheduleConfigs, Schedule, ScheduleBuildSettings,
ScheduleCleanupPolicy, SystemSet,
passes::AutoInsertApplyDeferredPass, tests::ResMut, IntoScheduleConfigs, Schedule,
ScheduleBuildPass, ScheduleBuildSettings, ScheduleCleanupPolicy, SystemSet,
},
system::Commands,
world::World,
Expand Down Expand Up @@ -2565,4 +2569,55 @@ mod tests {
let conflicts = schedule.graph().conflicting_systems();
assert!(conflicts.is_empty());
}

#[test]
fn build_pass_iteration_order() {
#[derive(Debug)]
struct Pass<const N: usize>;

impl<const N: usize> ScheduleBuildPass for Pass<N> {
type EdgeOptions = ();
fn add_dependency(
&mut self,
_from: crate::schedule::NodeId,
_to: crate::schedule::NodeId,
_options: Option<&Self::EdgeOptions>,
) {
}
fn build(
&mut self,
_world: &mut World,
_graph: &mut super::ScheduleGraph,
_dependency_flattened: &mut crate::schedule::graph::Dag<crate::schedule::SystemKey>,
) -> core::result::Result<(), crate::schedule::ScheduleBuildError> {
Ok(())
}
fn collapse_set(
&mut self,
_set: crate::schedule::SystemSetKey,
_systems: &bevy_platform::collections::HashSet<crate::schedule::SystemKey>,
_dependency_flattening: &crate::schedule::graph::DiGraph<crate::schedule::NodeId>,
) -> impl Iterator<Item = (crate::schedule::NodeId, crate::schedule::NodeId)>
{
core::iter::empty()
}
}

let mut schedule = Schedule::default();
schedule.add_build_pass(Pass::<0>);
schedule.add_build_pass(Pass::<1>);
schedule.add_build_pass(Pass::<2>);

let pass_order: Vec<TypeId> = schedule.graph().passes.keys().cloned().collect();

assert_eq!(
pass_order,
vec![
TypeId::of::<AutoInsertApplyDeferredPass>(),
TypeId::of::<Pass<0>>(),
TypeId::of::<Pass<1>>(),
TypeId::of::<Pass<2>>()
]
);
}
}
Loading