some getters and setters

This commit is contained in:
histausse 2021-05-15 21:31:41 +02:00
parent 50f94820a5
commit b9298c9c5e
Signed by: histausse
GPG key ID: 67486F107F62E9E9

View file

@ -52,6 +52,25 @@ impl Universe{
} }
count count
} }
fn regenerate_cells(&mut self) {
let size = (self.width * self.height) as usize;
self.cells = FixedBitSet::with_capacity(size);
for i in 0..size {
self.cells.set(i, false);
}
}
pub fn get_cells(&self) -> &FixedBitSet {
&self.cells
}
pub fn set_cells(&mut self, cells: &[(u32, u32)]) {
for (row, col) in cells.iter().cloned() {
let i = self.get_index(row, col);
self.cells.set(i, true);
}
}
} }
#[wasm_bindgen] #[wasm_bindgen]
@ -76,6 +95,16 @@ impl Universe {
self.cells = next; self.cells = next;
} }
pub fn set_width(&mut self, width: u32) {
self.width = width;
self.regenerate_cells();
}
pub fn set_height(&mut self, height: u32) {
self.height = height;
self.regenerate_cells();
}
pub fn new() -> Universe { pub fn new() -> Universe {
let width = 64; let width = 64;
let height = 64; let height = 64;