diff --git a/CHANGELOG.md b/CHANGELOG.md index caaf448cba..db42f8af25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed ### Fixed +- Fixed crash due to zooming out very far ## [0.13.0] - 2022-07-23 diff --git a/voxygen/src/scene/camera.rs b/voxygen/src/scene/camera.rs index a81c6f2f6a..c93d3474c7 100644 --- a/voxygen/src/scene/camera.rs +++ b/voxygen/src/scene/camera.rs @@ -541,7 +541,9 @@ impl Camera { } /// Zoom with the ability to switch between first and third-person mode. - pub fn zoom_switch(&mut self, delta: f32, cap: Option) { + /// + /// Note that cap > 18237958000000.0 can cause panic due to float overflow + pub fn zoom_switch(&mut self, delta: f32, cap: f32) { if delta > 0_f32 || self.mode != CameraMode::FirstPerson { let t = self.tgt_dist + delta; const MIN_THIRD_PERSON: f32 = 2.35; @@ -561,9 +563,7 @@ impl Camera { } } - if let Some(cap) = cap { - self.tgt_dist = self.tgt_dist.min(cap); - } + self.tgt_dist = self.tgt_dist.min(cap); } /// Get the distance of the camera from the focus diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 15ca5e10db..78ae2622cb 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -44,7 +44,8 @@ use num::traits::{Float, FloatConst}; use specs::{Entity as EcsEntity, Join, WorldExt}; use vek::*; -const ZOOM_CAP: f32 = 10000.0; +const ZOOM_CAP_PLAYER: f32 = 1000.0; +const ZOOM_CAP_ADMIN: f32 = 100000.0; // TODO: Don't hard-code this. const CURSOR_PAN_SCALE: f32 = 0.005; @@ -380,10 +381,14 @@ impl Scene { }, // Zoom the camera when a zoom event occurs Event::Zoom(delta) => { + let cap = if client.is_moderator() { + ZOOM_CAP_ADMIN + } else { + ZOOM_CAP_PLAYER + }; // when zooming in the distance the camera travelles should be based on the // final distance. This is to make sure the camera travelles the // same distance when zooming in and out - let cap = (!client.is_moderator()).then_some(ZOOM_CAP); if delta < 0.0 { self.camera.zoom_switch( // Thank you Imbris for doing the math