WinningConditionSystem
.join()
iterator? e.g. for z-ordering?
Hi, I've been working on the movement system and got an issue:
impl<'a> System<'a> for DestinationMovement {
type SystemData = (
Entities<'a>,
WriteStorage<'a, Position>,
ReadStorage<'a, Speed>,
ReadStorage<'a, Destination>,
ReadExpect<'a, Timings>,
ReadExpect<'a, Map>,
);
fn run(
&mut self,
(entities, mut positions, speeds, destinations, timings, map): Self::SystemData,
) {
for (_entity, speed, destination, position) in
(&entities, &speeds, &destinations, &mut positions).join()
{
let destination_position = positions.get(destination.0).cloned().unwrap();
// rest of the code is irrelevant
}
}
}
Some entities have a destination
, which is wrapper over Entity
, and to calculate a path to destination I need to retrieve destination's position. Naturally, I also want to have own position of the current entity itself.
Issue is that iterator mutably borrows positions
, so I cannot use it inside loop. For me it looks like a very common issue, so maybe there is known solution for this problem?
I could remove positions
dependency from join
and get both entity and destination position inside loop, but I don't like that it will relax component requirements for this system. Another potential solution I can think of, but haven't tried, is to collect all new positions into separate Vec
and then assign them with another loop. I don't like performance implications of this approach and unsoundness of it.
Is there anything else I can do?
join
within join
by using just Entities
to get both entities, then compare them for inequality and then access storages. In our game I think we first did that, but now were doing simple sweep-and-prune by using flagged storage to maintain internal data structure.
world.insert(unsafe { transmute::<&'_ DebugOverlay, &'static DebugOverlay>(surface.debug_overlay()) });
hey, can someone tell me if a VecStorage will ever shrink in size?
Looking at the VecStorage implementation of UnsafeStorage it seems that when entities as entities are added the vec grows, but the only way it can shrink is when it is cleaned, where all entities are removed. Is my thinking correct?