mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
Fix Added behaviour for QueryOne get. (#543)
Query unchanged as impacts performances. Added tests in bevy_ecs/hecs
This commit is contained in:
parent
9a4167ef7f
commit
1bdb9d3b00
2 changed files with 42 additions and 2 deletions
|
@ -37,7 +37,11 @@ impl<'a, Q: Query> QueryOne<'a, Q> {
|
|||
pub fn get(&mut self) -> Option<<Q::Fetch as Fetch<'_>>::Item> {
|
||||
unsafe {
|
||||
let mut fetch = Q::Fetch::get(self.archetype, self.index)?;
|
||||
Some(fetch.next())
|
||||
if fetch.should_skip() {
|
||||
None
|
||||
} else {
|
||||
Some(fetch.next())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +108,11 @@ where
|
|||
{
|
||||
unsafe {
|
||||
let mut fetch = Q::Fetch::get(self.archetype, self.index)?;
|
||||
Some(fetch.next())
|
||||
if fetch.should_skip() {
|
||||
None
|
||||
} else {
|
||||
Some(fetch.next())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -365,3 +365,35 @@ fn remove_tracking() {
|
|||
"world clears result in 'removed component' states"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn added_tracking() {
|
||||
let mut world = World::new();
|
||||
let a = world.spawn((123,));
|
||||
|
||||
assert_eq!(world.query::<&i32>().iter().count(), 1);
|
||||
assert_eq!(world.query::<Added<i32>>().iter().count(), 1);
|
||||
assert_eq!(world.query_mut::<&i32>().iter().count(), 1);
|
||||
assert_eq!(world.query_mut::<Added<i32>>().iter().count(), 1);
|
||||
assert!(world.query_one::<&i32>(a).unwrap().get().is_some());
|
||||
assert!(world.query_one::<Added<i32>>(a).unwrap().get().is_some());
|
||||
assert!(world.query_one_mut::<&i32>(a).unwrap().get().is_some());
|
||||
assert!(world
|
||||
.query_one_mut::<Added<i32>>(a)
|
||||
.unwrap()
|
||||
.get()
|
||||
.is_some());
|
||||
|
||||
world.clear_trackers();
|
||||
|
||||
assert_eq!(world.query::<&i32>().iter().count(), 1);
|
||||
assert_eq!(world.query::<Added<i32>>().iter().count(), 0);
|
||||
assert_eq!(world.query_mut::<&i32>().iter().count(), 1);
|
||||
assert_eq!(world.query_mut::<Added<i32>>().iter().count(), 0);
|
||||
assert!(world.query_one_mut::<&i32>(a).unwrap().get().is_some());
|
||||
assert!(world
|
||||
.query_one_mut::<Added<i32>>(a)
|
||||
.unwrap()
|
||||
.get()
|
||||
.is_none());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue