Commit 0988fe2e authored by Astro's avatar Astro
Browse files

l0dable, rkanoid: update display coordinate types everywhere else

parent d2bca3b8
Pipeline #4120 passed with stage
in 9 minutes and 27 seconds
...@@ -86,10 +86,10 @@ pub enum Font { ...@@ -86,10 +86,10 @@ pub enum Font {
/// Immediate mode routines /// Immediate mode routines
impl Display { impl Display {
pub const W: u16 = 160; pub const W: i16 = 160;
pub const H: u16 = 80; pub const H: i16 = 80;
pub const FONT_W: u16 = 14; pub const FONT_W: i16 = 14;
pub const FONT_H: u16 = 20; pub const FONT_H: i16 = 20;
/// Open the display, return an instance /// Open the display, return an instance
pub fn open() -> Self { pub fn open() -> Self {
......
...@@ -61,16 +61,16 @@ impl<'d> FrameBuffer<'d> { ...@@ -61,16 +61,16 @@ impl<'d> FrameBuffer<'d> {
impl<'d> Index<(u16, u16)> for FrameBuffer<'d> { impl<'d> Index<(u16, u16)> for FrameBuffer<'d> {
type Output = RawColor; type Output = RawColor;
fn index(&self, (x, y): (u16, u16)) -> &Self::Output { fn index(&self, (x, y): (u16, u16)) -> &Self::Output {
let x = usize::from(Display::W - 1 - x); let x = usize::from(Display::W as u16 - 1 - x);
let y = usize::from(Display::H - 1 - y); let y = usize::from(Display::H as u16 - 1 - y);
unsafe { transmute(&self.buffer.fb[y][x]) } unsafe { transmute(&self.buffer.fb[y][x]) }
} }
} }
impl<'d> IndexMut<(u16, u16)> for FrameBuffer<'d> { impl<'d> IndexMut<(u16, u16)> for FrameBuffer<'d> {
fn index_mut(&mut self, (x, y): (u16, u16)) -> &mut Self::Output { fn index_mut(&mut self, (x, y): (u16, u16)) -> &mut Self::Output {
let x = usize::from(Display::W - 1 - x); let x = usize::from(Display::W as u16 - 1 - x);
let y = usize::from(Display::H - 1 - y); let y = usize::from(Display::H as u16 - 1 - y);
unsafe { transmute(&mut self.buffer.fb[y][x]) } unsafe { transmute(&mut self.buffer.fb[y][x]) }
} }
} }
...@@ -85,7 +85,7 @@ impl<'d, C: PixelColor + Into<RawColor>> Drawing<C> for FrameBuffer<'d> { ...@@ -85,7 +85,7 @@ impl<'d, C: PixelColor + Into<RawColor>> Drawing<C> for FrameBuffer<'d> {
let x = coord[0] as u16; let x = coord[0] as u16;
let y = coord[1] as u16; let y = coord[1] as u16;
if x >= Display::W || y >= Display::H { if x >= Display::W as u16 || y >= Display::H as u16 {
continue; continue;
} }
// Swap bytes // Swap bytes
......
...@@ -24,10 +24,10 @@ impl<'a, 'd, 'f> Write for TextRenderer<'a, 'd, 'f> { ...@@ -24,10 +24,10 @@ impl<'a, 'd, 'f> Write for TextRenderer<'a, 'd, 'f> {
Some(glyph) => { Some(glyph) => {
for y in 0..self.font.h { for y in 0..self.font.h {
let y1 = (self.y + y as isize) as u16; let y1 = (self.y + y as isize) as u16;
if y1 < Display::H { if y1 < Display::H as u16 {
for x in 0..self.font.w { for x in 0..self.font.w {
let x1 = (self.x + x as isize) as u16; let x1 = (self.x + x as isize) as u16;
if x1 < Display::W { if x1 < Display::W as u16 {
if glyph.get_pixel(x as usize, y as usize) { if glyph.get_pixel(x as usize, y as usize) {
self.framebuffer[(x1, y1)] = self.color; self.framebuffer[(x1, y1)] = self.color;
} }
......
...@@ -184,7 +184,7 @@ fn game(level: u16, mut score: u32) -> GameResult { ...@@ -184,7 +184,7 @@ fn game(level: u16, mut score: u32) -> GameResult {
let mut blocks = Blocks::generate((0x3F + 0x10 * level).min(0xff) as u8); let mut blocks = Blocks::generate((0x3F + 0x10 * level).min(0xff) as u8);
// Clear screen // Clear screen
draw_rect(&mut fb, 0, 0, Display::W - 1, Display::H - 1, RawColor::black()); draw_rect(&mut fb, 0, 0, Display::W as u16 - 1, Display::H as u16 - 1, RawColor::black());
// Draw Blocks // Draw Blocks
for (lineno, line) in blocks.blocks.iter_mut().enumerate() { for (lineno, line) in blocks.blocks.iter_mut().enumerate() {
let lineno = lineno as u32; let lineno = lineno as u32;
...@@ -299,11 +299,11 @@ fn game(level: u16, mut score: u32) -> GameResult { ...@@ -299,11 +299,11 @@ fn game(level: u16, mut score: u32) -> GameResult {
} }
// Space below blocks // Space below blocks
draw_rect(&mut fb, 0, (BLOCK_H * BLOCKS_Y) as u16, draw_rect(&mut fb, 0, (BLOCK_H * BLOCKS_Y) as u16,
Display::W, Display::H, RawColor::black()); Display::W as u16, Display::H as u16, RawColor::black());
// Paddle // Paddle
draw_rect(&mut fb, draw_rect(&mut fb,
(paddle - paddle_size) as u16, Display::H - PADDLE_HEIGHT as u16, (paddle - paddle_size) as u16, Display::H as u16 - PADDLE_HEIGHT as u16,
(paddle + paddle_size) as u16, Display::H - 1, (paddle + paddle_size) as u16, Display::H as u16 - 1,
RawColor::rgb8(0x7f, 0xff, 0x7f)); RawColor::rgb8(0x7f, 0xff, 0x7f));
// Ball // Ball
fb.draw( fb.draw(
...@@ -412,10 +412,10 @@ fn main() { ...@@ -412,10 +412,10 @@ fn main() {
} }
fn draw_rect(fb: &mut FrameBuffer, x1: u16, y1: u16, x2: u16, y2: u16, color: RawColor) { fn draw_rect(fb: &mut FrameBuffer, x1: u16, y1: u16, x2: u16, y2: u16, color: RawColor) {
let x1 = x1.max(0).min(Display::W - 1); let x1 = x1.max(0).min(Display::W as u16 - 1);
let x2 = x2.max(0).min(Display::W - 1); let x2 = x2.max(0).min(Display::W as u16 - 1);
let y1 = y1.max(0).min(Display::H - 1); let y1 = y1.max(0).min(Display::H as u16 - 1);
let y2 = y2.max(0).min(Display::H - 1); let y2 = y2.max(0).min(Display::H as u16 - 1);
for y in y1..=y2 { for y in y1..=y2 {
for x in x1..=x2 { for x in x1..=x2 {
fb[(x, y)] = color; fb[(x, y)] = color;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment