bit more tweaking, need to get the entity component running through the render function now

master
mitchellhansen 4 years ago
parent f933fe8312
commit a38c8e3f36

@ -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::<Renderer>().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::<Renderer>().unwrap().render(&frame.output, &device, &queue, &spawner);
}
_ => {}
}

@ -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<u32>,
vertices: Vec<Vertex>) -> (Rc<Buffer>, Rc<Buffer>) {
@ -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,

Loading…
Cancel
Save