This commit is contained in:
Quaternions 2025-01-03 02:31:43 -08:00
parent ff011f9f0c
commit cbdc389cc9

View File

@ -16,15 +16,15 @@ struct WindowContext<'a>{
mouse:strafesnet_common::mouse::MouseState,//std::sync::Arc<std::sync::Mutex<>> mouse:strafesnet_common::mouse::MouseState,//std::sync::Arc<std::sync::Mutex<>>
screen_size:glam::UVec2, screen_size:glam::UVec2,
window:&'a winit::window::Window, window:&'a winit::window::Window,
physics_thread:crate::compat_worker::QNWorker<'a, TimedInstruction<crate::physics_worker::Instruction>>, physics_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<crate::physics_worker::Instruction>>,
} }
impl WindowContext<'_>{ impl WindowContext<'_>{
fn get_middle_of_screen(&self)->winit::dpi::PhysicalPosition<u32>{ fn get_middle_of_screen(&self)->winit::dpi::PhysicalPosition<u32>{
winit::dpi::PhysicalPosition::new(self.screen_size.x/2,self.screen_size.y/2) winit::dpi::PhysicalPosition::new(self.screen_size.x/2,self.screen_size.y/2)
} }
fn window_event(&mut self,time:integer::Time,event: winit::event::WindowEvent) { fn window_event(&mut self,time:integer::Time,event:winit::event::WindowEvent){
match event { match event{
winit::event::WindowEvent::DroppedFile(path)=>{ winit::event::WindowEvent::DroppedFile(path)=>{
match crate::file::load(path.as_path()){ match crate::file::load(path.as_path()){
Ok(map)=>self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ChangeMap(map)}).unwrap(), Ok(map)=>self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ChangeMap(map)}).unwrap(),
@ -122,11 +122,11 @@ impl WindowContext<'_>{
} }
} }
fn device_event(&mut self,time:integer::Time,event: winit::event::DeviceEvent) { fn device_event(&mut self,time:integer::Time,event: winit::event::DeviceEvent){
match event { match event{
winit::event::DeviceEvent::MouseMotion { winit::event::DeviceEvent::MouseMotion{
delta,//these (f64,f64) are integers on my machine delta,//these (f64,f64) are integers on my machine
} => { }=>{
if self.manual_mouse_lock{ if self.manual_mouse_lock{
match self.window.set_cursor_position(self.get_middle_of_screen()){ match self.window.set_cursor_position(self.get_middle_of_screen()){
Ok(())=>(), Ok(())=>(),
@ -145,7 +145,7 @@ impl WindowContext<'_>{
}, },
winit::event::DeviceEvent::MouseWheel { winit::event::DeviceEvent::MouseWheel {
delta, delta,
} => { }=>{
println!("mousewheel {:?}",delta); println!("mousewheel {:?}",delta);
if false{//self.physics.style.use_scroll{ if false{//self.physics.style.use_scroll{
self.physics_thread.send(TimedInstruction{ self.physics_thread.send(TimedInstruction{
@ -153,7 +153,7 @@ impl WindowContext<'_>{
instruction:crate::physics_worker::Instruction::Input(InputInstruction::Jump(true)),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump instruction:crate::physics_worker::Instruction::Input(InputInstruction::Jump(true)),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump
}).unwrap(); }).unwrap();
} }
} },
_=>(), _=>(),
} }
} }
@ -163,54 +163,54 @@ pub fn worker<'a>(
setup_context:crate::setup::SetupContext<'a>, setup_context:crate::setup::SetupContext<'a>,
)->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{ )->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{
// WindowContextSetup::new // WindowContextSetup::new
let user_settings=crate::settings::read_user_settings(); let user_settings=crate::settings::read_user_settings();
let mut graphics=crate::graphics::GraphicsState::new(&setup_context.device,&setup_context.queue,&setup_context.config); let mut graphics=crate::graphics::GraphicsState::new(&setup_context.device,&setup_context.queue,&setup_context.config);
graphics.load_user_settings(&user_settings); graphics.load_user_settings(&user_settings);
//WindowContextSetup::into_context //WindowContextSetup::into_context
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(graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue); let graphics_thread=crate::graphics_worker::new(graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
let mut window_context=WindowContext{ let mut window_context=WindowContext{
manual_mouse_lock:false, manual_mouse_lock:false,
mouse:strafesnet_common::mouse::MouseState::default(), mouse:strafesnet_common::mouse::MouseState::default(),
//make sure to update this!!!!! //make sure to update this!!!!!
screen_size, screen_size,
window, window,
physics_thread:crate::physics_worker::new( physics_thread:crate::physics_worker::new(
graphics_thread, graphics_thread,
user_settings, user_settings,
), ),
}; };
//WindowContextSetup::into_worker //WindowContextSetup::into_worker
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<WindowInstruction>|{ crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<WindowInstruction>|{
match ins.instruction{ match ins.instruction{
WindowInstruction::RequestRedraw=>{ WindowInstruction::RequestRedraw=>{
window_context.window.request_redraw(); window_context.window.request_redraw();
}
WindowInstruction::WindowEvent(window_event)=>{
window_context.window_event(ins.time,window_event);
},
WindowInstruction::DeviceEvent(device_event)=>{
window_context.device_event(ins.time,device_event);
},
WindowInstruction::Resize(size)=>{
window_context.physics_thread.send(
TimedInstruction{
time:ins.time,
instruction:crate::physics_worker::Instruction::Resize(size)
}
).unwrap();
}
WindowInstruction::Render=>{
window_context.physics_thread.send(
TimedInstruction{
time:ins.time,
instruction:crate::physics_worker::Instruction::Render
}
).unwrap();
}
} }
}) WindowInstruction::WindowEvent(window_event)=>{
window_context.window_event(ins.time,window_event);
},
WindowInstruction::DeviceEvent(device_event)=>{
window_context.device_event(ins.time,device_event);
},
WindowInstruction::Resize(size)=>{
window_context.physics_thread.send(
TimedInstruction{
time:ins.time,
instruction:crate::physics_worker::Instruction::Resize(size)
}
).unwrap();
}
WindowInstruction::Render=>{
window_context.physics_thread.send(
TimedInstruction{
time:ins.time,
instruction:crate::physics_worker::Instruction::Render
}
).unwrap();
}
}
})
} }