Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Add bevy_ecs::schedule_v3 module #6587

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a686708
Add `bevy_ecs::schedule_v3` module
maniwani Nov 15, 2022
0e8c2ce
Update schedule.rs
maniwani Nov 15, 2022
7451685
ambiguous_with system type sets
maniwani Nov 16, 2022
c1f35d2
docs
maniwani Nov 19, 2022
33f7c98
move `petgraph` to utils
maniwani Nov 19, 2022
d1ed541
clean up warnings
maniwani Nov 19, 2022
7f86219
document graph alg
maniwani Nov 19, 2022
2ee5ef6
fix condition issue, flatten graph mod, get executor kind
maniwani Nov 20, 2022
0152ce9
clippy being pedantic
maniwani Nov 20, 2022
a25017e
fix `is_apply_system_buffers` not working
maniwani Nov 20, 2022
26d29a5
docs docs docs docs docs
maniwani Nov 20, 2022
1a6a061
`explicit_iter_loop` is a dumb lint CMV
maniwani Nov 20, 2022
77d35f1
simplify loop
maniwani Nov 20, 2022
385d6bf
typo
maniwani Nov 20, 2022
4ba6a1d
just leave `State<S>` in the world
maniwani Nov 20, 2022
19fd6c0
nit
maniwani Nov 20, 2022
47b3ff4
internal consistency
maniwani Nov 20, 2022
54ba8b4
don't panic
maniwani Nov 20, 2022
71d4631
cleanup
maniwani Nov 20, 2022
cc41572
default system set handling for system sets
maniwani Nov 20, 2022
0c826fb
check docs
maniwani Nov 20, 2022
20eb905
Make signalling dependents copyless
james7132 Nov 21, 2022
dc5abef
Apply suggestions from code review
maniwani Nov 21, 2022
c899e99
nits
maniwani Nov 21, 2022
730182d
add some tests
hymm Nov 21, 2022
4c2af44
move tests to mod.rs
hymm Nov 21, 2022
6541956
fmt
maniwani Nov 21, 2022
7e11b44
builder pattern for `Schedule` methods
maniwani Nov 22, 2022
6ee040a
miri
maniwani Nov 22, 2022
a0bbdae
style + ticks
maniwani Nov 23, 2022
23f2250
rename fields for clarity
maniwani Nov 23, 2022
24c1945
respond to feedback pt1
maniwani Dec 5, 2022
3af4d28
docs
maniwani Jan 14, 2023
4869bed
update to match system param API changes
maniwani Jan 14, 2023
a2ef27b
beef with clippy
maniwani Jan 14, 2023
10227fd
reorganize
maniwani Jan 14, 2023
528f9dd
respond to feedback pt2
maniwani Jan 14, 2023
789cf77
fix tests
maniwani Jan 14, 2023
910b817
replace `ScheduleGraph` hash maps with vectors
maniwani Jan 14, 2023
470cce1
make optional errors opt-in
maniwani Jan 15, 2023
3d0224d
clippy
maniwani Jan 15, 2023
b465063
Apply suggestions from code review
maniwani Jan 15, 2023
d987a08
Apply suggestions from code review
maniwani Jan 15, 2023
533e266
wording
maniwani Jan 15, 2023
c8f0a98
*mildly* cursed code
maniwani Jan 15, 2023
3e10dc0
avoid counting bits in bitset
maniwani Jan 15, 2023
ca4e643
style
maniwani Jan 15, 2023
e357e30
Apply suggestions from review
maniwani Jan 15, 2023
66263c7
rename `Statelike` to `States` and remove blanket impl
maniwani Jan 15, 2023
1441bcd
all_tuples
maniwani Jan 15, 2023
8d65fac
remove TODO
maniwani Jan 15, 2023
7c0a1da
comment
maniwani Jan 15, 2023
4dc4139
Apply suggestions from code review
maniwani Jan 15, 2023
d851616
simplify trait bound
maniwani Jan 15, 2023
fbc2438
james said `difference` isn't optimized
maniwani Jan 15, 2023
7a15581
add `ambiguous_with` for tuples
maniwani Jan 15, 2023
2020bd4
Apply suggestions from review
maniwani Jan 15, 2023
6a70eef
safety
maniwani Jan 15, 2023
1f86f21
clippy, my archenemy
maniwani Jan 16, 2023
cad97b2
style
maniwani Jan 16, 2023
1ca012b
fix type signature
maniwani Jan 16, 2023
c10c467
take without option
maniwani Jan 16, 2023
c253885
Update crates/bevy_ecs/src/schedule_v3/executor/multi_threaded.rs
cart Jan 16, 2023
9a62c72
pass the CI vibecheck
maniwani Jan 17, 2023
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
30 changes: 29 additions & 1 deletion crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ mod component;
mod fetch;

