mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added option to not stop raycasting on error
Former-commit-id: 6e094b6514bcda2fbcdfe44dbb90900b50e939c2
This commit is contained in:
parent
266101c90d
commit
fc0f2f0801
@ -9,6 +9,7 @@ pub struct Ray<'a, V: ReadVol, F: RayUntil<V::Vox>> {
|
||||
to: Vec3<f32>,
|
||||
until: F,
|
||||
max_iter: usize,
|
||||
ignore_error: bool,
|
||||
}
|
||||
|
||||
impl<'a, V: ReadVol, F: RayUntil<V::Vox>> Ray<'a, V, F> {
|
||||
@ -19,6 +20,7 @@ impl<'a, V: ReadVol, F: RayUntil<V::Vox>> Ray<'a, V, F> {
|
||||
to,
|
||||
until,
|
||||
max_iter: 100,
|
||||
ignore_error: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +33,11 @@ impl<'a, V: ReadVol, F: RayUntil<V::Vox>> Ray<'a, V, F> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ignore_error(mut self) -> Self {
|
||||
self.ignore_error = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cast(mut self) -> (f32, Result<Option<&'a V::Vox>, V::Err>) {
|
||||
// TODO: Fully test this!
|
||||
|
||||
@ -49,8 +56,8 @@ impl<'a, V: ReadVol, F: RayUntil<V::Vox>> 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
|
||||
|
@ -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<Vec3<i32>>,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user