use flecs::*;
#[derive(Default, Debug, PartialEq)]
struct Position {
x: f32,
y: f32,
}
#[derive(Default, Debug, PartialEq)]
struct Velocity {
x: f32,
y: f32,
}
fn main() {
let mut world = World::new();
world.component::<Position>();
world.component::<Velocity>();
let mut q = world.query().with_components::<(Position, Velocity)>().build();
world.entity().named("e1").set(Position { x: 10.0, y: 20.0 }).set(Velocity { x: 1.0, y: 2.0 });
world.entity().named("e2").set(Position { x: 10.0, y: 20.0 }).set(Velocity { x: 3.0, y: 4.0 });
world.entity().named("e3").set(Position { x: 10.0, y: 20.0 });
q.each_mut::<(Position, Velocity)>(|e, (p, v)| {
p.x += v.x;
p.y += v.y;
println!("Each - {}: {:?}, {:?}", e.name(), p, v);
});
q.iter(|it| {
let positions = it.field::<Position>(1);
let vels = it.field::<Velocity>(2);
for index in 0..it.count() {
let pos = positions.get(index);
let vel = vels.get(index);
println!("Iter - {:?}, {:?}", pos, vel);
}
});
}
#[cfg(test)]
mod tests {
#[test]
fn flecs_queries_basics() {
super::main();
}
}