diff --git a/src/main.rs b/src/main.rs index 1a2ff04..904c45c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,13 +92,13 @@ pub enum ShaderStage { // a component is any type that is 'static, sized, send and sync #[derive(Clone, Copy, Debug, PartialEq)] -struct Position { +pub struct Position { x: f32, y: f32, } #[derive(Clone, Copy, Debug, PartialEq)] -struct Velocity { +pub struct Velocity { dx: f32, dy: f32, } @@ -182,7 +182,7 @@ fn main() { // construct a schedule (you should do this on init) let mut schedule = Schedule::builder() - // .add_system(Renderer::render_test) + .add_system(render::render_test_system()) .build(); // run our schedule (you should do this each update) @@ -320,11 +320,14 @@ fn main() { // Load up the renderer (and the resources) let mut renderer = render::Renderer::init(device.clone(), &sc_desc); - let (plane_vertex_buffer, plane_index_buffer) = Renderer::load_mesh_to_buffer(device.clone(), "plane.obj"); + let (plane_vertex_buffer, plane_index_buffer) = Renderer::load_mesh_to_buffer(device.clone(), "./resources/untitled.obj"); // Init, this wants the references to the buffers... let mut runtime = runtime::Runtime::init(&sc_desc, &device, &queue); + let mut resources = Resources::default(); + resources.insert(runtime); + resources.insert(renderer); // This is just an winit event loop event_loop.run(move |event, _, control_flow| { @@ -352,6 +355,7 @@ fn main() { { // ask for a redraw every 20 millis if last_update_inst.elapsed() > Duration::from_millis(20) { + schedule.execute(&mut world, &mut resources); window.request_redraw(); last_update_inst = Instant::now(); } @@ -372,7 +376,7 @@ fn main() { sc_desc.width = size.width; sc_desc.height = size.height; - renderer.resize(&sc_desc, &device, &queue); + resources.get_mut::().unwrap().resize(&sc_desc, &device, &queue); swap_chain = device.create_swap_chain(&surface, &sc_desc); } @@ -404,7 +408,7 @@ fn main() { } }; - renderer.render(&frame.output, &device, &queue, &spawner); + resources.get_mut::().unwrap().render(&frame.output, &device, &queue, &spawner); } _ => {} } diff --git a/src/render.rs b/src/render.rs index 5a6dabb..157f5c2 100644 --- a/src/render.rs +++ b/src/render.rs @@ -78,8 +78,16 @@ impl Renderer { } } +#[system(for_each)] +pub fn render_test(pos: &mut Position, vel: &Velocity) { + //pos.x += vel.dx * time.elapsed_seconds; + //pos.y += vel.dy * time.elapsed_seconds; +} + impl Renderer { + + pub fn create_buffer(device: &wgpu::Device, indices: Vec, vertices: Vec) -> (Rc, Rc) { @@ -483,11 +491,7 @@ impl Renderer { } } // - // #[system(for_each)] - // pub fn render_test(pos: &mut Position, vel: &Velocity) { - // //pos.x += vel.dx * time.elapsed_seconds; - // //pos.y += vel.dy * time.elapsed_seconds; - // } + pub fn render( &mut self,