use crate::sim::cell::materials::MaterialId; #[derive(Clone, Copy)] pub struct Cell { pub material: MaterialId, pub flags: u8, pub data: u16, } impl Cell { const FLAG_PARITY: u8 = 0b0000_0001; const FLAG_RB: u8 = 0b0000_0010; #[inline] pub fn parity(self) -> u8 { self.flags & Self::FLAG_PARITY } #[inline] pub fn flip_parity(&mut self) { self.flags ^= Self::FLAG_PARITY; } #[inline] pub fn match_parity(&mut self, seqno: u64) { let parity = seqno % 2 != 0; if parity { self.flags |= Self::FLAG_PARITY; } else { self.flags = self.flags & !Self::FLAG_PARITY } } #[inline] pub fn rb(self) -> bool { (self.flags & Self::FLAG_RB) == Self::FLAG_RB } pub fn set_rb(&mut self, rb: bool) { if rb { self.flags |= Self::FLAG_RB } else { self.flags = self.flags & !Self::FLAG_RB } } } impl Cell { pub fn void() -> Cell { Cell { material: MaterialId::Void, flags: 0, data: 0, } } pub fn from_material(material: MaterialId) -> Cell { Cell { material, flags: 0, data: 0, } } }