mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-04-20 03:25:09 +02:00
types: make CHUNKS_PER_REGION and BLOCKS_PER_CHUNK usize
Having these as usize is more convenient.
This commit is contained in:
parent
b918ff6106
commit
65c39ea153
2 changed files with 11 additions and 8 deletions
16
src/types.rs
16
src/types.rs
|
@ -5,7 +5,7 @@ use std::{
|
|||
|
||||
use itertools::iproduct;
|
||||
|
||||
pub const BLOCKS_PER_CHUNK: u8 = 16;
|
||||
pub const BLOCKS_PER_CHUNK: usize = 16;
|
||||
|
||||
/// A block X coordinate relative to a chunk
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
@ -28,7 +28,7 @@ pub struct BlockCoords {
|
|||
|
||||
impl BlockCoords {
|
||||
pub fn offset(&self) -> usize {
|
||||
const N: usize = BLOCKS_PER_CHUNK as usize;
|
||||
use BLOCKS_PER_CHUNK as N;
|
||||
let x = self.x.0 as usize;
|
||||
let y = self.y.0 as usize;
|
||||
let z = self.z.0 as usize;
|
||||
|
@ -46,7 +46,7 @@ impl Debug for BlockCoords {
|
|||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct SectionY(pub i32);
|
||||
|
||||
pub const CHUNKS_PER_REGION: u8 = 32;
|
||||
pub const CHUNKS_PER_REGION: usize = 32;
|
||||
|
||||
/// A chunk X coordinate relative to a region
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
@ -70,13 +70,15 @@ impl Debug for ChunkCoords {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct ChunkArray<T>(pub [[T; CHUNKS_PER_REGION as usize]; CHUNKS_PER_REGION as usize]);
|
||||
pub struct ChunkArray<T>(pub [[T; CHUNKS_PER_REGION]; CHUNKS_PER_REGION]);
|
||||
|
||||
impl<T> ChunkArray<T> {
|
||||
pub fn keys() -> impl Iterator<Item = ChunkCoords> {
|
||||
iproduct!(0..CHUNKS_PER_REGION, 0..CHUNKS_PER_REGION).map(|(z, x)| ChunkCoords {
|
||||
x: ChunkX(x),
|
||||
z: ChunkZ(z),
|
||||
iproduct!(0..(CHUNKS_PER_REGION as u8), 0..(CHUNKS_PER_REGION as u8)).map(|(z, x)| {
|
||||
ChunkCoords {
|
||||
x: ChunkX(x),
|
||||
z: ChunkZ(z),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,8 @@ pub struct OldSection<'a> {
|
|||
|
||||
impl<'a> OldSection<'a> {
|
||||
pub fn new(blocks: &'a fastnbt::ByteArray, data: &'a fastnbt::ByteArray) -> Result<Self> {
|
||||
const N: usize = BLOCKS_PER_CHUNK as usize;
|
||||
use BLOCKS_PER_CHUNK as N;
|
||||
|
||||
if blocks.len() != N * N * N {
|
||||
bail!("Invalid section block data");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue