forked from StrafesNET/strafe-client
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
This commit is contained in:
parent
aedef03e7c
commit
9fa4ea6716
@ -119,7 +119,7 @@ pub struct GlobalState{
|
||||
manual_mouse_lock:bool,
|
||||
mouse:physics::MouseState,
|
||||
graphics:GraphicsState,
|
||||
physics_thread:worker::Worker<TimedInstruction<InputInstruction>,physics::PhysicsOutputState>,
|
||||
physics_thread:worker::CompatWorker<TimedInstruction<InputInstruction>,physics::PhysicsOutputState,Box<dyn FnMut(TimedInstruction<InputInstruction>)->physics::PhysicsOutputState>>,
|
||||
}
|
||||
|
||||
impl GlobalState{
|
||||
|
@ -566,11 +566,11 @@ impl PhysicsState {
|
||||
self.intersects.clear();
|
||||
}
|
||||
|
||||
pub fn into_worker(mut self)->crate::worker::Worker<TimedInstruction<InputInstruction>,PhysicsOutputState>{
|
||||
pub fn into_worker(mut self)->crate::worker::CompatWorker<TimedInstruction<InputInstruction>,PhysicsOutputState,Box<dyn FnMut(TimedInstruction<InputInstruction>)->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<InputInstruction>|{
|
||||
crate::worker::CompatWorker::new(self.output(),Box::new(move |ins:TimedInstruction<InputInstruction>|{
|
||||
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{
|
||||
|
@ -45,6 +45,31 @@ impl<Task:Send+'static,Value:Clone+Send+'static> Worker<Task,Value> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CompatWorker<Task,Value:Clone,F>{
|
||||
data:std::marker::PhantomData<Task>,
|
||||
f:F,
|
||||
value:Value,
|
||||
}
|
||||
|
||||
impl<Task,Value:Clone,F:FnMut(Task)->Value> CompatWorker<Task,Value,F> {
|
||||
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");
|
||||
|
Loading…
Reference in New Issue
Block a user