Fixed close button
+ added controller main loop * cleaned code from previous commit
This commit is contained in:
parent
84f606ae16
commit
545f5b326e
@ -55,60 +55,65 @@ where
|
|||||||
|
|
||||||
let mut input_keys: Vec<Key> = Vec::new();
|
let mut input_keys: Vec<Key> = Vec::new();
|
||||||
|
|
||||||
for pipeline in &mut self.pipelines {
|
loop {
|
||||||
for input in &pipeline.inputs {
|
for pipeline in &mut self.pipelines {
|
||||||
match input.borrow().read(Duration::from_millis(1)) {
|
for input in &pipeline.inputs {
|
||||||
Ok(key) => input_keys.push(key),
|
match input.borrow().read(Duration::from_millis(1)) {
|
||||||
Err(_err) => (),
|
Ok(key) => input_keys.push(key),
|
||||||
|
Err(_err) => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
for input_key in &input_keys {
|
||||||
for input_key in &input_keys {
|
match input_key {
|
||||||
match input_key {
|
Key::MouseMove{x,y} => {
|
||||||
Key::MouseMove{x,y} => {
|
self.mouse_pos = [
|
||||||
self.mouse_pos = [
|
(x/1280.0 * 2.0 - 1.0) as f32,
|
||||||
(x/1280.0 * 2.0 - 1.0) as f32,
|
(y/720.0 * 2.0 - 1.0) as f32,
|
||||||
(y/720.0 * 2.0 - 1.0) as f32,
|
];
|
||||||
];
|
self.color = [
|
||||||
self.color = [
|
(x/1280.0) as f32,
|
||||||
(x/1280.0) as f32,
|
(y/720.0) as f32,
|
||||||
(y/720.0) as f32,
|
(((x + y)/2.0)/((1280.0 + 720.0)/2.0)) as f32,
|
||||||
(((x + y)/2.0)/((1280.0 + 720.0)/2.0)) as f32,
|
];
|
||||||
];
|
},
|
||||||
},
|
Key::Close => {
|
||||||
Key::Close => return,
|
info!("Shutting down IV !");
|
||||||
_ => (),
|
return;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
for subengines in &pipeline.subengines {
|
||||||
|
for subengine in subengines {
|
||||||
|
subengine.exec(SubengineCommand::Run);
|
||||||
|
}
|
||||||
|
for subengine in subengines {
|
||||||
|
subengine.wait_for_exec(Duration::from_millis(1)).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let triangle = Triangle {
|
||||||
|
points: [self.mouse_pos, [-0.5, 0.5], [-0.5, -0.5]],
|
||||||
};
|
};
|
||||||
}
|
|
||||||
for subengines in &pipeline.subengines {
|
|
||||||
for subengine in subengines {
|
|
||||||
subengine.exec(SubengineCommand::Run);
|
|
||||||
}
|
|
||||||
for subengine in subengines {
|
|
||||||
subengine.wait_for_exec(Duration::from_millis(1)).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let triangle = Triangle {
|
|
||||||
points: [self.mouse_pos, [-0.5, 0.5], [-0.5, -0.5]],
|
|
||||||
};
|
|
||||||
|
|
||||||
let colors = [
|
let colors = [
|
||||||
[self.color[0], self.color[1], self.color[2]],
|
[self.color[0], self.color[1], self.color[2]],
|
||||||
[self.color[2], self.color[0], self.color[1]],
|
[self.color[2], self.color[0], self.color[1]],
|
||||||
[self.color[1], self.color[2], self.color[0]],
|
[self.color[1], self.color[2], self.color[0]],
|
||||||
];
|
];
|
||||||
|
|
||||||
for (renderer, output) in &mut pipeline.renderers {
|
for (renderer, output) in &mut pipeline.renderers {
|
||||||
// match renderer.draw_clear_frame(output, self.color) {
|
// match renderer.draw_clear_frame(output, self.color) {
|
||||||
// Err(err) => warn!("{}", err),
|
// Err(err) => warn!("{}", err),
|
||||||
// _ => (),
|
// _ => (),
|
||||||
// }
|
// }
|
||||||
match renderer.draw_triangle_frame(output, triangle, colors) {
|
match renderer.draw_triangle_frame(output, triangle, colors) {
|
||||||
Err(err) => warn!("{}", err),
|
Err(err) => warn!("{}", err),
|
||||||
_ => (),
|
_ => (),
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//These tests are disabled because of some stange issue with cargo not waiting for the drop
|
//These tests are disabled because of some stange issue with cargo not waiting for the drop
|
||||||
|
|||||||
@ -90,10 +90,7 @@ pub fn run() -> Result<(), &'static str> {
|
|||||||
|
|
||||||
//running controller
|
//running controller
|
||||||
let mut controller = Controller::new(vec![subengine_pipeline]);
|
let mut controller = Controller::new(vec![subengine_pipeline]);
|
||||||
loop {
|
controller.run();
|
||||||
//for _i in 0..40 {
|
|
||||||
controller.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
//let engine_pipelines = vec![
|
//let engine_pipelines = vec![
|
||||||
// EnginePipeline {
|
// EnginePipeline {
|
||||||
|
|||||||
@ -189,11 +189,11 @@ where
|
|||||||
|
|
||||||
//println!("Frame nb : {}", self.frames.len());
|
//println!("Frame nb : {}", self.frames.len());
|
||||||
//TODO frames number diminish sometimes at resize...
|
//TODO frames number diminish sometimes at resize...
|
||||||
static mut id: i32 = 0;
|
//static mut id: i32 = 0;
|
||||||
let mut frame = self.frames.pop_back().unwrap();
|
let mut frame = self.frames.pop_back().unwrap();
|
||||||
unsafe {
|
//unsafe {
|
||||||
id = (id+1)%3;
|
// id = (id+1)%3;
|
||||||
}
|
//}
|
||||||
|
|
||||||
trace!("Waiting for Frame...");
|
trace!("Waiting for Frame...");
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -214,9 +214,10 @@ where
|
|||||||
frame.command_buffer.reset(false); //TODO may be needed at some point...
|
frame.command_buffer.reset(false); //TODO may be needed at some point...
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
//unsafe {
|
||||||
trace!("Acquiring Frame {}...", id);
|
// trace!("Acquiring Frame {}...", id);
|
||||||
}
|
//}
|
||||||
|
trace!("Acquiring Frame...");
|
||||||
let image = unsafe {
|
let image = unsafe {
|
||||||
match self.surface.acquire_image(core::u64::MAX) {
|
match self.surface.acquire_image(core::u64::MAX) {
|
||||||
Ok((image, suboptimal)) => {
|
Ok((image, suboptimal)) => {
|
||||||
@ -228,7 +229,7 @@ where
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
trace!("Creating Framebuffer...");
|
trace!("Creating Framebuffer...");
|
||||||
let mut framebuffer = unsafe {
|
let framebuffer = unsafe {
|
||||||
use gfx_hal::device::Device;
|
use gfx_hal::device::Device;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
@ -239,15 +240,12 @@ where
|
|||||||
.unwrap() //TODO improve that
|
.unwrap() //TODO improve that
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
//unsafe {
|
||||||
use gfx_hal::{
|
// use gfx_hal::{device::Device};
|
||||||
device::Device,
|
|
||||||
command::CommandBuffer,
|
|
||||||
};
|
|
||||||
|
|
||||||
gpu.device()
|
// gpu.device()
|
||||||
.set_framebuffer_name(&mut framebuffer, format!("frambuffer {}", id).as_str());
|
// .set_framebuffer_name(&mut framebuffer, format!("frambuffer {}", id).as_str());
|
||||||
}
|
//}
|
||||||
|
|
||||||
frame.link_swapchain_image(gpu, image, framebuffer);
|
frame.link_swapchain_image(gpu, image, framebuffer);
|
||||||
|
|
||||||
|
|||||||
@ -98,10 +98,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn link_swapchain_image(&mut self,
|
pub fn link_swapchain_image(&mut self,
|
||||||
gpu: &Gpu<B>,
|
_gpu: &Gpu<B>, //TODO clear that when framebuffer issue is fixed
|
||||||
image: <B::Surface as PresentationSurface<B>>::SwapchainImage,
|
image: <B::Surface as PresentationSurface<B>>::SwapchainImage,
|
||||||
framebuffer: B::Framebuffer) {
|
framebuffer: B::Framebuffer) {
|
||||||
use gfx_hal::device::Device;
|
|
||||||
|
|
||||||
self.framebuffer = Some(framebuffer);
|
self.framebuffer = Some(framebuffer);
|
||||||
//match self.framebuffer.replace(framebuffer) {
|
//match self.framebuffer.replace(framebuffer) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user