diff --git a/crates/bevy_app/src/app_builder.rs b/crates/bevy_app/src/app_builder.rs index fe7b5fb3d70fd..18f12f036596a 100644 --- a/crates/bevy_app/src/app_builder.rs +++ b/crates/bevy_app/src/app_builder.rs @@ -13,6 +13,7 @@ use bevy_ecs::{ world::{FromWorld, World}, }; use bevy_utils::tracing::debug; +use std::{fmt::Debug, hash::Hash}; /// Configure [App]s using the builder pattern pub struct AppBuilder { @@ -177,16 +178,18 @@ impl AppBuilder { self } - pub fn add_state(&mut self, initial: T) -> &mut Self { + pub fn add_state(&mut self, initial: T) -> &mut Self + where + T: Component + Debug + Clone + Eq + Hash, + { self.insert_resource(State::new(initial)) .add_system_set(State::::make_driver()) } - pub fn add_state_to_stage( - &mut self, - stage: impl StageLabel, - initial: T, - ) -> &mut Self { + pub fn add_state_to_stage(&mut self, stage: impl StageLabel, initial: T) -> &mut Self + where + T: Component + Debug + Clone + Eq + Hash, + { self.insert_resource(State::new(initial)) .add_system_set_to_stage(stage, State::::make_driver()) } diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index b35d8c054711c..07108b59de432 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -433,6 +433,12 @@ pub fn derive_ambiguity_set_label(input: TokenStream) -> TokenStream { derive_label(input, Ident::new("AmbiguitySetLabel", Span::call_site())).into() } +#[proc_macro_derive(RunCriteriaLabel)] +pub fn derive_run_criteria_label(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + derive_label(input, Ident::new("RunCriteriaLabel", Span::call_site())).into() +} + fn derive_label(input: DeriveInput, label_type: Ident) -> TokenStream2 { let ident = input.ident; let ecs_path: Path = bevy_ecs_path(); diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index aa1be8d483bb5..c3061d1580e4a 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -19,6 +19,7 @@ pub mod prelude { query::{Added, ChangeTrackers, Changed, Or, QueryState, With, WithBundle, Without}, schedule::{ AmbiguitySetLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion, + RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaLabel, RunCriteriaPiping, Schedule, Stage, StageLabel, State, SystemLabel, SystemSet, SystemStage, }, system::{ diff --git a/crates/bevy_ecs/src/schedule/graph_utils.rs b/crates/bevy_ecs/src/schedule/graph_utils.rs new file mode 100644 index 0000000000000..ea5e2a2a58362 --- /dev/null +++ b/crates/bevy_ecs/src/schedule/graph_utils.rs @@ -0,0 +1,125 @@ +use bevy_utils::{tracing::warn, HashMap, HashSet}; +use fixedbitset::FixedBitSet; +use std::{borrow::Cow, fmt::Debug, hash::Hash}; + +pub enum DependencyGraphError { + GraphCycles(Vec<(usize, Labels)>), +} + +pub trait GraphNode