Origin cleanup

This commit is contained in:
Kevin Hamacher 2020-02-21 10:19:21 +01:00
parent 30efdc1108
commit 8dd14c7719

View File

@ -144,7 +144,7 @@ impl BgMapAttributes {
#[derive(Debug, Copy, Clone)]
enum PixelOrigin {
Empty,
Background,
Background(usize),
Window,
Sprite,
}
@ -655,7 +655,8 @@ impl Display {
// Do not draw if the sprite should be drawn in the background
if !sprite.is_foreground() {
match pixel_origin {
PixelOrigin::Background | PixelOrigin::Window => continue,
PixelOrigin::Background(0) => {},
PixelOrigin::Window | PixelOrigin::Background(_) => continue,
_ => {}
}
}
@ -665,42 +666,17 @@ impl Display {
b2 = (tile_line_2 & 1 << (7 - x_o)) > 0;
// Sprites may be transparent.
if !b1 && !b2 {
if !b1 && !b2 && sprite.is_foreground() {
continue;
}
// GB
/*
let c = (b1 as u8) * 2 + b2 as u8;
let lookup: [u8; 4] = match sprite.palette() {
0 => [
self.object_palette[0] & 3,
(self.object_palette[0] >> 2) & 3,
(self.object_palette[0] >> 4) & 3,
(self.object_palette[0] >> 6) & 3,
],
1 => [
self.object_palette[1] & 3,
(self.object_palette[1] >> 2) & 3,
(self.object_palette[1] >> 4) & 3,
(self.object_palette[1] >> 6) & 3,
],
_ => unreachable!(),
};
let entry = MONOCHROME_PALETTE[lookup[c as usize] as usize];
// Draw stuff. We're currently only in monochrome mode
self.set_pixel(
x.wrapping_add(x_o),
render_y,
sdl2::pixels::Color::RGB(entry[0], entry[1], entry[2]),
PixelOrigin::Sprite,
);
*/
let c = ((b2 as u8) * 2 + b1 as u8) as usize;
if c == 0 {
continue;
}
// DMG:
// let c = self.object_palette[sprite.palette() as usize].get_color(c);
// GBC:
let c = self.object_palette_cgb[sprite.palette() as usize].get_color(c);
self.set_pixel(
x.wrapping_add(x_maybe_flipped),
@ -828,10 +804,7 @@ impl Display {
// Lookup the color
let c = ((b2 as u8) * 2 + b1 as u8) as usize;
let origin = match c {
0 => PixelOrigin::Empty, // Hack so that objects will be in front of it.
_ => PixelOrigin::Background,
};
let origin = PixelOrigin::Background(c);
let c = self.background_palette_cgb[bg_attribs.palette_number()].get_color(c);
self.set_pixel(render_x, render_y, c, origin);
/*
@ -921,10 +894,13 @@ impl Display {
let b2: bool = (tile_line_2 & 1 << (7 - tile_offset_x)) > 0;
let c = (b2 as u8) * 2 + b1 as u8;
/*
let origin = match c {
0 => PixelOrigin::Empty, // Hack so that objects will be in front of it.
_ => PixelOrigin::Window,
};
*/
let origin = PixelOrigin::Window;
let c = self.background_palette_cgb[bg_attribs.palette_number()]
.get_color(c as usize);
self.set_pixel(render_x, render_y, c, origin);