Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Apr 17, 2021
1 parent 36e3c0a commit 35c931b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ where
<F::Fetch as Fetch>::init(world, &self.filter_state, last_change_tick, change_tick);

if fetch.is_dense() && filter.is_dense() {
println!("dense");
let tables = &world.storages().tables;
for table_id in self.matched_table_ids.iter() {
let table = &tables[*table_id];
Expand Down Expand Up @@ -422,11 +423,13 @@ where
}
}
} else {
println!("not dense");
let archetypes = &world.archetypes;
for archetype_id in self.matched_archetype_ids.iter() {
let mut offset = 0;
let archetype = &archetypes[*archetype_id];
while offset < archetype.len() {
println!("starting");
let func = func.clone();
scope.spawn(async move {
let mut fetch = <Q::Fetch as Fetch>::init(
Expand All @@ -448,6 +451,7 @@ where

let len = batch_size.min(archetype.len() - offset);
for archetype_index in offset..offset + len {
// for archetype_index in 0..archetype.len() {
if !filter.archetype_filter_fetch(archetype_index) {
continue;
}
Expand Down

0 comments on commit 35c931b

Please sign in to comment.