-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
iter_frag_foreach_sparse.rs
46 lines (40 loc) · 1.56 KB
/
iter_frag_foreach_sparse.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use bevy_ecs::prelude::*;
macro_rules! create_entities {
($world:ident; $( $variants:ident ),*) => {
$(
#[derive(Component)]
struct $variants(f32);
for _ in 0..5 {
$world.spawn($variants(0.0));
}
)*
};
}
#[derive(Component)]
struct Data(f32);
pub struct Benchmark<'w>(World, QueryState<&'w mut Data>);
impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();
for _ in 0..5 {
world.spawn(Data(1.0));
}
create_entities!(world; C00, C01, C02, C03, C04, C05, C06, C07, C08, C09);
create_entities!(world; C10, C11, C12, C13, C14, C15, C16, C17, C18, C19);
create_entities!(world; C20, C21, C22, C23, C24, C25, C26, C27, C28, C29);
create_entities!(world; C30, C31, C32, C33, C34, C35, C36, C37, C38, C39);
create_entities!(world; C40, C41, C42, C43, C44, C45, C46, C47, C48, C49);
create_entities!(world; C50, C51, C52, C53, C54, C55, C56, C57, C58, C59);
create_entities!(world; C60, C61, C62, C63, C64, C65, C66, C67, C68, C69);
create_entities!(world; C70, C71, C72, C73, C74, C75, C76, C77, C78, C79);
create_entities!(world; C80, C81, C82, C83, C84, C85, C86, C87, C88, C89);
create_entities!(world; C90, C91, C92, C93, C94, C95, C96, C97, C98, C99);
let query = world.query::<&mut Data>();
Self(world, query)
}
pub fn run(&mut self) {
self.1.for_each_mut(&mut self.0, |mut data| {
data.0 *= 2.0;
});
}
}