use sdl2::pixels::Color; use sdl2::render::WindowCanvas; use sdl2::video::{Window, WindowContext}; use specs::prelude::*; use crate::components::{Pos, StaticDrawable}; use crate::texture_manager::TextureManager; pub struct SysDraw { canvas: WindowCanvas, texture_manager: TextureManager, } impl SysDraw { pub fn new(window: Window) -> Self { let mut canvas = window .into_canvas() .build() .expect("Unable to create canvas"); canvas.set_draw_color(Color::RGB(255, 255, 0)); let texture_manager = TextureManager::new(canvas.texture_creator()); Self { canvas, texture_manager, } } } impl<'a> System<'a> for SysDraw { type SystemData = (ReadStorage<'a, Pos>, ReadStorage<'a, StaticDrawable>); fn run(&mut self, (pos, drawable): Self::SystemData) { self.canvas.clear(); // XXX: This is so slow.. yaaaawn. Replace with ids and texture manager // lifetime? for (_pos, drawable) in (&pos, &drawable).join() { let texture = self .texture_manager .get(&drawable.texture_name) .expect("Unable to load texture"); // let texture_info = texture.query(); self.canvas .copy(&texture, None, None) .expect("Unable to draw texture"); } self.canvas.present(); } }