From c8e4a5d2aa97ed30012c10068a91748020720bee Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 19 Sep 2023 22:04:35 -0700 Subject: [PATCH] do not step physics on mouse input, only update pos (overwriting previous pos) --- src/body.rs | 3 ++- src/main.rs | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/body.rs b/src/body.rs index 96c6b49..64c55e0 100644 --- a/src/body.rs +++ b/src/body.rs @@ -102,7 +102,7 @@ pub struct MouseInterpolationState { impl MouseInterpolationState { pub fn new() -> Self { Self { - interpolation:MouseInterpolation::Lerp, + interpolation:MouseInterpolation::First, time0:0, time1:1,//ONE NANOSECOND!!!! avoid divide by zero mouse0:glam::IVec2::ZERO, @@ -901,6 +901,7 @@ impl crate::instruction::InstructionConsumer for PhysicsStat } //selectively update body match &ins.instruction { + PhysicsInstruction::Input(InputInstruction::MoveMouse(_)) => (),//dodge time for mouse movement PhysicsInstruction::Input(_) |PhysicsInstruction::ReachWalkTargetVelocity |PhysicsInstruction::CollisionStart(_) diff --git a/src/main.rs b/src/main.rs index fb0ab3d..358437f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -745,7 +745,6 @@ impl strafe_client::framework::Example for GraphicsData { fn device_event(&mut self, event: winit::event::DeviceEvent) { //there's no way this is the best way get a timestamp. let time=self.start_time.elapsed().as_nanos() as i64; - self.physics.run(time);//call it a day match event { winit::event::DeviceEvent::Key(winit::event::KeyboardInput { state, @@ -769,6 +768,7 @@ impl strafe_client::framework::Example for GraphicsData { _ => None, } { + self.physics.run(time); self.physics.process_instruction(TimedInstruction{ time, instruction:PhysicsInstruction::Input(input_instruction), @@ -778,6 +778,9 @@ impl strafe_client::framework::Example for GraphicsData { winit::event::DeviceEvent::MouseMotion { delta,//these (f64,f64) are integers on my machine } => { + //do not step the physics because the mouse polling rate is higher than the physics can run. + //essentially the previous input will be overwritten until a true step runs + //which is fine because they run all the time. self.physics.process_instruction(TimedInstruction{ time, instruction:PhysicsInstruction::Input(InputInstruction::MoveMouse(glam::ivec2(delta.0 as i32,delta.1 as i32))), @@ -788,6 +791,7 @@ impl strafe_client::framework::Example for GraphicsData { } => { println!("mousewheel{:?}",delta); if true{//self.physics.use_scroll + self.physics.run(time); self.physics.process_instruction(TimedInstruction{ time, instruction:PhysicsInstruction::Input(InputInstruction::Jump(true)),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump