mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
types: add LayerBlockCoords::offset() helper
This commit is contained in:
parent
aa2edc3d13
commit
b93e613152
1 changed files with 15 additions and 3 deletions
18
src/types.rs
18
src/types.rs
|
@ -53,6 +53,20 @@ impl Debug for LayerBlockCoords {
|
|||
}
|
||||
}
|
||||
|
||||
impl LayerBlockCoords {
|
||||
/// Computes a block's offset in various data structures
|
||||
///
|
||||
/// Many chunk data structures store block and biome data in the same
|
||||
/// order. This method computes the offset at which the data for the
|
||||
/// block at a given coordinate is stored.
|
||||
pub fn offset(&self) -> usize {
|
||||
use BLOCKS_PER_CHUNK as N;
|
||||
let x = self.x.0 as usize;
|
||||
let z = self.z.0 as usize;
|
||||
N * z + x
|
||||
}
|
||||
}
|
||||
|
||||
/// Generic array for data stored per block of a chunk layer
|
||||
///
|
||||
/// Includes various convenient iteration functions.
|
||||
|
@ -102,10 +116,8 @@ impl SectionBlockCoords {
|
|||
/// block at a given coordinate is stored.
|
||||
pub fn offset(&self) -> usize {
|
||||
use BLOCKS_PER_CHUNK as N;
|
||||
let x = self.xz.x.0 as usize;
|
||||
let y = self.y.0 as usize;
|
||||
let z = self.xz.z.0 as usize;
|
||||
((y * N) + z) * N + x
|
||||
N * N * y + self.xz.offset()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue