From 623a2d2a4f37aa579564b260b97bcffae48a46cc Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Wed, 21 Feb 2024 04:11:31 -0800
Subject: [PATCH] be pedantic about public private

---
 src/physics.rs        | 62 +++++++++++++++++++++++++++----------------
 src/physics_worker.rs | 18 +++++--------
 src/window.rs         |  2 +-
 3 files changed, 47 insertions(+), 35 deletions(-)

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<TimedInstruction<PhysicsInstruction>>{
 		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<PhysicsInstruction> for PhysicsContext{
@@ -1011,13 +998,32 @@ impl instruction::InstructionEmitter<PhysicsInstruction> 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<PhysicsInputInstruction>){
+		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<TimedInstruction<PhysicsInstruction>>{
@@ -1270,7 +1283,9 @@ fn run_teleport_behaviour(wormhole:&Option<gameplay_attributes::Wormhole>,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<gameplay_attributes::Wormhole>,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::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{
 		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<Instruction>|{
 			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)<ins.time-physics.state.get_next_mouse().time{
+					if Time::from_millis(10)<ins.time-physics.get_next_mouse().time{
 						//push an event to extrapolate no movement from
 						timeline.push_front(TimedInstruction{
 							time:last_mouse_time,
-							instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.state.get_next_mouse().pos}),
+							instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.get_next_mouse().pos}),
 						});
 						last_mouse_time=ins.time;
 						//stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets.
@@ -104,16 +104,12 @@ pub enum Instruction{
 			}{
 				//empty queue
 				while let Some(instruction)=timeline.pop_front(){
-					physics.run(instruction.time);
-					physics.process_instruction(TimedInstruction{
-						time:instruction.time,
-						instruction:crate::physics::PhysicsInstruction::Input(instruction.instruction),
-					});
+					physics.run_input_instruction(instruction);
 				}
 			}
 			match ins.instruction{
 				Instruction::Render=>{
-					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);