-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
bevy_ecs::schedule_v3
module (#6587)
# Objective Complete the first part of the migration detailed in bevyengine/rfcs#45. ## Solution Add all the new stuff. ### TODO - [x] Impl tuple methods. - [x] Impl chaining. - [x] Port ambiguity detection. - [x] Write docs. - [x] ~~Write more tests.~~(will do later) - [ ] Write changelog and examples here? - [x] ~~Replace `petgraph`.~~ (will do later) Co-authored-by: james7132 <[email protected]> Co-authored-by: Michael Hsu <[email protected]> Co-authored-by: Mike Hsu <[email protected]>
- Loading branch information
1 parent
6b4795c
commit 684f075
Showing
25 changed files
with
4,050 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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`. | ||
/// | ||
/// 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, | ||
} | ||
} | ||
} |
Oops, something went wrong.