use crate::fetch::derive_world_query_impl;
use bevy_macro_utils::{derive_label, get_named_struct_fields, BevyManifest};
use bevy_macro_utils::{
derive_boxed_label, derive_label, derive_set, get_named_struct_fields, BevyManifest,
};
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::{format_ident, quote};
Expand Down Expand Up @@ -565,6 +567,32 @@ pub fn derive_run_criteria_label(input: TokenStream) -> TokenStream {
derive_label(input, &trait_path, "run_criteria_label")
}

/// Derive macro generating an impl of the trait `ScheduleLabel`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to doc link these traits?

#[proc_macro_derive(ScheduleLabel)]
pub fn derive_schedule_label(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let mut trait_path = bevy_ecs_path();
trait_path
.segments
.push(format_ident!("schedule_v3").into());
trait_path
.segments
.push(format_ident!("ScheduleLabel").into());
derive_boxed_label(input, &trait_path)
}

/// Derive macro generating an impl of the trait `SystemSet`.
#[proc_macro_derive(SystemSet)]
pub fn derive_system_set(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let mut trait_path = bevy_ecs_path();
trait_path
.segments
.push(format_ident!("schedule_v3").into());
trait_path.segments.push(format_ident!("SystemSet").into());
derive_set(input, &trait_path)
}

pub(crate) fn bevy_ecs_path() -> syn::Path {
BevyManifest::default().get_path("bevy_ecs")
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod query;
#[cfg(feature = "bevy_reflect")]
pub mod reflect;
pub mod schedule;
pub mod schedule_v3;
pub mod storage;
pub mod system;
pub mod world;
Expand Down
97 changes: 97 additions & 0 deletions crates/bevy_ecs/src/schedule_v3/condition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
pub use common_conditions::*;

use crate::system::BoxedSystem;

pub type BoxedCondition = BoxedSystem<(), bool>;

/// A system that determines if one or more scheduled systems should run.
///
/// Implemented for functions and closures that convert into [`System<In=(), Out=bool>`](crate::system::System)
/// with [read-only](crate::system::ReadOnlySystemParam) parameters.
pub trait Condition<Params>: sealed::Condition<Params> {}

impl<Params, F> Condition<Params> for F where F: sealed::Condition<Params> {}

mod sealed {
use crate::system::{IntoSystem, IsFunctionSystem, ReadOnlySystemParam, SystemParamFunction};

pub trait Condition<Params>: IntoSystem<(), bool, Params> {}

impl<Params, Marker, F> Condition<(IsFunctionSystem, Params, Marker)> for F
where
F: SystemParamFunction<(), bool, Params, Marker> + Send + Sync + 'static,
Params: ReadOnlySystemParam + 'static,
Marker: 'static,
{
}
}

mod common_conditions {
use crate::schedule_v3::{State, States};
use crate::system::{Res, Resource};

/// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true`
/// if the resource exists.
pub fn resource_exists<T>() -> impl FnMut(Option<Res<T>>) -> bool
maniwani marked this conversation as resolved.
Show resolved Hide resolved
where
T: Resource,
{
move |res: Option<Res<T>>| res.is_some()
}

/// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true`
/// if the resource is equal to `value`.
///
/// # Panics
///
/// The condition will panic if the resource does not exist.
pub fn resource_equals<T>(value: T) -> impl FnMut(Res<T>) -> bool
where
T: Resource + PartialEq,
{
move |res: Res<T>| *res == value
}

/// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true`
/// if the resource exists and is equal to `value`.
///
/// The condition will return `false` if the resource does not exist.
pub fn resource_exists_and_equals<T>(value: T) -> impl FnMut(Option<Res<T>>) -> bool
where
T: Resource + PartialEq,
{
move |res: Option<Res<T>>| match res {
Some(res) => *res == value,
None => false,
}
}

/// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true`
/// if the state machine exists.
pub fn state_exists<S: States>() -> impl FnMut(Option<Res<State<S>>>) -> bool {
move |current_state: Option<Res<State<S>>>| current_state.is_some()
}

/// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true`
/// if the state machine is currently in `state`.
///
/// # Panics
///
/// The condition will panic if the resource does not exist.
pub fn state_equals<S: States>(state: S) -> impl FnMut(Res<State<S>>) -> bool {
move |current_state: Res<State<S>>| current_state.0 == state
}

/// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true`
/// if the state machine exists and is currently in `state`.
maniwani marked this conversation as resolved.
Show resolved Hide resolved
///
/// The condition will return `false` if the state does not exist.
pub fn state_exists_and_equals<S: States>(
state: S,
) -> impl FnMut(Option<Res<State<S>>>) -> bool {
move |current_state: Option<Res<State<S>>>| match current_state {
Some(current_state) => current_state.0 == state,
None => false,
}
}
}
Loading