From 5215d4004817b6cba15a23c750df995ac8be4537 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 19 Sep 2023 21:32:39 -0700 Subject: [PATCH] TEMP: prevent insane mouse polling from lagging the game --- src/main.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d997e7b..129ec1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,8 @@ struct ModelGraphics { } pub struct Skybox { + block_mouse:strafe_client::body::TIME, + period:strafe_client::body::TIME, start_time: std::time::Instant, screen_size: (u32, u32), physics: strafe_client::body::PhysicsState, @@ -473,6 +475,8 @@ impl strafe_client::framework::Example for Skybox { let depth_view = Self::create_depth_texture(config, device); Skybox { + block_mouse:0, + period:5_000_000, start_time: Instant::now(), screen_size: (config.width,config.height), physics, @@ -495,7 +499,6 @@ impl strafe_client::framework::Example for Skybox { 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, @@ -519,6 +522,7 @@ impl strafe_client::framework::Example for Skybox { _ => None, } { + self.physics.run(time);//call it a day self.physics.process_instruction(TimedInstruction{ time, instruction:PhysicsInstruction::Input(input_instruction), @@ -528,16 +532,34 @@ impl strafe_client::framework::Example for Skybox { winit::event::DeviceEvent::MouseMotion { delta,//these (f64,f64) are integers on my machine } => { - self.physics.process_instruction(TimedInstruction{ - time, - instruction:PhysicsInstruction::Input(InputInstruction::MoveMouse(glam::ivec2(delta.0 as i32,delta.1 as i32))), - }) + let run_the_physics= + if time { println!("mousewheel{:?}",delta); if true{//self.physics.use_scroll + self.physics.run(time);//call it a day 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