roguelike-game/src/map_indexing_system.rs

27 lines
713 B
Rust
Raw Normal View History

2021-12-24 10:38:44 -05:00
use ::specs::prelude::*;
2021-10-29 11:11:17 -04:00
use crate::{spatial, BlocksTile, Map, Position};
2021-12-10 20:16:48 -05:00
2021-10-29 11:11:17 -04:00
pub struct MapIndexingSystem {}
impl<'a> System<'a> for MapIndexingSystem {
type SystemData = (
ReadExpect<'a, Map>,
2021-10-29 11:11:17 -04:00
ReadStorage<'a, Position>,
ReadStorage<'a, BlocksTile>,
2021-10-29 15:15:22 -04:00
Entities<'a>,
2021-10-29 11:11:17 -04:00
);
fn run(&mut self, data: Self::SystemData) {
let (map, position, blockers, entities) = data;
2021-10-29 11:11:17 -04:00
spatial::clear();
spatial::populate_blocked_from_map(&*map);
2021-10-29 15:15:22 -04:00
for (entity, position) in (&entities, &position).join() {
2021-10-29 11:11:17 -04:00
let idx = map.xy_idx(position.x, position.y);
spatial::index_entity(entity, idx, blockers.get(entity).is_some());
2021-10-29 11:11:17 -04:00
}
}
}