veloren/common/src/view_distances.rs
Imbris 4126194a5c View distances small fixes and improvement:
* Properly set view_distance field in Client when sending it to the
  server in request_character/request_spectator.
* Removed invalid check I had included in Client::set_view_distance
* ViewDistances::clamp now clamps min to 1 for both types of view distance.
2022-08-25 23:24:43 -04:00

26 lines
940 B
Rust

#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
pub struct ViewDistances {
pub terrain: u32,
/// Server will clamp this to `terrain` if it is larger.
///
/// NOTE: Importantly, the server still loads entities in the `terrain` view
/// distance (at least currently, please update this if you change it!),
/// but the syncing to the client is done based on the entity view
/// distance.
pub entity: u32,
}
impl ViewDistances {
/// Clamps the terrain view distance to an optional max and clamps the
/// entity view distance to the resulting terrain view distance.
///
/// Also ensures both are at a minimum of 1 (unless the provided max is 0).
pub fn clamp(self, max: Option<u32>) -> Self {
let terrain = self.terrain.max(1).min(max.unwrap_or(u32::MAX));
Self {
terrain,
entity: self.entity.max(1).min(terrain),
}
}
}