From fbb2ba369cfb42a737168ef131e1e2a89e5e2cd5 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 30 Jul 2024 17:27:22 -0700 Subject: [PATCH] redo data structures --- src/physics_worker.rs | 25 +++++++++++++++++-------- src/window.rs | 16 ++++++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/physics_worker.rs b/src/physics_worker.rs index 1f40f63..6aca31e 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -16,7 +16,10 @@ pub enum InputInstruction{ PracticeFly, } pub enum Instruction{ - Input(InputInstruction), + Passthrough(PassthroughInstruction), + Interpolate(InputInstruction), +} +pub enum PassthroughInstruction{ Render, Resize(winit::dpi::PhysicalSize,crate::settings::UserSettings), GenerateModels(strafesnet_common::map::CompleteMap), @@ -27,7 +30,7 @@ pub struct MouseInterpolator{ queue:std::collections::VecDeque>, } impl MouseInterpolator{ - fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:TimedInstruction){ + fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:InputInstruction,time:Time){ //design is completely inverted //immediately add the instruction to the queue //if there are two mouse instructions or more than 10ms between the first and last @@ -40,20 +43,26 @@ pub fn new(mut physics:crate::physics::PhysicsContext,mut graphics_worker:crate: queue:std::collections::VecDeque::new(), }; crate::compat_worker::QNWorker::new(move |ins:TimedInstruction|{ - let instruction=interpolator.handle_instruction(&mut physics,ins); - match instruction{ - Instruction::Render=>{ + let passthrough_instruction=match ins.instruction{ + Instruction::Passthrough(passthrough_instruction)=>passthrough_instruction, + Instruction::Interpolate(input_instruction)=>{ + interpolator.handle_instruction(&mut physics,input_instruction,ins.time); + return; + }, + }; + match passthrough_instruction{ + PassthroughInstruction::Render=>{ graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.get_next_mouse().pos)).unwrap(); }, - Instruction::Resize(size,user_settings)=>{ + PassthroughInstruction::Resize(size,user_settings)=>{ graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap(); }, - Instruction::GenerateModels(map)=>{ + PassthroughInstruction::GenerateModels(map)=>{ physics.generate_models(&map); physics.spawn(); graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap(); }, - Instruction::ClearModels=>{ + PassthroughInstruction::ClearModels=>{ physics.clear(); graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap(); }, diff --git a/src/window.rs b/src/window.rs index 08ed102..b124701 100644 --- a/src/window.rs +++ b/src/window.rs @@ -115,7 +115,7 @@ impl WindowContext<'_>{ }{ self.physics_thread.send(TimedInstruction{ time, - instruction:crate::physics_worker::Instruction::Input(input_instruction), + instruction:crate::physics_worker::Instruction::Interpolate(input_instruction), }).unwrap(); } }, @@ -143,7 +143,7 @@ impl WindowContext<'_>{ self.mouse.pos+=delta; self.physics_thread.send(TimedInstruction{ time, - instruction:crate::physics_worker::Instruction::Input(InputInstruction::MoveMouse(self.mouse.pos)), + instruction:crate::physics_worker::Instruction::Interpolate(InputInstruction::MoveMouse(self.mouse.pos)), }).unwrap(); }, winit::event::DeviceEvent::MouseWheel { @@ -153,7 +153,7 @@ impl WindowContext<'_>{ if false{//self.physics.style.use_scroll{ self.physics_thread.send(TimedInstruction{ time, - 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::Interpolate(InputInstruction::Jump(true)),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump }).unwrap(); } } @@ -218,7 +218,9 @@ impl<'a> WindowContextSetup<'a>{ window_context.physics_thread.send( TimedInstruction{ time:ins.time, - instruction:crate::physics_worker::Instruction::Resize(size,window_context.user_settings.clone()) + instruction:crate::physics_worker::Instruction::Passthrough( + crate::physics_worker::PassthroughInstruction::Resize(size,window_context.user_settings.clone()) + ) } ).unwrap(); } @@ -226,11 +228,13 @@ impl<'a> WindowContextSetup<'a>{ window_context.physics_thread.send( TimedInstruction{ time:ins.time, - instruction:crate::physics_worker::Instruction::Render + instruction:crate::physics_worker::Instruction::Passthrough( + crate::physics_worker::PassthroughInstruction::Render + ) } ).unwrap(); } } }) } -} \ No newline at end of file +}