RA
iter_unchecked
для смелых :)Size: a a a
RA
iter_unchecked
для смелых :)RA
iter
принимает &mut World
.RA
iter_immutable
, если оба цикла только читают.R
unsafe
хотелось бы держать под капотомA
// Create a query which finds all `Position` and `Velocity` components
let query = <(Write<Position>, Read<Velocity>)>::query();
// Iterate through all entities that match the query in the world
for (mut pos, vel) in query.iter(&mut world) {
pos.x += vel.dx;
pos.y += vel.dy;
}
R
A
R
A
A
R
R
R
A
R
R
A
let damage_query = <(Read<Position>, Read<Damage>)>::query();
let health_query = <(Read<Position>, Write<Health>)>::query();
for (pos1, damage) in damage_query.iter(&mut world) {
for (pos2, mut health) in health_query.iter(&mut world) {
if (need_to_do_damage(pos1, pos2)) {
health.value = health.value - damage.value;
}
}
}
R
&mut world
два раза?A
A
damage_query.iter(&mut world)
можно и без mut