From 76bafa4d0aa18690735d740c82440dc26281a166 Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Tue, 21 Jan 2025 05:34:45 -0800
Subject: [PATCH] fix divide by zero crashes when mouse has not moved

---
 lib/common/src/integer.rs    |  1 +
 strafe-client/src/physics.rs | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/common/src/integer.rs b/lib/common/src/integer.rs
index b557d859..018b1f02 100644
--- a/lib/common/src/integer.rs
+++ b/lib/common/src/integer.rs
@@ -14,6 +14,7 @@ impl<T> Time<T>{
 	pub const MIN:Self=Self::raw(i64::MIN);
 	pub const MAX:Self=Self::raw(i64::MAX);
 	pub const ZERO:Self=Self::raw(0);
+	pub const EPSILON:Self=Self::raw(1);
 	pub const ONE_SECOND:Self=Self::raw(1_000_000_000);
 	pub const ONE_MILLISECOND:Self=Self::raw(1_000_000);
 	pub const ONE_MICROSECOND:Self=Self::raw(1_000);
diff --git a/strafe-client/src/physics.rs b/strafe-client/src/physics.rs
index fd437102..520841fc 100644
--- a/strafe-client/src/physics.rs
+++ b/strafe-client/src/physics.rs
@@ -71,7 +71,7 @@ pub enum InternalInstruction{
 	// Water,
 }
 
-#[derive(Clone,Debug,Default)]
+#[derive(Clone,Debug)]
 pub struct InputState{
 	mouse:MouseState,
 	next_mouse:MouseState,
@@ -104,6 +104,15 @@ impl InputState{
 		((dm*t)/dt).as_ivec2()
 	}
 }
+impl Default for InputState{
+	fn default()->Self{
+		Self{
+			mouse:MouseState{pos:Default::default(),time:Time::ZERO-Time::EPSILON*2},
+			next_mouse:MouseState{pos:Default::default(),time:Time::ZERO-Time::EPSILON},
+			controls:Default::default(),
+		}
+	}
+}
 #[derive(Clone,Debug)]
 enum JumpDirection{
 	Exactly(Planar64Vec3),