Merge branch '7-input-is-lagging' into 'dev'
Resolve "Input is lagging" See merge request Steins7/iv!11
This commit is contained in:
commit
6169470702
2
main.rs
2
main.rs
@ -25,7 +25,7 @@ fn setup_logger() -> Result<(), fern::InitError> {
|
||||
message
|
||||
))
|
||||
})
|
||||
.level(log::LevelFilter::Trace)
|
||||
.level(log::LevelFilter::Debug)
|
||||
.chain(std::io::stdout())
|
||||
.chain(fern::log_file("output.log")?)
|
||||
.apply()?;
|
||||
|
||||
@ -45,7 +45,7 @@ where
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
use std::time::Duration;
|
||||
use std::time::Duration; //, SystemTime};
|
||||
|
||||
use crate::{
|
||||
subengine::subengine_controller::SubengineCommand,
|
||||
@ -56,6 +56,8 @@ where
|
||||
let mut input_keys: Vec<Key> = Vec::new();
|
||||
|
||||
loop {
|
||||
// let frame_start = SystemTime::now();
|
||||
|
||||
for pipeline in &mut self.pipelines {
|
||||
for input in &pipeline.inputs {
|
||||
match input.borrow().read(Duration::from_millis(1)) {
|
||||
@ -114,6 +116,20 @@ where
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// let frame_time = SystemTime::now()
|
||||
// .duration_since(frame_start)
|
||||
// .unwrap();
|
||||
//
|
||||
// let sleep_time = Duration::from_secs_f32(1.0/60.0)
|
||||
// .checked_sub(frame_time)
|
||||
// .unwrap_or_else(|| {
|
||||
// info!("Engine overloaded !");
|
||||
// Duration::from_secs(0)
|
||||
// });
|
||||
// std::thread::sleep(sleep_time);
|
||||
//
|
||||
// info!("FPS : {}", 1.0/frame_time.as_secs_f32());// + sleep_time.as_secs_f32()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ impl WinitWindow {
|
||||
//Since we can't move the EventLoop from one thread to another, we need to create it in the
|
||||
//right thread and then move the Window back to the main thread instead
|
||||
let cloned_name = name.clone();
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let (tx, rx) = mpsc::sync_channel(1);
|
||||
let (tmp_tx, tmp_rx) = mpsc::sync_channel(1);
|
||||
let builder = thread::Builder::new().name(title.into());
|
||||
//the EventLoop hijacks the thread so there is no need to join it later...
|
||||
@ -92,23 +92,25 @@ impl WinitWindow {
|
||||
|
||||
match event {
|
||||
Event::LoopDestroyed => {
|
||||
let _ = tx.send(Key::Closed).unwrap();
|
||||
tx.send(Key::Closed).unwrap();
|
||||
debug!("Closed EventLoop");
|
||||
return;
|
||||
},
|
||||
|
||||
Event::WindowEvent{window_id: _, event} => match event {
|
||||
event::WindowEvent::CloseRequested => {
|
||||
debug!("Close requested");
|
||||
let _ = tx.send(Key::Close).unwrap();
|
||||
tx.send(Key::Close).unwrap();
|
||||
},
|
||||
event::WindowEvent::CursorMoved{position, ..} => {
|
||||
tx.send(Key::MouseMove{
|
||||
let _ = tx.try_send(Key::MouseMove{
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
}).unwrap();
|
||||
});
|
||||
},
|
||||
_ => (),
|
||||
},
|
||||
|
||||
Event::UserEvent(signal) => match signal {
|
||||
Signal::Exit => {
|
||||
debug!("Stopping input thread...");
|
||||
@ -118,6 +120,7 @@ impl WinitWindow {
|
||||
tx.send(Key::Test).unwrap();
|
||||
},
|
||||
},
|
||||
|
||||
_ => (),
|
||||
}})
|
||||
});
|
||||
|
||||
@ -88,6 +88,7 @@ where
|
||||
use gfx_hal::{
|
||||
Instance,
|
||||
window::Surface,
|
||||
adapter::DeviceType,
|
||||
};
|
||||
|
||||
// dry run to print all adapters for debug purposes
|
||||
@ -103,7 +104,7 @@ where
|
||||
let adapter = instance
|
||||
.enumerate_adapters()
|
||||
.into_iter()
|
||||
.find(|a| {
|
||||
.filter(|a| {
|
||||
a.queue_families
|
||||
.iter()
|
||||
.any(|qf|
|
||||
@ -113,7 +114,16 @@ where
|
||||
.all(|surface|
|
||||
surface.supports_queue_family(&qf)
|
||||
))})
|
||||
.max_by_key(|adapter| {
|
||||
match adapter.info.device_type {
|
||||
DeviceType::DiscreteGpu => 4,
|
||||
DeviceType::IntegratedGpu => 3,
|
||||
DeviceType::VirtualGpu => 2,
|
||||
DeviceType::Other => 1,
|
||||
DeviceType::Cpu => 0,
|
||||
}})
|
||||
.ok_or("Could not find a graphical adapter")?;
|
||||
|
||||
info!("Selected adapter : {}", adapter.info.name);
|
||||
|
||||
adapter
|
||||
|
||||
Loading…
Reference in New Issue
Block a user