diff options
| author | troido <troido@protonmail.com> | 2020-02-08 18:50:58 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-08 18:50:58 +0100 |
| commit | 3ebe9e6f792a0457c6f3b37b6e9d92c83f8694e2 (patch) | |
| tree | aaa81d23a4816ebecacc64593419d3d811b7283b /src/systems/makefloor.rs | |
| parent | 7dfc7956a7c2df9a1df3ea0b32e0c3d2036fa3ce (diff) | |
don't rebuild the ground each step
Diffstat (limited to 'src/systems/makefloor.rs')
| -rw-r--r-- | src/systems/makefloor.rs | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/systems/makefloor.rs b/src/systems/makefloor.rs index 8b550bc..74e4389 100644 --- a/src/systems/makefloor.rs +++ b/src/systems/makefloor.rs @@ -1,4 +1,5 @@ +use std::collections::HashSet; use specs::{ ReadStorage, @@ -8,20 +9,40 @@ use specs::{ Join }; -use super::super::components::Position; +use crate::components::{ + Position, + New, + Moved, + Removed +}; -use super::super::resources::{ +use crate::resources::{ Ground }; +#[derive(Default)] pub struct MakeFloor; impl <'a> System<'a> for MakeFloor { - type SystemData = (Entities<'a>, Write<'a, Ground>, ReadStorage<'a, Position>); - fn run(&mut self, (entities, mut ground, positions): Self::SystemData) { - ground.cells.clear(); - for (ent, pos) in (&entities, &positions).join() { - ground.cells.entry(pos.pos).or_insert(Vec::new()).push(ent); + type SystemData = ( + Entities<'a>, + Write<'a, Ground>, + ReadStorage<'a, Position>, + ReadStorage<'a, New>, + ReadStorage<'a, Moved>, + ReadStorage<'a, Removed> + ); + fn run(&mut self, (entities, mut ground, positions, new, moved, removed): Self::SystemData) { + for (ent, pos, _new) in (&entities, &positions, &new).join() { + ground.cells.entry(pos.pos).or_insert(HashSet::new()).insert(ent); + } + for (ent, pos, mov) in (&entities, &positions, &moved).join() { + ground.cells.entry(pos.pos).or_insert(HashSet::new()).insert(ent); + ground.cells.get_mut(&mov.from).unwrap().remove(&ent); + } + for (ent, pos, _removed) in (&entities, &positions, &removed).join() { + ground.cells.get_mut(&pos.pos).unwrap().remove(&ent); } } } + |
