Fix some more linter errors

This commit is contained in:
Gwilym Kuiper 2022-06-11 20:48:18 +01:00
parent 1b393cd612
commit 062e8c8881
6 changed files with 51 additions and 31 deletions

View file

@ -24,6 +24,6 @@ impl Bitmap3 {
pub fn draw_point(&mut self, x: i32, y: i32, colour: u16) {
let x = x.try_into().unwrap();
let y = y.try_into().unwrap();
BITMAP_MODE_3.set(x, y, colour)
BITMAP_MODE_3.set(x, y, colour);
}
}

View file

@ -18,6 +18,7 @@ const BITMAP_PAGE_BACK_MODE_4: MemoryMapped2DArray<
const PALETTE_BACKGROUND: MemoryMapped1DArray<u16, 256> =
unsafe { MemoryMapped1DArray::new(0x0500_0000) };
#[derive(Clone, Copy)]
pub enum Page {
Front = 0,
Back = 1,
@ -47,9 +48,9 @@ impl Bitmap4 {
let c = addr.get(x_in_screen, y_in_screen);
if x & 0b1 != 0 {
addr.set(x_in_screen, y_in_screen, c | (colour as u16) << 8);
addr.set(x_in_screen, y_in_screen, c | u16::from(colour) << 8);
} else {
addr.set(x_in_screen, y_in_screen, c | colour as u16);
addr.set(x_in_screen, y_in_screen, c | u16::from(colour));
}
}
@ -66,7 +67,7 @@ impl Bitmap4 {
Page::Back
};
self.draw_point_page(x, y, colour, page)
self.draw_point_page(x, y, colour, page);
}
/// Sets the colour of colour index in the background palette.

View file

