From 76bafa4d0aa18690735d740c82440dc26281a166 Mon Sep 17 00:00:00 2001 From: Quaternions 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 b557d85..018b1f0 100644 --- a/lib/common/src/integer.rs +++ b/lib/common/src/integer.rs @@ -14,6 +14,7 @@ impl Time{ 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 fd43710..520841f 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),