From adcd7db4f1015afea00831575c4a3a7682ca75d1 Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Mon, 20 Jan 2025 05:25:13 -0800
Subject: [PATCH] common: timer: the time of a paused timer does not depend on
 the parent time

---
 lib/common/src/run.rs   |  2 +-
 lib/common/src/timer.rs | 20 ++++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/common/src/run.rs b/lib/common/src/run.rs
index 8ab499ce..2b21060f 100644
--- a/lib/common/src/run.rs
+++ b/lib/common/src/run.rs
@@ -76,7 +76,7 @@ impl Run{
 		match &self.state{
 			RunState::Created=>Time::ZERO,
 			RunState::Started{timer}=>timer.time(time),
-			RunState::Finished{timer}=>timer.time(time),
+			RunState::Finished{timer}=>timer.time(),
 		}
 	}
 	pub fn start(&mut self,time:PhysicsTime)->Result<(),Error>{
diff --git a/lib/common/src/timer.rs b/lib/common/src/timer.rs
index b75c68b9..fcd4de7f 100644
--- a/lib/common/src/timer.rs
+++ b/lib/common/src/timer.rs
@@ -157,7 +157,7 @@ impl<T:TimerState> TimerFixed<T,Paused>
 	where Time<T::In>:Copy,
 {
 	pub fn into_unpaused(self,time:Time<T::In>)->TimerFixed<T,Unpaused>{
-		let new_time=self.time(time);
+		let new_time=self.time();
 		let mut timer=TimerFixed{
 			state:self.state,
 			_paused:Unpaused,
@@ -165,6 +165,9 @@ impl<T:TimerState> TimerFixed<T,Paused>
 		timer.set_time(time,new_time);
 		timer
 	}
+	pub fn time(&self)->Time<T::Out>{
+		self.state.get_offset().coerce()
+	}
 }
 impl<T:TimerState> TimerFixed<T,Unpaused>
 	where Time<T::In>:Copy,
@@ -178,6 +181,9 @@ impl<T:TimerState> TimerFixed<T,Unpaused>
 		timer.set_time(time,new_time);
 		timer
 	}
+	pub fn time(&self,time:Time<T::In>)->Time<T::Out>{
+		self.state.get_time(time)
+	}
 }
 
 //the new constructor and time queries are generic across both
@@ -199,12 +205,6 @@ impl<T:TimerState,P:PauseState> TimerFixed<T,P>{
 	pub fn into_state(self)->T{
 		self.state
 	}
-	pub fn time(&self,time:Time<T::In>)->Time<T::Out>{
-		match P::IS_PAUSED{
-			true=>self.state.get_offset().coerce(),
-			false=>self.state.get_time(time),
-		}
-	}
 	pub fn set_time(&mut self,time:Time<T::In>,new_time:Time<T::Out>){
 		match P::IS_PAUSED{
 			true=>self.state.set_offset(new_time.coerce()),
@@ -256,7 +256,7 @@ impl<T:TimerState> Timer<T>
 	}
 	pub fn time(&self,time:Time<T::In>)->Time<T::Out>{
 		match self{
-			Self::Paused(timer)=>timer.time(time),
+			Self::Paused(timer)=>timer.time(),
 			Self::Unpaused(timer)=>timer.time(time),
 		}
 	}
@@ -329,7 +329,7 @@ mod test{
 		//create a paused timer that reads 0s
 		let timer=TimerFixed::<Scaled<Parent,Calculated>,Paused>::from_state(Scaled::new(0.5f32.try_into().unwrap(),sec!(0)));
 		//the paused timer at 1 second should read 0s
-		assert_eq!(timer.time(sec!(1)),sec!(0));
+		assert_eq!(timer.time(),sec!(0));
 
 		//unpause it after one second
 		let timer=timer.into_unpaused(sec!(1));
@@ -339,7 +339,7 @@ mod test{
 		//pause the timer after 11 seconds
 		let timer=timer.into_paused(sec!(11));
 		//the paused timer at 20 seconds should read 5s
-		assert_eq!(timer.time(sec!(20)),sec!(5));
+		assert_eq!(timer.time(),sec!(5));
 	}
 	#[test]
 	fn test_timer()->Result<(),Error>{