mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
par_for_each: split batches when iterating on a sparse query (#1945)
Fixes #1943 Each batch was iterating over the complete query
This commit is contained in:
parent
20673dbe0e
commit
2bd8ed57d0
2 changed files with 26 additions and 2 deletions
|
@ -249,7 +249,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn par_for_each() {
|
||||
fn par_for_each_dense() {
|
||||
let mut world = World::new();
|
||||
let task_pool = TaskPool::default();
|
||||
let e1 = world.spawn().insert(1).id();
|
||||
|
@ -268,6 +268,29 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn par_for_each_sparse() {
|
||||
let mut world = World::new();
|
||||
world
|
||||
.register_component(ComponentDescriptor::new::<i32>(StorageType::SparseSet))
|
||||
.unwrap();
|
||||
let task_pool = TaskPool::default();
|
||||
let e1 = world.spawn().insert(1).id();
|
||||
let e2 = world.spawn().insert(2).id();
|
||||
let e3 = world.spawn().insert(3).id();
|
||||
let e4 = world.spawn().insert_bundle((4, true)).id();
|
||||
let e5 = world.spawn().insert_bundle((5, true)).id();
|
||||
let results = Arc::new(Mutex::new(Vec::new()));
|
||||
world
|
||||
.query::<(Entity, &i32)>()
|
||||
.par_for_each(&world, &task_pool, 2, |(e, &i)| results.lock().push((e, i)));
|
||||
results.lock().sort();
|
||||
assert_eq!(
|
||||
&*results.lock(),
|
||||
&[(e1, 1), (e2, 2), (e3, 3), (e4, 4), (e5, 5)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn query_missing_component() {
|
||||
let mut world = World::new();
|
||||
|
|
|
@ -446,7 +446,8 @@ where
|
|||
fetch.set_archetype(&self.fetch_state, archetype, tables);
|
||||
filter.set_archetype(&self.filter_state, archetype, tables);
|
||||
|
||||
for archetype_index in 0..archetype.len() {
|
||||
let len = batch_size.min(archetype.len() - offset);
|
||||
for archetype_index in offset..offset + len {
|
||||
if !filter.archetype_filter_fetch(archetype_index) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue