veloren_common/
view_distances.rs

1#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
2pub struct ViewDistances {
3    pub terrain: u32,
4    /// Server will clamp this to `terrain` if it is larger.
5    ///
6    /// NOTE: Importantly, the server still loads entities in the `terrain` view
7    /// distance (at least currently, please update this if you change it!),
8    /// but the syncing to the client is done based on the entity view
9    /// distance.
10    pub entity: u32,
11}
12
13impl ViewDistances {
14    /// Clamps the terrain view distance to an optional max and clamps the
15    /// entity view distance to the resulting terrain view distance.
16    ///
17    /// Also ensures both are at a minimum of 1 (unless the provided max is 0).
18    pub fn clamp(self, max: Option<u32>) -> Self {
19        let terrain = self.terrain.clamp(1, max.unwrap_or(u32::MAX));
20        Self {
21            terrain,
22            entity: self.entity.clamp(1, terrain),
23        }
24    }
25}