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/controlinput.rs | |
| parent | 7dfc7956a7c2df9a1df3ea0b32e0c3d2036fa3ce (diff) | |
don't rebuild the ground each step
Diffstat (limited to 'src/systems/controlinput.rs')
| -rw-r--r-- | src/systems/controlinput.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/systems/controlinput.rs b/src/systems/controlinput.rs index 27ef5cf..0771b1e 100644 --- a/src/systems/controlinput.rs +++ b/src/systems/controlinput.rs @@ -11,7 +11,7 @@ use specs::{ Join }; -use crate::components::{Controller, Player}; +use crate::components::{Controller, Player, Removed}; use crate::controls::{Control, Action}; use crate::resources::{Input, NewEntities, Spawn}; use crate::hashmap; @@ -23,8 +23,26 @@ use crate::parameter::Parameter; pub struct ControlInput; impl <'a> System<'a> for ControlInput { - type SystemData = (Entities<'a>, Read<'a, Input>, WriteStorage<'a, Controller>, ReadStorage<'a, Player>, Write<'a, NewEntities>, Read<'a, Spawn>); - fn run(&mut self, (entities, input, mut controllers, players, mut new, spawn): Self::SystemData) { + type SystemData = ( + Entities<'a>, + Read<'a, Input>, + WriteStorage<'a, Controller>, + ReadStorage<'a, Player>, + Write<'a, NewEntities>, + Read<'a, Spawn>, + WriteStorage<'a, Removed> + ); + fn run(&mut self, (entities, input, mut controllers, players, mut new, spawn, mut removed): Self::SystemData) { + { + let mut ents = Vec::new(); + for (ent, _controller) in (&*entities, &controllers).join() { + ents.push(ent); + } + for ent in ents { + controllers.remove(ent); + } + } + let mut playercontrols: HashMap<&str, Control> = HashMap::new(); let mut leaving = HashSet::new(); for action in &input.actions { @@ -44,7 +62,7 @@ impl <'a> System<'a> for ControlInput { let _ = controllers.insert(entity, Controller(control.clone())); } if leaving.contains(&player.name) { - let _ = entities.delete(entity); + let _ = removed.insert(entity, Removed); } } } |
