From e224e5ebef651d065e27d13992388ef508832049 Mon Sep 17 00:00:00 2001 From: nat Date: Sun, 8 Dec 2024 09:21:05 -0800 Subject: [PATCH] feat: implement reap and sow for direct land access --- src/bin/ponderosa-cpu.rs | 2 +- src/state.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin/ponderosa-cpu.rs b/src/bin/ponderosa-cpu.rs index b9e1017..d0e80e9 100644 --- a/src/bin/ponderosa-cpu.rs +++ b/src/bin/ponderosa-cpu.rs @@ -62,7 +62,7 @@ fn parse_rom(path: &String) -> io::Result<(state::Land, Vec, HashMa let x_pos = rom_words.pop_front().unwrap(); let y_pos = rom_words.pop_front().unwrap(); - land.map.insert((x_pos % land.width, y_pos % land.height), value); + land.sow(&(x_pos, y_pos), value); } println!("World\n====="); diff --git a/src/state.rs b/src/state.rs index 88b96c0..d6c5cf0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -83,6 +83,14 @@ impl Land { return self.semaphores.get_mut(position).unwrap(); } + + pub fn sow(&mut self, position: &(u16, u16), value: u16) { + self.map.insert((position.0 % self.width, position.1 % self.height), value); + } + + pub fn reap(&mut self, position: &(u16, u16)) -> u16 { + self.map.insert((position.0 % self.width, position.1 % self.height), 0).unwrap_or(0) + } } pub type Rule = VecDeque;