+ added defined code structure + started implementing generic outputs + added support for multiples windows + switched to frame-based architecture
173 lines
5.3 KiB
Rust
173 lines
5.3 KiB
Rust
#[cfg(test)]
|
|
//--------------------------------------------------------------------------------------------------
|
|
/* imports */
|
|
|
|
#[allow(unused_imports)]
|
|
use log::{debug, error, info, trace, warn};
|
|
|
|
//use std::{
|
|
// sync::mpsc,
|
|
// thread,
|
|
// collections::HashMap,
|
|
// cell::RefCell,
|
|
//};
|
|
|
|
use gfx_backend_vulkan as vk_back;
|
|
|
|
pub mod utils;
|
|
use crate::utils::Rect;
|
|
|
|
mod winit_window;
|
|
use winit_window::WinitWindow;
|
|
|
|
//use winit::{
|
|
// event::{Event, WindowEvent},
|
|
// event_loop::ControlFlow,
|
|
//};
|
|
|
|
mod renderer;
|
|
use renderer::Renderer;
|
|
|
|
//mod local_state;
|
|
//use local_state::LocalState;
|
|
|
|
pub enum Command {
|
|
NoCommand,
|
|
Stop,
|
|
Color{
|
|
r: f32,
|
|
g: f32,
|
|
b: f32,
|
|
a: f32,
|
|
},
|
|
}
|
|
|
|
pub enum Input {
|
|
Close,
|
|
Mouse{
|
|
x: f64,
|
|
y: f64,
|
|
},
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
/* functions */
|
|
|
|
/// The main function of the library
|
|
pub fn run() -> Result<(), &'static str> {
|
|
|
|
let mut windows = vec![
|
|
WinitWindow::new("IV", Rect {w: 1280, h: 720})?,
|
|
WinitWindow::new("IV 2", Rect {w: 720, h: 480})?,
|
|
];
|
|
|
|
let mut renderer: Renderer<vk_back::Backend> = Renderer::new(&mut windows)?;
|
|
//let local_state = LocalState::default();
|
|
|
|
let color = [0.5, 0.0, 0.0, 0.1];
|
|
|
|
loop {
|
|
for mut window in &mut windows {
|
|
let _ = renderer.draw_clear_frame(&mut window, color);
|
|
}
|
|
}
|
|
}
|
|
|
|
// let (input_tx, input_rx) = mpsc::channel();
|
|
// let mut window_senders = HashMap::with_capacity(1);
|
|
// window_senders.insert(1, input_tx);
|
|
//
|
|
// let control_thread = RefCell::new(Some(thread::spawn(move || {
|
|
// #[allow(unused_imports)]
|
|
// use log::{debug, error, info, trace, warn};
|
|
//
|
|
// let (cmd_tx, cmd_rx) = mpsc::channel();
|
|
// let render_thread = thread::spawn(move || {
|
|
// #[allow(unused_imports)]
|
|
// use log::{debug, error, info, trace, warn};
|
|
//
|
|
// let mut color = [0.0, 0.0, 0.0, 0.0];
|
|
//
|
|
// loop {
|
|
//
|
|
// //TODO manage errors
|
|
// for window in windows {
|
|
// let _ = renderer.draw_clear_frame(&mut window, color);
|
|
// }
|
|
//
|
|
// match cmd_rx.try_recv().unwrap_or(Command::NoCommand) {
|
|
// Command::NoCommand => (),
|
|
// Command::Stop => {
|
|
// warn!("Stop render thread");
|
|
// return;
|
|
// },
|
|
// Command::Color{r, g, b, a} => {
|
|
// color = [r, g, b, a];
|
|
// },
|
|
// }
|
|
// }
|
|
// });
|
|
//
|
|
// loop {
|
|
// match input_rx.recv().unwrap() {
|
|
// Input::Close => {
|
|
// cmd_tx.send(Command::Stop).unwrap();
|
|
// //TODO stop event_loop
|
|
// warn!("wait for render thread");
|
|
// render_thread.join().unwrap();
|
|
// warn!("Stop control thread");
|
|
// return;
|
|
// },
|
|
// Input::Mouse{x, y} => {
|
|
// let pos = Command::Color{
|
|
// r: (x/1280.0) as f32,
|
|
// g: (y/720.0) as f32,
|
|
// b: ((x/1280.0 + y/720.0)/2.0) as f32,
|
|
// a: 1.0,
|
|
// };
|
|
// cmd_tx.send(pos).unwrap();
|
|
// },
|
|
// }
|
|
// }
|
|
// })));
|
|
//
|
|
// windows[0].event_loop.run(move |event, _, control_flow| {
|
|
// #[allow(unused_imports)]
|
|
// use log::{debug, error, info, trace, warn};
|
|
//
|
|
// *control_flow = ControlFlow::Wait;
|
|
//
|
|
// //TODO manage errors
|
|
// let input_tx = window_senders.get(&1).unwrap();
|
|
// match event {
|
|
// Event::WindowEvent{window_id: _, event} => match event {
|
|
// WindowEvent::CloseRequested => {
|
|
// input_tx.send(Input::Close).unwrap();
|
|
// let handle = control_thread.replace(None).unwrap();
|
|
// warn!("Wait for control thread");
|
|
// handle.join().unwrap();
|
|
// warn!("Stop input thread");
|
|
// *control_flow = ControlFlow::Exit;
|
|
// },
|
|
// WindowEvent::CursorMoved{position, ..} => {
|
|
// input_tx
|
|
// .send(Input::Mouse{
|
|
// x: position.x,
|
|
// y: position.y})
|
|
// .unwrap();
|
|
// },
|
|
// _ => (),
|
|
// }
|
|
// _ => (),
|
|
// }
|
|
// });
|
|
//}
|
|
//
|
|
//mod tests {
|
|
// #[test]
|
|
// fn it_works() {
|
|
// assert_eq!(2 + 2, 4);
|
|
// }
|
|
//}
|