diff --git a/src/physics.rs b/src/physics.rs index 6fc515a..0af0b19 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -27,6 +27,7 @@ pub enum PhysicsInstruction { // ) //InputInstructions conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it) Input(PhysicsInputInstruction), + SetSensitivity(Ratio64Vec2), } #[derive(Debug)] pub enum PhysicsInputInstruction { @@ -937,27 +938,13 @@ impl Default for PhysicsData{ } impl PhysicsState { - pub fn clear(&mut self){ + fn clear(&mut self){ self.touching.clear(); } - pub const fn output(&self)->PhysicsOutputState{ - PhysicsOutputState{ - body:self.body, - camera:self.camera, - camera_offset:self.style.camera_offset, - mouse_pos:self.input_state.mouse.pos, - } - } - pub fn load_user_settings(&mut self,user_settings:&crate::settings::UserSettings){ - self.camera.sensitivity=user_settings.calculate_sensitivity(); - } - pub fn advance_time(&mut self, time: Time){ + fn advance_time(&mut self, time: Time){ self.body.advance_time(time); self.time=time; } - pub const fn get_next_mouse(&self)->&MouseState{ - self.input_state.get_next_mouse() - } fn next_move_instruction(&self)->Option>{ self.move_state.next_move_instruction(&self.style.strafe,self.time) } @@ -996,7 +983,7 @@ impl PhysicsState { #[derive(Default)] pub struct PhysicsContext{ - pub state:PhysicsState,//this captures the entire state of the physics. + state:PhysicsState,//this captures the entire state of the physics. data:PhysicsData,//data currently loaded into memory which is needded for physics to run, but is not part of the state. } impl instruction::InstructionConsumer for PhysicsContext{ @@ -1011,13 +998,32 @@ impl instruction::InstructionEmitter for PhysicsContext{ } } impl PhysicsContext{ - pub fn spawn(&mut self){ - self.process_instruction(instruction::TimedInstruction{ + pub fn clear(&mut self){ + self.state.clear(); + } + pub fn load_user_settings(&mut self,user_settings:&crate::settings::UserSettings){ + self.process_instruction(TimedInstruction{ time:self.state.time, - instruction: PhysicsInstruction::Input(PhysicsInputInstruction::Reset), + instruction:PhysicsInstruction::SetSensitivity(user_settings.calculate_sensitivity()), }); } - + pub fn spawn(&mut self){ + self.process_instruction(TimedInstruction{ + time:self.state.time, + instruction:PhysicsInstruction::Input(PhysicsInputInstruction::Reset), + }); + } + pub const fn output(&self)->PhysicsOutputState{ + PhysicsOutputState{ + body:self.state.body, + camera:self.state.camera, + camera_offset:self.state.style.camera_offset, + mouse_pos:self.state.input_state.mouse.pos, + } + } + pub const fn get_next_mouse(&self)->&MouseState{ + self.state.input_state.get_next_mouse() + } pub fn generate_models(&mut self,map:&map::CompleteMap){ self.data.modes=map.modes.clone(); let mut used_attributes=Vec::new(); @@ -1087,7 +1093,7 @@ impl PhysicsContext{ } //tickless gaming - pub fn run(&mut self,time_limit:Time){ + fn run(&mut self,time_limit:Time){ //prepare is ommitted - everything is done via instructions. while let Some(instruction)=self.next_instruction(time_limit){//collect //process @@ -1095,6 +1101,13 @@ impl PhysicsContext{ //write hash lol } } + pub fn run_input_instruction(&mut self,instruction:TimedInstruction){ + self.run(instruction.time); + self.process_instruction(TimedInstruction{ + time:instruction.time, + instruction:PhysicsInstruction::Input(instruction.instruction), + }); + } } fn literally_next_instruction_but_with_context(state:&PhysicsState,data:&PhysicsData,time_limit:Time)->Option>{ @@ -1270,7 +1283,9 @@ fn run_teleport_behaviour(wormhole:&Option,models |PhysicsInstruction::ReachWalkTargetVelocity |PhysicsInstruction::CollisionStart(_) |PhysicsInstruction::CollisionEnd(_) - |PhysicsInstruction::StrafeTick=>state.advance_time(ins.time), + |PhysicsInstruction::StrafeTick + |PhysicsInstruction::SetSensitivity(_) + =>state.advance_time(ins.time), } match ins.instruction{ PhysicsInstruction::CollisionStart(c)=>{ @@ -1419,6 +1434,7 @@ fn run_teleport_behaviour(wormhole:&Option,models } } }, + PhysicsInstruction::SetSensitivity(sensitivity)=>state.camera.sensitivity=sensitivity, PhysicsInstruction::Input(input_instruction)=>{ let mut b_refresh_walk_target=true; match input_instruction{ diff --git a/src/physics_worker.rs b/src/physics_worker.rs index 59e3082..37196e1 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -25,7 +25,7 @@ pub enum Instruction{ pub fn new(mut physics:crate::physics::PhysicsContext,mut graphics_worker:crate::compat_worker::INWorker)->crate::compat_worker::QNWorker>{ let mut mouse_blocking=true; - let mut last_mouse_time=physics.state.get_next_mouse().time; + let mut last_mouse_time=physics.get_next_mouse().time; let mut timeline=std::collections::VecDeque::new(); crate::compat_worker::QNWorker::new(move |ins:TimedInstruction|{ if if let Some(phys_input)=match &ins.instruction{ @@ -43,7 +43,7 @@ pub enum Instruction{ timeline.push_front(TimedInstruction{ time:last_mouse_time, instruction:PhysicsInputInstruction::ReplaceMouse( - MouseState{time:last_mouse_time,pos:physics.state.get_next_mouse().pos}, + MouseState{time:last_mouse_time,pos:physics.get_next_mouse().pos}, MouseState{time:ins.time,pos:m} ), }); @@ -79,11 +79,11 @@ pub enum Instruction{ //shitty mice are 125Hz which is 8ms so this should cover that. //setting this to 100us still doesn't print even though it's 10x lower than the polling rate, //so mouse events are probably not handled separately from drawing and fire right before it :( - if Time::from_millis(10){ - graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.state.output(),ins.time,physics.state.get_next_mouse().pos)).unwrap(); + graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.get_next_mouse().pos)).unwrap(); }, Instruction::Resize(size,user_settings)=>{ graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap(); @@ -124,7 +120,7 @@ pub enum Instruction{ graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap(); }, Instruction::ClearModels=>{ - physics.state.clear(); + physics.clear(); graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap(); }, _=>(), diff --git a/src/window.rs b/src/window.rs index 38406c9..3421469 100644 --- a/src/window.rs +++ b/src/window.rs @@ -173,7 +173,7 @@ impl<'a> WindowContextSetup<'a>{ let user_settings=crate::settings::read_user_settings(); let mut physics=crate::physics::PhysicsContext::default(); - physics.state.load_user_settings(&user_settings); + physics.load_user_settings(&user_settings); let mut graphics=crate::graphics::GraphicsState::new(&context.device,&context.queue,&context.config); graphics.load_user_settings(&user_settings);