chore(ppu): rename Pixel to Pixels

Since the Pixel struct represents 8 pixels in a 2BPP format, I felt like
the name of the type needed to represent this
This commit is contained in:
Rekai Nyangadzayi Musuka 2021-05-04 22:55:34 -05:00
parent 6b0bba48f9
commit b57df3d2a7
2 changed files with 11 additions and 9 deletions

View File

@ -6,7 +6,7 @@ use std::convert::TryInto;
use registers::{ use registers::{
BackgroundPalette, GrayShade, LCDControl, LCDStatus, ObjectFlags, ObjectPalette, BackgroundPalette, GrayShade, LCDControl, LCDStatus, ObjectFlags, ObjectPalette,
ObjectPaletteId, Pixel, PpuMode, RenderPriority, TileDataAddress, ObjectPaletteId, Pixels, PpuMode, RenderPriority, TileDataAddress,
}; };
mod registers; mod registers;
@ -246,19 +246,19 @@ impl Ppu {
.zip(maybe_high) .zip(maybe_high)
.expect("Low & High Bytes in TileBuilder were unexpectedly missing."); .expect("Low & High Bytes in TileBuilder were unexpectedly missing.");
let tbpp = Pixel::from_bytes(high, low); let tbpp = Pixels::from_bytes(high, low);
let palette = match attr.flags.palette() { let palette = match attr.flags.palette() {
ObjectPaletteId::Zero => self.monochrome.obj_palette_0, ObjectPaletteId::Zero => self.monochrome.obj_palette_0,
ObjectPaletteId::One => self.monochrome.obj_palette_1, ObjectPaletteId::One => self.monochrome.obj_palette_1,
}; };
let start = ((self.x_pos + 8) - attr.x) as usize; let end = Pixels::PIXEL_COUNT - self.fifo.object.len();
let end = start + (8 - self.fifo.object.len()); let start = Pixels::PIXEL_COUNT - end;
let x_flip = attr.flags.x_flip(); let x_flip = attr.flags.x_flip();
for i in start..end { for i in start..Pixels::PIXEL_COUNT {
let x = if x_flip { 7 - i } else { i }; let x = if x_flip { 7 - i } else { i };
let priority = attr.flags.priority(); let priority = attr.flags.priority();
@ -708,10 +708,10 @@ impl PixelFetcher {
.zip(maybe_high) .zip(maybe_high)
.expect("Low & High Bytes in TileBuilder were unexpectedly missing."); .expect("Low & High Bytes in TileBuilder were unexpectedly missing.");
let tbpp = Pixel::from_bytes(high, low); let tbpp = Pixels::from_bytes(high, low);
if fifo.background.is_empty() { if fifo.background.is_empty() {
for x in 0..8 { for x in 0..Pixels::PIXEL_COUNT {
let shade = palette.shade(tbpp.shade_id(x)); let shade = palette.shade(tbpp.shade_id(x));
let fifo_info = BackgroundFifoInfo { shade }; let fifo_info = BackgroundFifoInfo { shade };

View File

@ -303,9 +303,11 @@ impl From<ObjectPalette> for u8 {
} }
} }
pub struct Pixel(u8, u8); pub struct Pixels(u8, u8);
impl Pixels {
pub const PIXEL_COUNT: usize = 8;
impl Pixel {
pub fn from_bytes(higher: u8, lower: u8) -> Self { pub fn from_bytes(higher: u8, lower: u8) -> Self {
Self(higher, lower) Self(higher, lower)
} }