Struct veloren_common::terrain::map::MapSizeLg
source · pub struct MapSizeLg(Vec2<u32>);
Expand description
Base two logarithm of a world size, in chunks, per dimension (each dimension must be a power of 2, so the logarithm is exact).
NOTE: As an invariant, each dimension must be between 0 and
[MAX_WORLD_BLOCKS_LG] - [TERRAIN_CHUNK_BLOCKS_LG]
.
NOTE: As an invariant, (1 << ([DEFAULT_WORLD_CHUNKS_LG] + [TERRAIN_CHUNK_BLOCKS_LG]))
fits in an i32 (derived from the invariant
on MAX_WORLD_BLOCKS_LG).
NOTE: As an invariant, each dimension (in chunks) must fit in a i16.
NOTE: As an invariant, the product of dimensions (in chunks) must fit in a usize.
These invariants are all checked on construction of a MapSizeLg
.
Tuple Fields§
§0: Vec2<u32>
Implementations§
source§impl MapSizeLg
impl MapSizeLg
sourcepub const fn new(map_size_lg: Vec2<u32>) -> Result<Self, ()>
pub const fn new(map_size_lg: Vec2<u32>) -> Result<Self, ()>
Construct a new MapSizeLg
, returning an error if the needed invariants
do not hold and the vector otherwise.
TODO: In the future, we may use unsafe code to assert to the compiler that these invariants indeed hold, safely opening up optimizations that might not otherwise be available at runtime.
sourcepub const fn chunks_len(self) -> usize
pub const fn chunks_len(self) -> usize
Get the size of an array of the correct size to hold all chunks.
sourcepub const fn contains_chunk(&self, chunk_key: Vec2<i32>) -> bool
pub const fn contains_chunk(&self, chunk_key: Vec2<i32>) -> bool
Determine whether a chunk position is in bounds.