From 552cfd4a18025c66e5a96d113c1720dfe9c9477c Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 20 Oct 2021 17:36:38 -0300 Subject: [PATCH] chore(ppu): sort OAM Memory --- src/ppu.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ppu.rs b/src/ppu.rs index a00b536..e50b0fe 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -88,6 +88,17 @@ impl Ppu { self.fifo.back.clear(); self.fifo.obj.clear(); + // Sort Sprites + self.obj_buffer.inner.sort_by(|left, right| { + left.zip(*right) + .map(|(left, right)| right.x.cmp(&left.x)) + .unwrap_or(std::cmp::Ordering::Greater) + }); + + // if self.obj_buffer.len != 0 { + // dbg!(&self.obj_buffer); + // } + self.stat.set_mode(PpuMode::Drawing); } @@ -578,7 +589,7 @@ impl Default for ObjectAttributeTable { } } -#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, Default)] struct ObjectAttribute { y: u8, x: u8,