From 9fa4ea6716f177484b0d7c18caa9992f2d9d2209 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 5 Oct 2023 19:45:15 -0700 Subject: [PATCH] create CompatWorker and move physics back into main thread so it feels good to play eventually I will work on thread stuff again and make threads for everything and workarounds to latency issues --- src/main.rs | 2 +- src/physics.rs | 6 +++--- src/worker.rs | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index cb79127..a356c3c 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 7d7bcae..44da8dc 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 52e0348..bdeb957 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");