error is white (colour corrected for cgb) in release builds

This commit is contained in:
Alex Janka 2023-04-23 10:12:48 +10:00
parent 63818494b7
commit ba9a601874
3 changed files with 27 additions and 11 deletions

View file

@ -132,7 +132,7 @@ where
} else {
None
};
let buffer = vec![ColourInner::Error.rgb_bytes(None).into(); WIDTH * HEIGHT];
let buffer = vec![ColourInner::Error.rgb_bytes(None, false).into(); WIDTH * HEIGHT];
Self {
buffer,
@ -321,8 +321,9 @@ where
*e = true;
}
for x in 0..WIDTH {
self.buffer[(scanline as usize * WIDTH) + x] =
ColourInner::Error.rgb_bytes(None).into();
self.buffer[(scanline as usize * WIDTH) + x] = ColourInner::Error
.rgb_bytes(None, self.is_cgb_mode())
.into();
}
if self.lcdc.bg_window_enable {
self.render_scanline_bg(scanline);
@ -335,8 +336,9 @@ where
}
} else {
for x in 0..WIDTH {
self.buffer[(scanline as usize * WIDTH) + x] =
ColourInner::Error.rgb_bytes(None).into();
self.buffer[(scanline as usize * WIDTH) + x] = ColourInner::Error
.rgb_bytes(None, self.is_cgb_mode())
.into();
}
}
if self.lcdc.obj_enable {
@ -487,7 +489,8 @@ where
)
});
self.buffer[buffer_index] = colour.rgb_bytes(cgb_data).into();
self.buffer[buffer_index] =
colour.rgb_bytes(cgb_data, self.is_cgb_mode()).into();
}
}
}
@ -564,7 +567,8 @@ where
.as_ref()
.map(|v| (v.palettes.bg, attributes.palette));
self.buffer[(scanline as usize * WIDTH) + x] = colour.rgb_bytes(cgb_data).into();
self.buffer[(scanline as usize * WIDTH) + x] =
colour.rgb_bytes(cgb_data, self.is_cgb_mode()).into();
}
}

View file

@ -27,7 +27,7 @@ where
pub(super) fn new(window: R) -> Self {
Self {
sprite_buffer: vec![
ColourInner::Error.rgb_bytes(None).into();
ColourInner::Error.rgb_bytes(None, false).into();
TILE_WINDOW_WIDTH * TILE_WINDOW_HEIGHT
],
sprite_renderer: window,
@ -110,7 +110,7 @@ where
};
self.sprite_buffer[real_px_x + (real_px_y * TILE_WINDOW_WIDTH)] = colour
.rgb_bytes(cgb_data.map(|v| (v, attributes.palette)))
.rgb_bytes(cgb_data.map(|v| (v, attributes.palette)), is_cgb_mode)
.into();
}
}

View file

@ -138,7 +138,11 @@ fn rgb_from_bytes(bytes: u16) -> Colour {
}
impl ColourInner {
pub(super) fn rgb_bytes(&self, cgb_data: Option<(CgbPalette, u8)>) -> Colour {
pub(super) fn rgb_bytes(
&self,
cgb_data: Option<(CgbPalette, u8)>,
is_cgb_mode: bool,
) -> Colour {
if let Some((cgb_palette, pallete_num)) = cgb_data {
if *self == ColourInner::Error {
return Colour(0xFF, 0, 0);
@ -152,7 +156,15 @@ impl ColourInner {
ColourInner::One => Colour(0xAA, 0xAA, 0xAA),
ColourInner::Two => Colour(0x55, 0x55, 0x55),
ColourInner::Three => Colour(0x00, 0x00, 0x00),
ColourInner::Error => Colour(0xFF, 0x00, 0x00),
ColourInner::Error => {
if cfg!(debug_assertions) {
Colour(0xFF, 0x00, 0x00)
} else if is_cgb_mode {
rgb_from_bytes(0xFFFF)
} else {
Colour(0xFF, 0xFF, 0xFF)
}
}
}
}
}