base update order on initial positions

This commit is contained in:
Corwin 2023-08-28 15:59:20 +01:00
parent 2a02da1c2f
commit 31c5519bc8
No known key found for this signature in database
2 changed files with 6 additions and 10 deletions

View file

@ -41,7 +41,10 @@ impl Simulation {
let mut entities = EntityMap::default(); let mut entities = EntityMap::default();
let mut animation = Animation::default(); let mut animation = Animation::default();
for (item, location) in a { let mut entities_to_add: Vec<_> = a.collect();
entities_to_add.sort_unstable_by_key(|(_, location)| location.x + location.y * 100);
for (item, location) in entities_to_add {
animation.populate(entities.add(item, location), sfx); animation.populate(entities.add(item, location), sfx);
} }

View file

@ -5,7 +5,7 @@
use core::ops::Neg; use core::ops::Neg;
use agb::fixnum::Vector2D; use agb::fixnum::Vector2D;
use alloc::{boxed::Box, collections::VecDeque, vec::Vec}; use alloc::{boxed::Box, vec::Vec};
use slotmap::{new_key_type, SlotMap}; use slotmap::{new_key_type, SlotMap};
use crate::{ use crate::{
@ -311,7 +311,7 @@ impl EntityMap {
let mut animations = Vec::new(); let mut animations = Vec::new();
let mut entities_to_try_update = self let entities_to_try_update = self
.map .map
.iter() .iter()
.map(|(key, entity)| (key, entity.desired_action(hero))) .map(|(key, entity)| (key, entity.desired_action(hero)))
@ -321,13 +321,6 @@ impl EntityMap {
}) })
.collect::<Vec<_>>(); .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 entities_to_try_update = entities_to_try_update;
for (entity_to_update_key, direction) in entities_to_try_update.iter().copied() { for (entity_to_update_key, direction) in entities_to_try_update.iter().copied() {
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(