Path: blob/main/crates/bevy_ecs/src/schedule/graph/mod.rs
9354 views
use alloc::{boxed::Box, vec::Vec};1use core::{2any::{Any, TypeId},3fmt::Debug,4};56use bevy_utils::TypeIdMap;78use crate::schedule::InternedSystemSet;910mod dag;11mod graph_map;12mod tarjan_scc;1314pub use dag::*;15pub use graph_map::{DiGraph, DiGraphToposortError, Direction, GraphNodeId, UnGraph};1617/// Specifies what kind of edge should be added to the dependency graph.18#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]19pub(crate) enum DependencyKind {20/// A node that should be preceded.21Before,22/// A node that should be succeeded.23After,24}2526/// An edge to be added to the dependency graph.27pub(crate) struct Dependency {28pub(crate) kind: DependencyKind,29pub(crate) set: InternedSystemSet,30pub(crate) options: TypeIdMap<Box<dyn Any>>,31}3233impl Dependency {34pub fn new(kind: DependencyKind, set: InternedSystemSet) -> Self {35Self {36kind,37set,38options: Default::default(),39}40}41pub fn add_config<T: 'static>(mut self, option: T) -> Self {42self.options.insert(TypeId::of::<T>(), Box::new(option));43self44}45}4647/// Configures ambiguity detection for a single system.48#[derive(Clone, Debug, Default)]49pub(crate) enum Ambiguity {50#[default]51Check,52/// Ignore warnings with systems in any of these system sets. May contain duplicates.53IgnoreWithSet(Vec<InternedSystemSet>),54/// Ignore all warnings.55IgnoreAll,56}5758/// Metadata about how the node fits in the schedule graph59#[derive(Default)]60pub struct GraphInfo {61/// the sets that the node belongs to (hierarchy)62pub(crate) hierarchy: Vec<InternedSystemSet>,63/// the sets that the node depends on (must run before or after)64pub(crate) dependencies: Vec<Dependency>,65pub(crate) ambiguous_with: Ambiguity,66}6768/// Converts 2D row-major pair of indices into a 1D array index.69pub(crate) fn index(row: usize, col: usize, num_cols: usize) -> usize {70debug_assert!(col < num_cols);71(row * num_cols) + col72}7374/// Converts a 1D array index into a 2D row-major pair of indices.75pub(crate) fn row_col(index: usize, num_cols: usize) -> (usize, usize) {76(index / num_cols, index % num_cols)77}787980