LIFETIMES
This commit is contained in:
parent
b5a0cf7045
commit
75f958348c
@ -1,13 +1,13 @@
|
|||||||
pub type QNWorker<Task>=CompatNWorker<Task>;
|
pub type QNWorker<'a,Task>=CompatNWorker<'a,Task>;
|
||||||
pub type INWorker<Task>=CompatNWorker<Task>;
|
pub type INWorker<'a,Task>=CompatNWorker<'a,Task>;
|
||||||
|
|
||||||
pub struct CompatNWorker<Task>{
|
pub struct CompatNWorker<'a,Task>{
|
||||||
data:std::marker::PhantomData<Task>,
|
data:std::marker::PhantomData<Task>,
|
||||||
f:Box<dyn FnMut(Task)>,
|
f:Box<dyn FnMut(Task)+'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Task> CompatNWorker<Task>{
|
impl<'a,Task> CompatNWorker<'a,Task>{
|
||||||
pub fn new(f:impl FnMut(Task)+'static)->Self{
|
pub fn new(f:impl FnMut(Task)+'a)->CompatNWorker<'a,Task>{
|
||||||
Self{
|
Self{
|
||||||
data:std::marker::PhantomData,
|
data:std::marker::PhantomData,
|
||||||
f:Box::new(f),
|
f:Box::new(f),
|
||||||
|
@ -872,7 +872,6 @@ impl GraphicsState{
|
|||||||
pub fn resize(
|
pub fn resize(
|
||||||
&mut self,
|
&mut self,
|
||||||
device:&wgpu::Device,
|
device:&wgpu::Device,
|
||||||
queue:&wgpu::Queue,
|
|
||||||
config:&wgpu::SurfaceConfiguration,
|
config:&wgpu::SurfaceConfiguration,
|
||||||
user_settings:&crate::settings::UserSettings,
|
user_settings:&crate::settings::UserSettings,
|
||||||
) {
|
) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
pub enum Instruction{
|
pub enum Instruction{
|
||||||
Render(crate::physics::PhysicsOutputState,crate::integer::Time,glam::IVec2),
|
Render(crate::physics::PhysicsOutputState,crate::integer::Time,glam::IVec2),
|
||||||
//UpdateModel(crate::graphics::ModelUpdate),
|
//UpdateModel(crate::graphics::ModelUpdate),
|
||||||
Resize(winit::dpi::PhysicalSize<u32>),
|
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ideally the graphics thread worker description is:
|
//Ideally the graphics thread worker description is:
|
||||||
@ -14,26 +14,27 @@ WorkerDescription{
|
|||||||
*/
|
*/
|
||||||
//up to three frames in flight, dropping new frame requests when all three are busy, and dropping output frames when one renders out of order
|
//up to three frames in flight, dropping new frame requests when all three are busy, and dropping output frames when one renders out of order
|
||||||
|
|
||||||
pub fn new(
|
pub fn new<'a>(
|
||||||
mut graphics:crate::graphics::GraphicsState,
|
mut graphics:crate::graphics::GraphicsState,
|
||||||
mut config:wgpu::SurfaceConfiguration,
|
mut config:wgpu::SurfaceConfiguration,
|
||||||
surface:wgpu::Surface,
|
surface:wgpu::Surface,
|
||||||
device:&wgpu::Device,
|
device:wgpu::Device,
|
||||||
queue:&wgpu::Queue,
|
queue:wgpu::Queue,
|
||||||
)->crate::compat_worker::INWorker<Instruction>{
|
)->crate::compat_worker::INWorker<'a,Instruction>{
|
||||||
crate::compat_worker::INWorker::new(move |ins:Instruction|{
|
crate::compat_worker::INWorker::new(move |ins:Instruction|{
|
||||||
match ins{
|
match ins{
|
||||||
Instruction::Resize(size)=>{
|
Instruction::Resize(size,user_settings)=>{
|
||||||
config.width=size.width.max(1);
|
config.width=size.width.max(1);
|
||||||
config.height=size.height.max(1);
|
config.height=size.height.max(1);
|
||||||
surface.configure(device,&config);
|
surface.configure(&device,&config);
|
||||||
|
graphics.resize(&device,&config,&user_settings);
|
||||||
}
|
}
|
||||||
Instruction::Render(physics_output,predicted_time,mouse_pos)=>{
|
Instruction::Render(physics_output,predicted_time,mouse_pos)=>{
|
||||||
//this has to go deeper somehow
|
//this has to go deeper somehow
|
||||||
let frame=match surface.get_current_texture(){
|
let frame=match surface.get_current_texture(){
|
||||||
Ok(frame)=>frame,
|
Ok(frame)=>frame,
|
||||||
Err(_)=>{
|
Err(_)=>{
|
||||||
surface.configure(device,&config);
|
surface.configure(&device,&config);
|
||||||
surface
|
surface
|
||||||
.get_current_texture()
|
.get_current_texture()
|
||||||
.expect("Failed to acquire next surface texture!")
|
.expect("Failed to acquire next surface texture!")
|
||||||
@ -44,7 +45,7 @@ pub fn new(
|
|||||||
..wgpu::TextureViewDescriptor::default()
|
..wgpu::TextureViewDescriptor::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
graphics.render(&view,device,queue,physics_output,predicted_time,mouse_pos);
|
graphics.render(&view,&device,&queue,physics_output,predicted_time,mouse_pos);
|
||||||
|
|
||||||
frame.present();
|
frame.present();
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ pub enum InputInstruction {
|
|||||||
pub enum Instruction{
|
pub enum Instruction{
|
||||||
Input(InputInstruction),
|
Input(InputInstruction),
|
||||||
Render,
|
Render,
|
||||||
Resize(winit::dpi::PhysicalSize<u32>),
|
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
||||||
//Graphics(crate::graphics_worker::Instruction),
|
//Graphics(crate::graphics_worker::Instruction),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ pub enum Instruction{
|
|||||||
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
|
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
|
||||||
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
|
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
|
||||||
},
|
},
|
||||||
Instruction::Resize(_)=>Some(PhysicsInputInstruction::Idle),
|
Instruction::Resize(_,_)=>Some(PhysicsInputInstruction::Idle),
|
||||||
Instruction::Render=>Some(PhysicsInputInstruction::Idle),
|
Instruction::Render=>Some(PhysicsInputInstruction::Idle),
|
||||||
}{
|
}{
|
||||||
//non-mouse event
|
//non-mouse event
|
||||||
@ -111,8 +111,8 @@ pub enum Instruction{
|
|||||||
Instruction::Render=>{
|
Instruction::Render=>{
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.next_mouse.pos)).unwrap();
|
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.next_mouse.pos)).unwrap();
|
||||||
},
|
},
|
||||||
Instruction::Resize(size)=>{
|
Instruction::Resize(size,user_settings)=>{
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size)).unwrap();
|
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
|
||||||
},
|
},
|
||||||
_=>(),
|
_=>(),
|
||||||
}
|
}
|
||||||
|
22
src/run.rs
22
src/run.rs
@ -1,6 +1,5 @@
|
|||||||
use crate::physics::PhysicsInstruction;
|
|
||||||
use crate::physics_worker::InputInstruction;
|
|
||||||
use crate::instruction::TimedInstruction;
|
use crate::instruction::TimedInstruction;
|
||||||
|
use crate::physics_worker::InputInstruction;
|
||||||
|
|
||||||
pub enum RunInstruction{
|
pub enum RunInstruction{
|
||||||
Resize(winit::dpi::PhysicalSize<u32>),
|
Resize(winit::dpi::PhysicalSize<u32>),
|
||||||
@ -11,18 +10,16 @@ pub enum RunInstruction{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//holds thread handles to dispatch to
|
//holds thread handles to dispatch to
|
||||||
struct RunContext{
|
struct RunContext<'a>{
|
||||||
manual_mouse_lock:bool,
|
manual_mouse_lock:bool,
|
||||||
mouse:crate::physics::MouseState,//std::sync::Arc<std::sync::Mutex<>>
|
mouse:crate::physics::MouseState,//std::sync::Arc<std::sync::Mutex<>>
|
||||||
device:wgpu::Device,
|
|
||||||
queue:wgpu::Queue,
|
|
||||||
screen_size:glam::UVec2,
|
screen_size:glam::UVec2,
|
||||||
user_settings:crate::settings::UserSettings,
|
user_settings:crate::settings::UserSettings,
|
||||||
window:winit::window::Window,
|
window:winit::window::Window,
|
||||||
physics_thread:crate::compat_worker::QNWorker<TimedInstruction<crate::physics_worker::Instruction>>,
|
physics_thread:crate::compat_worker::QNWorker<'a, TimedInstruction<crate::physics_worker::Instruction>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunContext{
|
impl RunContext<'_>{
|
||||||
fn get_middle_of_screen(&self)->winit::dpi::PhysicalPosition<f32>{
|
fn get_middle_of_screen(&self)->winit::dpi::PhysicalPosition<f32>{
|
||||||
winit::dpi::PhysicalPosition::new(self.screen_size.x as f32/2.0, self.screen_size.y as f32/2.0)
|
winit::dpi::PhysicalPosition::new(self.screen_size.x as f32/2.0, self.screen_size.y as f32/2.0)
|
||||||
}
|
}
|
||||||
@ -121,7 +118,6 @@ impl RunContext{
|
|||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_=>(),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_=>(),
|
_=>(),
|
||||||
@ -200,23 +196,21 @@ impl RunContextSetup{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_context(self,setup_context:crate::setup::SetupContext)->RunContext{
|
fn into_context<'a>(self,setup_context:crate::setup::SetupContext)->RunContext<'a>{
|
||||||
let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height);
|
let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height);
|
||||||
let graphics_thread=crate::graphics_worker::new(self.graphics,setup_context.config,setup_context.surface,&setup_context.device,&setup_context.queue);
|
let graphics_thread=crate::graphics_worker::new(self.graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
|
||||||
RunContext{
|
RunContext{
|
||||||
manual_mouse_lock:false,
|
manual_mouse_lock:false,
|
||||||
mouse:crate::physics::MouseState::default(),
|
mouse:crate::physics::MouseState::default(),
|
||||||
//make sure to update this!!!!!
|
//make sure to update this!!!!!
|
||||||
screen_size,
|
screen_size,
|
||||||
device:setup_context.device,
|
|
||||||
queue:setup_context.queue,
|
|
||||||
user_settings:self.user_settings,
|
user_settings:self.user_settings,
|
||||||
window:self.window,
|
window:self.window,
|
||||||
physics_thread:crate::physics_worker::new(self.physics,graphics_thread),
|
physics_thread:crate::physics_worker::new(self.physics,graphics_thread),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_worker(self,setup_context:crate::setup::SetupContext)->crate::compat_worker::QNWorker<TimedInstruction<RunInstruction>>{
|
pub fn into_worker<'a>(self,setup_context:crate::setup::SetupContext)->crate::compat_worker::QNWorker<'a,TimedInstruction<RunInstruction>>{
|
||||||
let mut run_context=self.into_context(setup_context);
|
let mut run_context=self.into_context(setup_context);
|
||||||
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<RunInstruction>|{
|
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<RunInstruction>|{
|
||||||
match ins.instruction{
|
match ins.instruction{
|
||||||
@ -233,7 +227,7 @@ impl RunContextSetup{
|
|||||||
run_context.physics_thread.send(
|
run_context.physics_thread.send(
|
||||||
TimedInstruction{
|
TimedInstruction{
|
||||||
time:ins.time,
|
time:ins.time,
|
||||||
instruction:crate::physics_worker::Instruction::Resize(size)
|
instruction:crate::physics_worker::Instruction::Resize(size,run_context.user_settings.clone())
|
||||||
}
|
}
|
||||||
).unwrap();
|
).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
use crate::integer::{Ratio64,Ratio64Vec2};
|
use crate::integer::{Ratio64,Ratio64Vec2};
|
||||||
|
#[derive(Clone)]
|
||||||
struct Ratio{
|
struct Ratio{
|
||||||
ratio:f64,
|
ratio:f64,
|
||||||
}
|
}
|
||||||
|
#[derive(Clone)]
|
||||||
enum DerivedFov{
|
enum DerivedFov{
|
||||||
FromScreenAspect,
|
FromScreenAspect,
|
||||||
FromAspect(Ratio),
|
FromAspect(Ratio),
|
||||||
}
|
}
|
||||||
|
#[derive(Clone)]
|
||||||
enum Fov{
|
enum Fov{
|
||||||
Exactly{x:f64,y:f64},
|
Exactly{x:f64,y:f64},
|
||||||
SpecifyXDeriveY{x:f64,y:DerivedFov},
|
SpecifyXDeriveY{x:f64,y:DerivedFov},
|
||||||
@ -16,9 +19,11 @@ impl Default for Fov{
|
|||||||
Fov::SpecifyYDeriveX{x:DerivedFov::FromScreenAspect,y:1.0}
|
Fov::SpecifyYDeriveX{x:DerivedFov::FromScreenAspect,y:1.0}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Clone)]
|
||||||
enum DerivedSensitivity{
|
enum DerivedSensitivity{
|
||||||
FromRatio(Ratio64),
|
FromRatio(Ratio64),
|
||||||
}
|
}
|
||||||
|
#[derive(Clone)]
|
||||||
enum Sensitivity{
|
enum Sensitivity{
|
||||||
Exactly{x:Ratio64,y:Ratio64},
|
Exactly{x:Ratio64,y:Ratio64},
|
||||||
SpecifyXDeriveY{x:Ratio64,y:DerivedSensitivity},
|
SpecifyXDeriveY{x:Ratio64,y:DerivedSensitivity},
|
||||||
@ -30,7 +35,7 @@ impl Default for Sensitivity{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default,Clone)]
|
||||||
pub struct UserSettings{
|
pub struct UserSettings{
|
||||||
fov:Fov,
|
fov:Fov,
|
||||||
sensitivity:Sensitivity,
|
sensitivity:Sensitivity,
|
||||||
|
10
src/setup.rs
10
src/setup.rs
@ -244,7 +244,7 @@ impl SetupContextSetup{
|
|||||||
// };
|
// };
|
||||||
match event{
|
match event{
|
||||||
winit::event::Event::AboutToWait=>{
|
winit::event::Event::AboutToWait=>{
|
||||||
run_thread.send(TimedInstruction{time,instruction:RunInstruction::RequestRedraw});
|
run_thread.send(TimedInstruction{time,instruction:RunInstruction::RequestRedraw}).unwrap();
|
||||||
}
|
}
|
||||||
winit::event::Event::WindowEvent {
|
winit::event::Event::WindowEvent {
|
||||||
event:
|
event:
|
||||||
@ -257,7 +257,7 @@ impl SetupContextSetup{
|
|||||||
window_id:_,
|
window_id:_,
|
||||||
} => {
|
} => {
|
||||||
println!("Resizing to {:?}",size);
|
println!("Resizing to {:?}",size);
|
||||||
run_thread.send(TimedInstruction{time,instruction:RunInstruction::Resize(size)});
|
run_thread.send(TimedInstruction{time,instruction:RunInstruction::Resize(size)}).unwrap();
|
||||||
}
|
}
|
||||||
winit::event::Event::WindowEvent{event,..}=>match event{
|
winit::event::Event::WindowEvent{event,..}=>match event{
|
||||||
winit::event::WindowEvent::KeyboardInput{
|
winit::event::WindowEvent::KeyboardInput{
|
||||||
@ -273,17 +273,17 @@ impl SetupContextSetup{
|
|||||||
elwt.exit();
|
elwt.exit();
|
||||||
}
|
}
|
||||||
winit::event::WindowEvent::RedrawRequested=>{
|
winit::event::WindowEvent::RedrawRequested=>{
|
||||||
run_thread.send(TimedInstruction{time,instruction:RunInstruction::Render});
|
run_thread.send(TimedInstruction{time,instruction:RunInstruction::Render}).unwrap();
|
||||||
}
|
}
|
||||||
_=>{
|
_=>{
|
||||||
run_thread.send(TimedInstruction{time,instruction:RunInstruction::WindowEvent(event)});
|
run_thread.send(TimedInstruction{time,instruction:RunInstruction::WindowEvent(event)}).unwrap();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
winit::event::Event::DeviceEvent{
|
winit::event::Event::DeviceEvent{
|
||||||
event,
|
event,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
run_thread.send(TimedInstruction{time,instruction:RunInstruction::DeviceEvent(event)});
|
run_thread.send(TimedInstruction{time,instruction:RunInstruction::DeviceEvent(event)}).unwrap();
|
||||||
},
|
},
|
||||||
_=>{}
|
_=>{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user