chore(ppu): improve bg-sprite priority functionality
This commit is contained in:
parent
de8fe1a367
commit
4cfd951ede
52
src/ppu.rs
52
src/ppu.rs
|
@ -430,43 +430,39 @@ impl Ppu {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clock_fifo(&mut self) -> Option<GrayShade> {
|
fn clock_fifo(&mut self) -> Option<GrayShade> {
|
||||||
use ObjectPaletteKind::*;
|
|
||||||
use RenderPriority::*;
|
use RenderPriority::*;
|
||||||
|
|
||||||
let obj_palette_0 = &self.monochrome.obj_palette_0;
|
self.fifo
|
||||||
let obj_palette_1 = &self.monochrome.obj_palette_1;
|
.back
|
||||||
|
.pop_front()
|
||||||
match self.fifo.back.pop_front() {
|
.map(|bg| match self.fifo.obj.pop_front() {
|
||||||
Some(bg_pixel) => match self.fifo.obj.pop_front() {
|
Some(obj) => match obj.priority {
|
||||||
Some(obj_pixel) => match obj_pixel.priority {
|
_ if obj.shade_id == 0 => self.bg_pixel(bg),
|
||||||
Object | BackgroundAndWindow if obj_pixel.shade_id == 0 => {
|
BackgroundAndWindow if bg.shade_id != 0 => self.bg_pixel(bg),
|
||||||
Some(self.bg_pixel(bg_pixel.shade_id))
|
_ => self.obj_pixel(obj),
|
||||||
}
|
|
||||||
BackgroundAndWindow if bg_pixel.shade_id != 0 => {
|
|
||||||
Some(self.bg_pixel(bg_pixel.shade_id))
|
|
||||||
}
|
|
||||||
Object | BackgroundAndWindow => {
|
|
||||||
let maybe_sprite = match obj_pixel.palette_kind {
|
|
||||||
Zero => obj_palette_0.shade(obj_pixel.shade_id),
|
|
||||||
One => obj_palette_1.shade(obj_pixel.shade_id),
|
|
||||||
};
|
|
||||||
|
|
||||||
let sprite = maybe_sprite
|
|
||||||
.expect("Sprite w/ a colour id of 0 has already been handled");
|
|
||||||
Some(sprite)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_ => Some(self.bg_pixel(bg_pixel.shade_id)),
|
None => self.bg_pixel(bg),
|
||||||
},
|
})
|
||||||
None => None,
|
}
|
||||||
|
|
||||||
|
fn obj_pixel(&self, obj: ObjPixelProperty) -> GrayShade {
|
||||||
|
use ObjectPaletteKind::*;
|
||||||
|
assert!(obj.shade_id != 0);
|
||||||
|
|
||||||
|
let p0 = &self.monochrome.obj_palette_0;
|
||||||
|
let p1 = &self.monochrome.obj_palette_1;
|
||||||
|
|
||||||
|
match obj.palette_kind {
|
||||||
|
Zero => p0.shade(obj.shade_id).expect("Object shade id is non-zero"),
|
||||||
|
One => p1.shade(obj.shade_id).expect("Object shade id is non-zero"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bg_pixel(&self, shade_id: u8) -> GrayShade {
|
fn bg_pixel(&self, bg: BgPixelProperty) -> GrayShade {
|
||||||
let bg_palette = &self.monochrome.bg_palette;
|
let bg_palette = &self.monochrome.bg_palette;
|
||||||
|
|
||||||
if self.ctrl.bg_win_enabled() {
|
if self.ctrl.bg_win_enabled() {
|
||||||
bg_palette.shade(shade_id)
|
bg_palette.shade(bg.shade_id)
|
||||||
} else {
|
} else {
|
||||||
bg_palette.shade(0)
|
bg_palette.shade(0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue