summaryrefslogtreecommitdiff
path: root/src/sim/chunk.rs
blob: 154cf82f5ca16d40753e4c95259c0594bc0d3709 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::{
    config::{CELLS_IN_CHUNK, CHUNK_SIZE},
    sim::cell::Cell,
};

pub struct Chunk {
    pub cells: Box<[Cell; CELLS_IN_CHUNK as usize]>,
}

impl Chunk {
    #[inline]
    pub fn get_cell_at_local_position(&self, x: u8, y: u8) -> Cell {
        self.cells[x as usize + y as usize * CHUNK_SIZE as usize]
    }
    #[inline]
    pub fn set_cell_at_local_position(&mut self, x: u8, y: u8, cell: Cell) {
        self.cells[x as usize + y as usize * CHUNK_SIZE as usize] = cell;
    }

    pub fn void() -> Self {
        Chunk {
            cells: Box::new([Cell::void(); CELLS_IN_CHUNK]),
        }
    }
}