@ -15,6 +15,7 @@ pub struct FontLetter {
}
impl FontLetter {
#[must_use]
pub const fn new(
width: u8,
height: u8,
@ -41,6 +42,7 @@ pub struct Font {
}
impl Font {
#[must_use]
pub const fn new(letters: &'static [FontLetter], line_height: i32, ascent: i32) -> Self {
Self {
letters,
@ -102,7 +104,7 @@ impl<'a> Write for TextRenderer<'a> {
self.render_letter(letter);
self.current_x_pos += letter.advance_width as i32;
self.current_x_pos += i32::from(letter.advance_width);
}
Ok(())
@ -119,9 +121,10 @@ impl<'a> TextRenderer<'a> {
let foreground_colour = self.foreground_colour;
let background_colour = self.background_colour;
let x_start = (self.current_x_pos + letter.xmin as i32).max(0);
let y_start =
self.current_y_pos + self.font.ascent - letter.height as i32 - letter.ymin as i32;
let x_start = (self.current_x_pos + i32::from(letter.xmin)).max(0);
let y_start = self.current_y_pos + self.font.ascent
- i32::from(letter.height)
- i32::from(letter.ymin);
let x_tile_start = x_start / 8;
let y_tile_start = y_start / 8;
@ -129,20 +132,20 @@ impl<'a> TextRenderer<'a> {
let letter_offset_x = x_start.rem_euclid(8);
let letter_offset_y = y_start.rem_euclid(8);
let x_tiles = div_ceil(letter.width as i32 + letter_offset_x, 8);
let y_tiles = div_ceil(letter.height as i32 + letter_offset_y, 8);
let x_tiles = div_ceil(i32::from(letter.width) + letter_offset_x, 8);
let y_tiles = div_ceil(i32::from(letter.height) + letter_offset_y, 8);
for letter_y_tile in 0..(y_tiles + 1) {
let letter_y_start = 0.max(letter_offset_y - 8 * letter_y_tile) + 8 * letter_y_tile;
let letter_y_end =
(letter_offset_y + letter.height as i32).min((letter_y_tile + 1) * 8);
(letter_offset_y + i32::from(letter.height)).min((letter_y_tile + 1) * 8);
let tile_y = y_tile_start + letter_y_tile;
for letter_x_tile in 0..(x_tiles + 1) {
let letter_x_start = 0.max(letter_offset_x - 8 * letter_x_tile) + 8 * letter_x_tile;
let letter_x_end =
(letter_offset_x + letter.width as i32).min((letter_x_tile + 1) * 8);
(letter_offset_x + i32::from(letter.width)).min((letter_x_tile + 1) * 8);
let tile_x = x_tile_start + letter_x_tile;
@ -154,13 +157,13 @@ impl<'a> TextRenderer<'a> {
for letter_x in letter_x_start..letter_x_end {
let x = letter_x - letter_offset_x;
let pos = x + y * letter.width as i32;
let pos = x + y * i32::from(letter.width);
let px_line = letter.data[(pos / 8) as usize];
let px = (px_line >> (pos & 7)) & 1;
if px != 0 {
masks[(letter_y & 7) as usize] |=
(foreground_colour as u32) << ((letter_x & 7) * 4);
u32::from(foreground_colour) << ((letter_x & 7) * 4);
zero = false;
}
}

View file

@ -29,7 +29,7 @@ unsafe fn init_object_controller() {
}
unsafe fn uninit_object_controller() {
OBJECT_CONTROLLER.assume_init_drop()
OBJECT_CONTROLLER.assume_init_drop();
}
struct ObjectControllerRef {}
@ -78,10 +78,12 @@ impl Drop for ObjectControllerRef {
crate::interrupt::free(|c| {
let mut b = OBJECT_REFS_CURRENT.borrow(c).borrow_mut();
*b -= 1;
})
});
}
}
// Required for safety reasons
#[allow(clippy::trivially_copy_pass_by_ref)]
unsafe fn get_object_controller(_r: &ObjectControllerReference) -> ObjectControllerRef {
ObjectControllerRef::new()
}
@ -153,12 +155,15 @@ pub struct Graphics {
}
impl Graphics {
#[must_use]
pub const fn new(sprites: &'static [Sprite], tag_map: &'static TagMap) -> Self {
Self { sprites, tag_map }
}
#[must_use]
pub const fn tags(&self) -> &TagMap {
self.tag_map
}
#[must_use]
pub const fn sprites(&self) -> &[Sprite] {
self.sprites
}
@ -184,9 +189,11 @@ const fn const_byte_compare(a: &[u8], b: &[u8]) -> bool {
}
impl TagMap {
#[must_use]
pub const fn new(tags: &'static [(&'static str, Tag)]) -> TagMap {
Self { tags }
}
#[must_use]
pub const fn try_get(&'static self, tag: &str) -> Option<&'static Tag> {
let mut i = 0;
while i < self.tags.len() {
@ -200,6 +207,7 @@ impl TagMap {
None
}
#[must_use]
pub const fn get(&'static self, tag: &str) -> &'static Tag {
let t = self.try_get(tag);
match t {
@ -237,15 +245,18 @@ pub struct Tag {
}
impl Tag {
#[must_use]
pub fn sprites(&self) -> &'static [Sprite] {
unsafe { slice::from_raw_parts(self.sprites, self.len) }
}
#[must_use]
pub fn sprite(&self, idx: usize) -> &'static Sprite {
&self.sprites()[idx]
}
#[inline]
#[must_use]
pub fn animation_sprite(&self, idx: usize) -> &'static Sprite {
let len_sub_1 = self.len - 1;
match self.direction {
@ -259,6 +270,7 @@ impl Tag {
}
#[doc(hidden)]
#[must_use]
pub const fn new(sprites: &'static [Sprite], from: usize, to: usize, direction: usize) -> Self {
assert!(from <= to);
assert!(to < sprites.len());
@ -291,6 +303,7 @@ impl Size {
(self as u8 >> 2, self as u8 & 0b11)
}
#[must_use]
pub const fn from_width_height(width: usize, height: usize) -> Self {
match (width, height) {
(8, 8) => Size::S8x8,
@ -309,6 +322,7 @@ impl Size {
}
}
#[must_use]
pub const fn to_width_height(self) -> (usize, usize) {
match self {
Size::S8x8 => (8, 8),
@ -353,10 +367,10 @@ impl Storage {
count: 1,
}
}
fn as_palette_ptr(&self) -> *mut u8 {
fn as_palette_ptr(self) -> *mut u8 {
(self.location as usize * Palette16::layout().size() + PALETTE_SPRITE) as *mut u8
}
fn as_sprite_ptr(&self) -> *mut u8 {
fn as_sprite_ptr(self) -> *mut u8 {
(self.location as usize * BYTES_PER_TILE_4BPP + TILE_SPRITE) as *mut u8
}
}
@ -427,7 +441,7 @@ impl Drop for Loan<'_> {
s.shadow_oam[self.index as usize]
.as_mut()
.unwrap_unchecked()
.destroy = true
.destroy = true;
};
}
}
@ -461,12 +475,8 @@ impl ObjectControllerStatic {
fn update_z_ordering(&mut self) {
let shadow_oam = &self.shadow_oam;
self.z_order.sort_by_key(|&a| {
shadow_oam[a as usize]
.as_ref()
.map(|s| s.z)
.unwrap_or(i32::MAX)
});
self.z_order
.sort_by_key(|&a| shadow_oam[a as usize].as_ref().map_or(i32::MAX, |s| s.z));
}
}
@ -498,7 +508,7 @@ impl ObjectController {
unsafe {
(OBJECT_ATTRIBUTE_MEMORY as *mut u16)
.add((i as usize) * 4)
.write_volatile(HIDDEN_VALUE)
.write_volatile(HIDDEN_VALUE);
}
let a = unsafe { s.shadow_oam[z as usize].take().unwrap_unchecked() };
@ -515,7 +525,7 @@ impl ObjectController {
unsafe {
(OBJECT_ATTRIBUTE_MEMORY as *mut u16)
.add(i * 4)
.write_volatile(HIDDEN_VALUE)
.write_volatile(HIDDEN_VALUE);
}
}
}
@ -530,7 +540,7 @@ impl ObjectController {
unsafe {
(OBJECT_ATTRIBUTE_MEMORY as *mut u16)
.add(i * 4)
.write_volatile(HIDDEN_VALUE)
.write_volatile(HIDDEN_VALUE);
}
}
@ -540,10 +550,12 @@ impl ObjectController {
}
}
#[must_use]
pub fn object<'a>(&'a self, sprite: SpriteBorrow<'a>) -> Object<'a> {
self.try_get_object(sprite).expect("No object available")
}
#[must_use]
pub fn try_get_object<'a>(&'a self, sprite: SpriteBorrow<'a>) -> Option<Object<'a>> {
let mut s = unsafe { get_object_controller(&self.phantom) };
@ -578,11 +590,13 @@ impl ObjectController {
Some(Object { loan })
}
#[must_use]
pub fn sprite(&self, sprite: &'static Sprite) -> SpriteBorrow {
self.try_get_sprite(sprite)
.expect("No slot for sprite available")
}
#[must_use]
pub fn try_get_sprite(&self, sprite: &'static Sprite) -> Option<SpriteBorrow> {
let s = unsafe { get_object_controller(&self.phantom) };
unsafe {
@ -721,6 +735,7 @@ impl Sprite {
fn layout(&self) -> Layout {
Layout::from_size_align(self.size.number_of_tiles() * BYTES_PER_TILE_4BPP, 8).unwrap()
}
#[must_use]
pub const fn new(palette: &'static Palette16, data: &'static [u8], size: Size) -> Self {
Self {
palette,
@ -728,6 +743,7 @@ impl Sprite {
size,
}
}
#[must_use]
pub const fn size(&self) -> Size {
self.size
}
@ -823,7 +839,7 @@ impl SpriteControllerInner {
}
}
self.return_palette(sprite.palette)
self.return_palette(sprite.palette);
}
fn return_palette(&mut self, palette: &'static Palette16) {
@ -843,7 +859,7 @@ impl SpriteControllerInner {
impl<'a> Drop for SpriteBorrow<'a> {
fn drop(&mut self) {
let mut s = unsafe { get_object_controller(&self.phantom) };
s.sprite_controller.return_sprite(self.id.sprite())
s.sprite_controller.return_sprite(self.id.sprite());
}
}

View file

@ -7,6 +7,7 @@ pub struct TileData {
}
impl TileData {
#[must_use]
pub const fn new(
palettes: &'static [Palette16],
tiles: &'static [u8],

View file

@ -9,7 +9,6 @@
#![warn(clippy::must_use_candidate)]
#![warn(clippy::trivially_copy_pass_by_ref)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![warn(clippy::match_same_arms)]
#![warn(clippy::cast_lossless)]
#![warn(clippy::map_unwrap_or)]
#![warn(clippy::needless_pass_by_value)]