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
|
.map
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(key, entity)| (key, entity.desired_action(hero)))
|
.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<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
entities_to_try_update.sort_unstable_by_key(|(e, _)| {
|
entities_to_try_update.sort_unstable_by_key(|(e, _)| {
|
||||||
let e = self.map.get(*e).unwrap();
|
let e = self.map.get(*e).unwrap();
|
||||||
e.location.x + e.location.y * 1000
|
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()
|
let entities_to_try_update = entities_to_try_update;
|
||||||
{
|
|
||||||
match desired_action {
|
for (entity_to_update_key, direction) in entities_to_try_update.iter().copied() {
|
||||||
Action::Nothing => {}
|
|
||||||
Action::Direction(direction) => {
|
|
||||||
let (_, hero_has_died_result, win_has_triggered_result) = self
|
let (_, hero_has_died_result, win_has_triggered_result) = self
|
||||||
.attempt_move_in_direction(
|
.attempt_move_in_direction(
|
||||||
map,
|
map,
|
||||||
|
@ -344,8 +345,6 @@ impl EntityMap {
|
||||||
hero_has_died |= hero_has_died_result;
|
hero_has_died |= hero_has_died_result;
|
||||||
win_has_triggered |= win_has_triggered_result;
|
win_has_triggered |= win_has_triggered_result;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(
|
(
|
||||||
if hero_has_died {
|
if hero_has_died {
|
||||||
|
|
Loading…
Reference in a new issue