diff --git a/src/main.rs b/src/main.rs index cb79127c..a356c3c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,7 @@ pub struct GlobalState{ manual_mouse_lock:bool, mouse:physics::MouseState, graphics:GraphicsState, - physics_thread:worker::Worker,physics::PhysicsOutputState>, + physics_thread:worker::CompatWorker,physics::PhysicsOutputState,Box)->physics::PhysicsOutputState>>, } impl GlobalState{ diff --git a/src/physics.rs b/src/physics.rs index 7d7bcaeb..44da8dc3 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -566,11 +566,11 @@ impl PhysicsState { self.intersects.clear(); } - pub fn into_worker(mut self)->crate::worker::Worker,PhysicsOutputState>{ + pub fn into_worker(mut self)->crate::worker::CompatWorker,PhysicsOutputState,Box)->PhysicsOutputState>>{ let mut mouse_blocking=true; let mut last_mouse_time=self.next_mouse.time; let mut timeline=std::collections::VecDeque::new(); - crate::worker::Worker::new(self.output(),move |ins:TimedInstruction|{ + crate::worker::CompatWorker::new(self.output(),Box::new(move |ins:TimedInstruction|{ if if let Some(phys_input)=match ins.instruction{ InputInstruction::MoveMouse(m)=>{ if mouse_blocking{ @@ -650,7 +650,7 @@ impl PhysicsState { } } self.output() - }) + })) } pub fn output(&self)->PhysicsOutputState{ diff --git a/src/worker.rs b/src/worker.rs index 52e03485..bdeb9573 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -45,6 +45,31 @@ impl Worker { } } +pub struct CompatWorker{ + data:std::marker::PhantomData, + f:F, + value:Value, +} + +implValue> CompatWorker { + pub fn new(value:Value,f:F) -> Self { + Self { + f, + value, + data:std::marker::PhantomData, + } + } + + pub fn send(&mut self,task:Task)->Result<(),()>{ + self.value=(self.f)(task); + Ok(()) + } + + pub fn grab_clone(&self)->Value{ + self.value.clone() + } +} + #[test]//How to run this test with printing: cargo test --release -- --nocapture fn test_worker() { println!("hiiiii");