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();
|
||||
|
||||
for pipeline in &mut self.pipelines {
|
||||
for input in &pipeline.inputs {
|
||||
match input.borrow().read(Duration::from_millis(1)) {
|
||||
Ok(key) => input_keys.push(key),
|
||||
Err(_err) => (),
|
||||
loop {
|
||||
for pipeline in &mut self.pipelines {
|
||||
for input in &pipeline.inputs {
|
||||
match input.borrow().read(Duration::from_millis(1)) {
|
||||
Ok(key) => input_keys.push(key),
|
||||
Err(_err) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
for input_key in &input_keys {
|
||||
match input_key {
|
||||
Key::MouseMove{x,y} => {
|
||||
self.mouse_pos = [
|
||||
(x/1280.0 * 2.0 - 1.0) as f32,
|
||||
(y/720.0 * 2.0 - 1.0) as f32,
|
||||
];
|
||||
self.color = [
|
||||
(x/1280.0) as f32,
|
||||
(y/720.0) as f32,
|
||||
(((x + y)/2.0)/((1280.0 + 720.0)/2.0)) as f32,
|
||||
];
|
||||
},
|
||||
Key::Close => return,
|
||||
_ => (),
|
||||
for input_key in &input_keys {
|
||||
match input_key {
|
||||
Key::MouseMove{x,y} => {
|
||||
self.mouse_pos = [
|
||||
(x/1280.0 * 2.0 - 1.0) as f32,
|
||||
(y/720.0 * 2.0 - 1.0) as f32,
|
||||
];
|
||||
self.color = [
|
||||
(x/1280.0) as f32,
|
||||
(y/720.0) as f32,
|
||||
(((x + y)/2.0)/((1280.0 + 720.0)/2.0)) as f32,
|
||||
];
|
||||
},
|
||||
Key::Close => {
|
||||
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 = [
|
||||
[self.color[0], self.color[1], self.color[2]],
|
||||
[self.color[2], self.color[0], self.color[1]],
|
||||
[self.color[1], self.color[2], self.color[0]],
|
||||
];
|
||||
|
||||
let colors = [
|
||||
[self.color[0], self.color[1], self.color[2]],
|
||||
[self.color[2], self.color[0], self.color[1]],
|
||||
[self.color[1], self.color[2], self.color[0]],
|
||||
];
|
||||
|
||||
for (renderer, output) in &mut pipeline.renderers {
|
||||
// match renderer.draw_clear_frame(output, self.color) {
|
||||
// Err(err) => warn!("{}", err),
|
||||
// _ => (),
|
||||
// }
|
||||
match renderer.draw_triangle_frame(output, triangle, colors) {
|
||||
Err(err) => warn!("{}", err),
|
||||
_ => (),
|
||||
for (renderer, output) in &mut pipeline.renderers {
|
||||
// match renderer.draw_clear_frame(output, self.color) {
|
||||
// Err(err) => warn!("{}", err),
|
||||
// _ => (),
|
||||
// }
|
||||
match renderer.draw_triangle_frame(output, triangle, colors) {
|
||||
Err(err) => warn!("{}", err),
|
||||
_ => (),
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
//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
|
||||
let mut controller = Controller::new(vec![subengine_pipeline]);
|
||||
loop {
|
||||
//for _i in 0..40 {
|
||||
controller.run();
|
||||
}
|
||||
controller.run();
|
||||
|
||||
//let engine_pipelines = vec![
|
||||
// EnginePipeline {
|
||||
|
||||
@ -189,11 +189,11 @@ where
|
||||
|
||||
//println!("Frame nb : {}", self.frames.len());
|
||||
//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();
|
||||
unsafe {
|
||||
id = (id+1)%3;
|
||||
}
|
||||
//unsafe {
|
||||
// id = (id+1)%3;
|
||||
//}
|
||||
|
||||
trace!("Waiting for Frame...");
|
||||
unsafe {
|
||||
@ -214,9 +214,10 @@ where
|
||||
frame.command_buffer.reset(false); //TODO may be needed at some point...
|
||||
};
|
||||
|
||||
unsafe {
|
||||
trace!("Acquiring Frame {}...", id);
|
||||
}
|
||||
//unsafe {
|
||||
// trace!("Acquiring Frame {}...", id);
|
||||
//}
|
||||
trace!("Acquiring Frame...");
|
||||
let image = unsafe {
|
||||
match self.surface.acquire_image(core::u64::MAX) {
|
||||
Ok((image, suboptimal)) => {
|
||||
@ -228,7 +229,7 @@ where
|
||||
}};
|
||||
|
||||
trace!("Creating Framebuffer...");
|
||||
let mut framebuffer = unsafe {
|
||||
let framebuffer = unsafe {
|
||||
use gfx_hal::device::Device;
|
||||
use std::borrow::Borrow;
|
||||
|
||||
@ -239,15 +240,12 @@ where
|
||||
.unwrap() //TODO improve that
|
||||
};
|
||||
|
||||
unsafe {
|
||||
use gfx_hal::{
|
||||
device::Device,
|
||||
command::CommandBuffer,
|
||||
};
|
||||
//unsafe {
|
||||
// use gfx_hal::{device::Device};
|
||||
|
||||
gpu.device()
|
||||
.set_framebuffer_name(&mut framebuffer, format!("frambuffer {}", id).as_str());
|
||||
}
|
||||
// gpu.device()
|
||||
// .set_framebuffer_name(&mut framebuffer, format!("frambuffer {}", id).as_str());
|
||||
//}
|
||||
|
||||
frame.link_swapchain_image(gpu, image, framebuffer);
|
||||
|
||||
|
||||
@ -98,10 +98,9 @@ where
|
||||
}
|
||||
|
||||
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,
|
||||
framebuffer: B::Framebuffer) {
|
||||
use gfx_hal::device::Device;
|
||||
|
||||
self.framebuffer = Some(framebuffer);
|
||||
//match self.framebuffer.replace(framebuffer) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user