This commit is contained in:
2026-02-16 08:34:29 -08:00
parent dc0cd4c8da
commit 24dc416316
3 changed files with 18 additions and 7 deletions

View File

@@ -1,16 +1,16 @@
use crate::window::Instruction;
use strafesnet_common::integer;
use strafesnet_common::instruction::TimedInstruction;
use strafesnet_common::session::Time as SessionTime;
use crate::window::WindowContext;
pub struct App<'a>{
root_time:std::time::Instant,
window_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTime>>,
window_thread:WindowContext<'a>,
}
impl<'a> App<'a>{
pub fn new(
root_time:std::time::Instant,
window_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTime>>,
window_thread:WindowContext<'a>,
)->App<'a>{
Self{
root_time,
@@ -19,7 +19,7 @@ impl<'a> App<'a>{
}
fn send_timed_instruction(&mut self,instruction:Instruction){
let time=integer::Time::from_nanos(self.root_time.elapsed().as_nanos() as i64);
self.window_thread.send(TimedInstruction{time,instruction}).unwrap();
self.window_thread.send(TimedInstruction{time,instruction});
}
}
impl winit::application::ApplicationHandler for App<'_>{

View File

@@ -178,7 +178,7 @@ pub fn setup_and_start(title:&str){
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
//the thread that spawns the physics thread
let mut window_thread=crate::window::worker(
let mut window_thread=crate::window::WindowContext::new(
&window,
setup_context,
);
@@ -187,7 +187,7 @@ pub fn setup_and_start(title:&str){
window_thread.send(strafesnet_common::instruction::TimedInstruction{
time:strafesnet_common::integer::Time::ZERO,
instruction:crate::window::Instruction::WindowEvent(winit::event::WindowEvent::DroppedFile(arg.into())),
}).unwrap();
});
};
println!("Entering event loop...");

View File

@@ -10,7 +10,7 @@ pub enum Instruction{
}
//holds thread handles to dispatch to
struct WindowContext<'a>{
pub struct WindowContext<'a>{
manual_mouse_lock:bool,
mouse_pos:glam::DVec2,
simulation_paused:bool,
@@ -235,6 +235,17 @@ impl WindowContext<'_>{
}
}
pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){
match ins.instruction{
Instruction::WindowEvent(window_event)=>{
self.window_event(ins.time,window_event);
},
Instruction::DeviceEvent(device_event)=>{
self.device_event(ins.time,device_event);
},
}
}
pub fn new<'a>(
window:&'a winit::window::Window,
setup_context:crate::setup::SetupContext<'a>,