Skip to content

Commit 2adab7f

Browse files
Refactor i32 to usize
1 parent 7598006 commit 2adab7f

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/client/terrain/util/chunk.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::prelude::*;
22

3-
pub const CHUNK_SIZE: i32 = 32;
4-
pub const PADDED_CHUNK_SIZE: i32 = CHUNK_SIZE + 2;
3+
pub const CHUNK_SIZE: usize = 32;
4+
pub const PADDED_CHUNK_SIZE: usize = CHUNK_SIZE + 2;
55
pub const PADDED_CHUNK_USIZE: usize = PADDED_CHUNK_SIZE as usize;
66
pub const CHUNK_LENGTH: usize =
77
(PADDED_CHUNK_SIZE * PADDED_CHUNK_SIZE * PADDED_CHUNK_SIZE) as usize;
@@ -20,11 +20,11 @@ impl Chunk {
2020
}
2121

2222
pub fn get(&self, x: usize, y: usize, z: usize) -> BlockId {
23-
self.data[Self::index(x + 1, y + 1, z + 1)]
23+
self.data[Self::index(x, y, z)]
2424
}
2525

2626
pub fn set(&mut self, x: usize, y: usize, z: usize, value: BlockId) {
27-
self.data[Self::index(x + 1, y + 1, z + 1)] = value;
27+
self.data[Self::index(x, y, z)] = value;
2828
}
2929

3030
#[rustfmt::skip]

src/client/terrain/util/generator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ impl Generator {
1919
return;
2020
}
2121

22-
for x in -1..=CHUNK_SIZE {
23-
for y in -1..=CHUNK_SIZE {
24-
for z in -1..=CHUNK_SIZE {
22+
for x in 0..=CHUNK_SIZE + 1 {
23+
for y in 0..=CHUNK_SIZE + 1 {
24+
for z in 0..=CHUNK_SIZE + 1 {
2525
let local_position = Vec3::new(x as f32, y as f32, z as f32);
2626
let block_position = chunk_origin + local_position;
2727
let block = self.generate_block(block_position);

src/client/terrain/util/mesher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ pub fn create_chunk_mesh(chunk: &Chunk, texture_manager: &TextureManager) -> Opt
8686
indices: Vec::new(),
8787
};
8888

89-
for x in 0..CHUNK_SIZE {
90-
for y in 0..CHUNK_SIZE {
91-
for z in 0..CHUNK_SIZE {
89+
for x in 1..CHUNK_SIZE - 1 {
90+
for y in 1..CHUNK_SIZE - 1 {
91+
for z in 1..CHUNK_SIZE - 1 {
9292
let block_id = chunk.get(x as usize, y as usize, z as usize);
9393

9494
if block_id == BlockId::Air {
9595
continue;
9696
}
9797

98-
fn update_mask(chunk: &Chunk, mask: &mut u8, value: u8, x: i32, y: i32, z: i32) {
98+
fn update_mask(chunk: &Chunk, mask: &mut u8, value: u8, x: usize, y: usize, z: usize) {
9999
if chunk.get(x as usize, y as usize, z as usize) == BlockId::Air {
100100
*mask |= value;
101101
}

0 commit comments

Comments
 (0)