mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 06:30:19 +00:00
impl ReadOnlyFetch for Or, FetchOr, and FetchMutated (#763)
This commit is contained in:
parent
5cd67f7867
commit
f81208adaa
2 changed files with 41 additions and 0 deletions
|
@ -263,6 +263,9 @@ macro_rules! impl_or_query {
|
|||
true $( && $T.should_skip(n) )+
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<$( $T: ReadOnlyFetch ),+> ReadOnlyFetch for Or<($( $T ),+)> {}
|
||||
unsafe impl<$( $T: ReadOnlyFetch ),+> ReadOnlyFetch for FetchOr<($( $T ),+)> {}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -320,6 +323,7 @@ impl<'a, T: Component> Query for Mutated<'a, T> {
|
|||
|
||||
#[doc(hidden)]
|
||||
pub struct FetchMutated<T>(NonNull<T>, NonNull<bool>);
|
||||
unsafe impl<T> ReadOnlyFetch for FetchMutated<T> {}
|
||||
|
||||
impl<'a, T: Component> Fetch<'a> for FetchMutated<T> {
|
||||
type Item = Mutated<'a, T>;
|
||||
|
|
|
@ -489,6 +489,43 @@ mod tests {
|
|||
assert!(*resources.get::<bool>().unwrap(), "system ran");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn or_query_set_system() {
|
||||
// Regression test for issue #762
|
||||
use crate::{Added, Changed, Mutated, Or};
|
||||
fn query_system(
|
||||
mut ran: ResMut<bool>,
|
||||
set: QuerySet<(
|
||||
Query<Or<(Changed<A>, Changed<B>)>>,
|
||||
Query<Or<(Added<A>, Added<B>)>>,
|
||||
Query<Or<(Mutated<A>, Mutated<B>)>>,
|
||||
)>,
|
||||
) {
|
||||
let changed = set.q0().iter().count();
|
||||
let added = set.q1().iter().count();
|
||||
let mutated = set.q2().iter().count();
|
||||
|
||||
assert_eq!(changed, 1);
|
||||
assert_eq!(added, 1);
|
||||
assert_eq!(mutated, 0);
|
||||
|
||||
*ran = true;
|
||||
}
|
||||
|
||||
let mut world = World::default();
|
||||
let mut resources = Resources::default();
|
||||
resources.insert(false);
|
||||
world.spawn((A, B));
|
||||
|
||||
let mut schedule = Schedule::default();
|
||||
schedule.add_stage("update");
|
||||
schedule.add_system_to_stage("update", query_system.system());
|
||||
|
||||
schedule.run(&mut world, &mut resources);
|
||||
|
||||
assert!(*resources.get::<bool>().unwrap(), "system ran");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn changed_resource_system() {
|
||||
fn incr_e_on_flip(_run_on_flip: ChangedRes<bool>, mut i: Mut<i32>) {
|
||||
|
|
Loading…
Reference in a new issue