handsonrust/src/systems/entity_render.rs

25 lines
803 B
Rust
Raw Normal View History

2021-08-28 04:25:52 +00:00
use crate::prelude::*;
#[system]
#[read_component(Point)]
#[read_component(Render)]
2021-08-31 04:40:48 +00:00
#[read_component(Player)]
#[read_component(FieldOfView)]
2021-08-28 04:25:52 +00:00
pub fn entity_render(ecs: &mut SubWorld, #[resource] camera: &mut Camera) {
2021-08-31 04:40:48 +00:00
let mut renderables = <(&Point, &Render)>::query();
let mut fov = <&FieldOfView>::query().filter(component::<Player>());
let player_fov = fov.iter(ecs).nth(0).unwrap();
2021-08-28 04:25:52 +00:00
let mut draw_batch = DrawBatch::new();
draw_batch.target(1);
let offset = Point::new(camera.left_x, camera.top_y);
2021-08-31 04:40:48 +00:00
renderables
2021-08-28 04:25:52 +00:00
.iter(ecs)
2021-08-31 04:40:48 +00:00
.filter(|(pos, _)| player_fov.visible_tiles.contains(&pos))
2021-08-28 04:25:52 +00:00
.for_each(|(pos, render)| {
draw_batch.set(*pos - offset, render.color, render.glyph);
});
draw_batch.submit(5000).expect("Batch error");
}