From 624b3a94b498d7410049d2227568534c118a9f7d Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 9 Feb 2020 00:38:00 +0100 Subject: ground is now always up-to-date; view doesn't rebuild whole room --- src/systems/moving.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/systems/moving.rs') diff --git a/src/systems/moving.rs b/src/systems/moving.rs index 35f73ea..98b0979 100644 --- a/src/systems/moving.rs +++ b/src/systems/moving.rs @@ -7,7 +7,8 @@ use specs::{ WriteStorage, Read, System, - Join + Join, + Write }; use super::super::pos::Pos; @@ -39,12 +40,12 @@ impl <'a> System<'a> for Move { WriteStorage<'a, Position>, Read<'a, Size>, ReadStorage<'a, Blocking>, - Read<'a, Ground>, + Write<'a, Ground>, ReadStorage<'a, Floor>, WriteStorage<'a, Moved> ); - fn run(&mut self, (entities, controllers, mut positions, size, blocking, ground, floor, mut moved): Self::SystemData) { + fn run(&mut self, (entities, controllers, mut positions, size, blocking, mut ground, floor, mut moved): Self::SystemData) { { let mut ents = Vec::new(); for (ent, _moved) in (&*entities, &moved).join() { @@ -71,9 +72,10 @@ impl <'a> System<'a> for Move { } if !blocked && on_floor { let mut pos_mut = pos.get_mut_unchecked(); - pos_mut.prev = Some(pos_mut.pos); moved.insert(ent, Moved{from: pos_mut.pos}).expect("can't insert Moved"); + ground.cells.get_mut(&pos_mut.pos).unwrap().remove(&ent); pos_mut.pos = newpos.clone(); + ground.cells.entry(newpos).or_insert(HashSet::new()).insert(ent); } } _ => {} -- cgit