From fc0f2f0801262df11f22c345779eb97662081b87 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 12 May 2019 06:37:10 +0100 Subject: [PATCH] Added option to not stop raycasting on error Former-commit-id: 6e094b6514bcda2fbcdfe44dbb90900b50e939c2 --- common/src/ray.rs | 11 +++++++++-- common/src/state.rs | 2 +- server/src/lib.rs | 2 +- voxygen/src/scene/camera.rs | 9 ++++++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/common/src/ray.rs b/common/src/ray.rs index c577980f54..49a7e7da37 100644 --- a/common/src/ray.rs +++ b/common/src/ray.rs @@ -9,6 +9,7 @@ pub struct Ray<'a, V: ReadVol, F: RayUntil> { to: Vec3, until: F, max_iter: usize, + ignore_error: bool, } impl<'a, V: ReadVol, F: RayUntil> Ray<'a, V, F> { @@ -19,6 +20,7 @@ impl<'a, V: ReadVol, F: RayUntil> Ray<'a, V, F> { to, until, max_iter: 100, + ignore_error: false, } } @@ -31,6 +33,11 @@ impl<'a, V: ReadVol, F: RayUntil> Ray<'a, V, F> { self } + pub fn ignore_error(mut self) -> Self { + self.ignore_error = true; + self + } + pub fn cast(mut self) -> (f32, Result, V::Err>) { // TODO: Fully test this! @@ -49,8 +56,8 @@ impl<'a, V: ReadVol, F: RayUntil> Ray<'a, V, F> { match self.vol.get(ipos).map(|vox| (vox, (self.until)(vox))) { Ok((vox, true)) => return (dist, Ok(Some(vox))), - Ok((_, false)) => {} - Err(err) => return (dist, Err(err)), + Err(err) if !self.ignore_error => return (dist, Err(err)), + _ => {} } // Allow one iteration above max diff --git a/common/src/state.rs b/common/src/state.rs index 82b28adfcf..34eb33df50 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -36,7 +36,7 @@ pub struct DeltaTime(pub f32); /// too fast, we'd skip important physics events like collisions. This constant determines what /// the upper limit is. If delta time exceeds this value, the game's physics will begin to produce /// time lag. Ideally, we'd avoid such a situation. -const MAX_DELTA_TIME: f32 = 0.2; +const MAX_DELTA_TIME: f32 = 0.05; pub struct Changes { pub new_chunks: HashSet>, diff --git a/server/src/lib.rs b/server/src/lib.rs index 43422d5306..fe6a5ed5f1 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -227,7 +227,7 @@ impl Server { .join() { let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32)); - let dist = (chunk_pos - key).map(|e| e.abs()).reduce_max(); + let dist = Vec2::from(chunk_pos - key).map(|e: i32| e.abs()).reduce_max(); min_dist = min_dist.min(dist); } diff --git a/voxygen/src/scene/camera.rs b/voxygen/src/scene/camera.rs index c72da5ec54..3768986e73 100644 --- a/voxygen/src/scene/camera.rs +++ b/voxygen/src/scene/camera.rs @@ -54,7 +54,14 @@ impl Camera { ) * self.dist), ); - match client.state().terrain().ray(start, end).cast() { + match client + .state() + .terrain() + .ray(start, end) + .ignore_error() + .max_iter(500) + .cast() + { (d, Ok(Some(_))) => f32::min(d - 1.0, self.dist), (_, Ok(None)) => self.dist, (_, Err(_)) => self.dist,