chore(ppu): reimplement object buffer remove

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-04-24 01:48:15 -05:00
parent 98af1865ee
commit e8f6a94fee
1 changed files with 13 additions and 0 deletions

View File

@ -205,6 +205,7 @@ impl Ppu {
self.fifo.pause(); self.fifo.pause();
obj_attr = Some(*attr); obj_attr = Some(*attr);
break;
} }
} }
} }
@ -286,6 +287,7 @@ impl Ppu {
self.fetcher.bg.resume(); self.fetcher.bg.resume();
self.fifo.resume(); self.fifo.resume();
self.obj_buffer.remove(&attr);
} }
} else if self.fetcher.obj.fifo_count == 2 { } else if self.fetcher.obj.fifo_count == 2 {
self.fetcher.obj.reset(); self.fetcher.obj.reset();
@ -1032,6 +1034,17 @@ impl ObjectBuffer {
pub fn get(&self, index: usize) -> Option<&ObjectAttribute> { pub fn get(&self, index: usize) -> Option<&ObjectAttribute> {
self.buf[index].as_ref() self.buf[index].as_ref()
} }
pub fn remove(&mut self, attr: &ObjectAttribute) {
let maybe_index = self.buf.iter().position(|maybe_attr| match maybe_attr {
Some(other_attr) => attr == other_attr,
None => false,
});
if let Some(i) = maybe_index {
self.buf[i] = None;
}
}
} }
impl Default for ObjectBuffer { impl Default for ObjectBuffer {