diff options
| author | troido <troido@protonmail.com> | 2020-02-09 00:38:00 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-09 00:38:00 +0100 |
| commit | 624b3a94b498d7410049d2227568534c118a9f7d (patch) | |
| tree | e8ef65c48e332a8f1c90d97c6aa346baffece394 /src/systems/moving.rs | |
| parent | b56add981c2f520789b97d1ee6f71dae41e8c900 (diff) | |
ground is now always up-to-date; view doesn't rebuild whole room
Diffstat (limited to 'src/systems/moving.rs')
| -rw-r--r-- | src/systems/moving.rs | 10 |
1 files changed, 6 insertions, 4 deletions
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); } } _ => {} |
