mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
simplify entity update loop
This commit is contained in:
parent
0b45c006c8
commit
2a02da1c2f
|
@ -315,19 +315,20 @@ impl EntityMap {
|
|||
.map
|
||||
.iter()
|
||||
.map(|(key, entity)| (key, entity.desired_action(hero)))
|
||||
.filter_map(|(key, action)| match action {
|
||||
Action::Nothing => None,
|
||||
Action::Direction(direction) => Some((key, direction)),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
entities_to_try_update.sort_unstable_by_key(|(e, _)| {
|
||||
let e = self.map.get(*e).unwrap();
|
||||
e.location.x + e.location.y * 1000
|
||||
});
|
||||
let mut entities_to_try_update = VecDeque::from(entities_to_try_update);
|
||||
|
||||
while let Some((entity_to_update_key, desired_action)) = entities_to_try_update.pop_front()
|
||||
{
|
||||
match desired_action {
|
||||
Action::Nothing => {}
|
||||
Action::Direction(direction) => {
|
||||
let entities_to_try_update = entities_to_try_update;
|
||||
|
||||
for (entity_to_update_key, direction) in entities_to_try_update.iter().copied() {
|
||||
let (_, hero_has_died_result, win_has_triggered_result) = self
|
||||
.attempt_move_in_direction(
|
||||
map,
|
||||
|
@ -344,8 +345,6 @@ impl EntityMap {
|
|||
hero_has_died |= hero_has_died_result;
|
||||
win_has_triggered |= win_has_triggered_result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(
|
||||
if hero_has_died {
|
||||
|
|
Loading…
Reference in a new issue