mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Fix new clippy lints in tiled
This commit is contained in:
parent
f2e565f512
commit
1b393cd612
|
@ -24,6 +24,7 @@ pub enum PartialUpdateStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> InfiniteScrolledMap<'a> {
|
impl<'a> InfiniteScrolledMap<'a> {
|
||||||
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
map: MapLoan<'a, RegularMap>,
|
map: MapLoan<'a, RegularMap>,
|
||||||
tile: Box<dyn Fn(Vector2D<i32>) -> (&'a TileSet<'a>, TileSetting) + 'a>,
|
tile: Box<dyn Fn(Vector2D<i32>) -> (&'a TileSet<'a>, TileSetting) + 'a>,
|
||||||
|
@ -190,8 +191,8 @@ impl<'a> InfiniteScrolledMap<'a> {
|
||||||
|
|
||||||
let current_scroll = self.map.scroll_pos();
|
let current_scroll = self.map.scroll_pos();
|
||||||
let new_scroll = (
|
let new_scroll = (
|
||||||
size.px_offset_x(current_scroll.x as i32 + difference.x),
|
size.px_offset_x(i32::from(current_scroll.x) + difference.x),
|
||||||
size.px_offset_y(current_scroll.y as i32 + difference.y),
|
size.px_offset_y(i32::from(current_scroll.y) + difference.y),
|
||||||
)
|
)
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl RegularMap {
|
||||||
|
|
||||||
pub fn commit(&mut self, vram: &mut VRamManager) {
|
pub fn commit(&mut self, vram: &mut VRamManager) {
|
||||||
let new_bg_control_value = (self.priority as u16)
|
let new_bg_control_value = (self.priority as u16)
|
||||||
| ((self.screenblock as u16) << 8)
|
| (u16::from(self.screenblock) << 8)
|
||||||
| (self.size.size_flag() << 14);
|
| (self.size.size_flag() << 14);
|
||||||
|
|
||||||
self.bg_control_register().set(new_bg_control_value);
|
self.bg_control_register().set(new_bg_control_value);
|
||||||
|
@ -136,6 +136,7 @@ impl RegularMap {
|
||||||
self.y_scroll = pos.y;
|
self.y_scroll = pos.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn scroll_pos(&self) -> Vector2D<u16> {
|
pub fn scroll_pos(&self) -> Vector2D<u16> {
|
||||||
(self.x_scroll, self.y_scroll).into()
|
(self.x_scroll, self.y_scroll).into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,25 +18,23 @@ pub enum RegularBackgroundSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RegularBackgroundSize {
|
impl RegularBackgroundSize {
|
||||||
|
#[must_use]
|
||||||
pub fn width(&self) -> u32 {
|
pub fn width(&self) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
RegularBackgroundSize::Background32x32 => 32,
|
RegularBackgroundSize::Background32x64 | RegularBackgroundSize::Background32x32 => 32,
|
||||||
RegularBackgroundSize::Background64x32 => 64,
|
RegularBackgroundSize::Background64x64 | RegularBackgroundSize::Background64x32 => 64,
|
||||||
RegularBackgroundSize::Background32x64 => 32,
|
|
||||||
RegularBackgroundSize::Background64x64 => 64,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn height(&self) -> u32 {
|
pub fn height(&self) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
RegularBackgroundSize::Background32x32 => 32,
|
RegularBackgroundSize::Background32x32 | RegularBackgroundSize::Background64x32 => 32,
|
||||||
RegularBackgroundSize::Background64x32 => 32,
|
RegularBackgroundSize::Background32x64 | RegularBackgroundSize::Background64x64 => 64,
|
||||||
RegularBackgroundSize::Background32x64 => 64,
|
|
||||||
RegularBackgroundSize::Background64x64 => 64,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn size_flag(&self) -> u16 {
|
pub(crate) fn size_flag(self) -> u16 {
|
||||||
match self {
|
match self {
|
||||||
RegularBackgroundSize::Background32x32 => 0,
|
RegularBackgroundSize::Background32x32 => 0,
|
||||||
RegularBackgroundSize::Background64x32 => 1,
|
RegularBackgroundSize::Background64x32 => 1,
|
||||||
|
@ -45,17 +43,17 @@ impl RegularBackgroundSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn num_tiles(&self) -> usize {
|
pub(crate) fn num_tiles(self) -> usize {
|
||||||
(self.width() * self.height()) as usize
|
(self.width() * self.height()) as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn num_screen_blocks(&self) -> usize {
|
pub(crate) fn num_screen_blocks(self) -> usize {
|
||||||
self.num_tiles() / (32 * 32)
|
self.num_tiles() / (32 * 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is hilariously complicated due to how the GBA stores the background screenblocks.
|
// This is hilariously complicated due to how the GBA stores the background screenblocks.
|
||||||
// See https://www.coranac.com/tonc/text/regbg.htm#sec-map for an explanation
|
// See https://www.coranac.com/tonc/text/regbg.htm#sec-map for an explanation
|
||||||
pub(crate) fn gba_offset(&self, pos: Vector2D<u16>) -> usize {
|
pub(crate) fn gba_offset(self, pos: Vector2D<u16>) -> usize {
|
||||||
let x_mod = pos.x & (self.width() as u16 - 1);
|
let x_mod = pos.x & (self.width() as u16 - 1);
|
||||||
let y_mod = pos.y & (self.height() as u16 - 1);
|
let y_mod = pos.y & (self.height() as u16 - 1);
|
||||||
|
|
||||||
|
@ -66,19 +64,19 @@ impl RegularBackgroundSize {
|
||||||
pos as usize
|
pos as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tile_pos_x(&self, x: i32) -> u16 {
|
pub(crate) fn tile_pos_x(self, x: i32) -> u16 {
|
||||||
((x as u32) & (self.width() - 1)) as u16
|
((x as u32) & (self.width() - 1)) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tile_pos_y(&self, y: i32) -> u16 {
|
pub(crate) fn tile_pos_y(self, y: i32) -> u16 {
|
||||||
((y as u32) & (self.height() - 1)) as u16
|
((y as u32) & (self.height() - 1)) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn px_offset_x(&self, x: i32) -> u16 {
|
pub(crate) fn px_offset_x(self, x: i32) -> u16 {
|
||||||
((x as u32) & (self.width() * 8 - 1)) as u16
|
((x as u32) & (self.width() * 8 - 1)) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn px_offset_y(&self, y: i32) -> u16 {
|
pub(crate) fn px_offset_y(self, y: i32) -> u16 {
|
||||||
((y as u32) & (self.height() * 8 - 1)) as u16
|
((y as u32) & (self.height() * 8 - 1)) as u16
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,6 +99,7 @@ impl Tile {
|
||||||
pub struct TileSetting(u16);
|
pub struct TileSetting(u16);
|
||||||
|
|
||||||
impl TileSetting {
|
impl TileSetting {
|
||||||
|
#[must_use]
|
||||||
pub const fn new(tile_id: u16, hflip: bool, vflip: bool, palette_id: u8) -> Self {
|
pub const fn new(tile_id: u16, hflip: bool, vflip: bool, palette_id: u8) -> Self {
|
||||||
Self(
|
Self(
|
||||||
(tile_id & ((1 << 10) - 1))
|
(tile_id & ((1 << 10) - 1))
|
||||||
|
@ -110,6 +109,7 @@ impl TileSetting {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub const fn from_raw(raw: u16) -> Self {
|
pub const fn from_raw(raw: u16) -> Self {
|
||||||
Self(raw)
|
Self(raw)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ pub struct TileSet<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TileSet<'a> {
|
impl<'a> TileSet<'a> {
|
||||||
|
#[must_use]
|
||||||
pub fn new(tiles: &'a [u8], format: TileFormat) -> Self {
|
pub fn new(tiles: &'a [u8], format: TileFormat) -> Self {
|
||||||
Self { tiles, format }
|
Self { tiles, format }
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,7 @@ impl<'a> TileSet<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct TileIndex(u16);
|
pub struct TileIndex(u16);
|
||||||
|
|
||||||
impl TileIndex {
|
impl TileIndex {
|
||||||
|
@ -61,7 +62,7 @@ impl TileIndex {
|
||||||
Self(index as u16)
|
Self(index as u16)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) const fn index(&self) -> u16 {
|
pub(crate) const fn index(self) -> u16 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,8 +129,9 @@ pub struct DynamicTile<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DynamicTile<'_> {
|
impl DynamicTile<'_> {
|
||||||
|
#[must_use]
|
||||||
pub fn fill_with(self, colour_index: u8) -> Self {
|
pub fn fill_with(self, colour_index: u8) -> Self {
|
||||||
let colour_index = colour_index as u32;
|
let colour_index = u32::from(colour_index);
|
||||||
|
|
||||||
let mut value = 0;
|
let mut value = 0;
|
||||||
for i in 0..8 {
|
for i in 0..8 {
|
||||||
|
@ -142,6 +144,7 @@ impl DynamicTile<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DynamicTile<'_> {
|
impl DynamicTile<'_> {
|
||||||
|
#[must_use]
|
||||||
pub fn tile_set(&self) -> TileSet<'_> {
|
pub fn tile_set(&self) -> TileSet<'_> {
|
||||||
let tiles = unsafe {
|
let tiles = unsafe {
|
||||||
slice::from_raw_parts_mut(
|
slice::from_raw_parts_mut(
|
||||||
|
@ -153,6 +156,7 @@ impl DynamicTile<'_> {
|
||||||
TileSet::new(tiles, TileFormat::FourBpp)
|
TileSet::new(tiles, TileFormat::FourBpp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn tile_index(&self) -> u16 {
|
pub fn tile_index(&self) -> u16 {
|
||||||
let difference = self.tile_data.as_ptr() as usize - TILE_RAM_START;
|
let difference = self.tile_data.as_ptr() as usize - TILE_RAM_START;
|
||||||
(difference / (8 * 8 / 2)) as u16
|
(difference / (8 * 8 / 2)) as u16
|
||||||
|
@ -188,6 +192,7 @@ impl VRamManager {
|
||||||
TileReference(NonNull::new(ptr as *mut _).unwrap())
|
TileReference(NonNull::new(ptr as *mut _).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn new_dynamic_tile<'a>(&mut self) -> DynamicTile<'a> {
|
pub fn new_dynamic_tile<'a>(&mut self) -> DynamicTile<'a> {
|
||||||
let tile_format = TileFormat::FourBpp;
|
let tile_format = TileFormat::FourBpp;
|
||||||
let new_reference: NonNull<u32> =
|
let new_reference: NonNull<u32> =
|
||||||
|
@ -227,6 +232,8 @@ impl VRamManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This needs to take ownership of the dynamic tile because it will no longer be valid after this call
|
||||||
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
pub fn remove_dynamic_tile(&mut self, dynamic_tile: DynamicTile<'_>) {
|
pub fn remove_dynamic_tile(&mut self, dynamic_tile: DynamicTile<'_>) {
|
||||||
let pointer = NonNull::new(dynamic_tile.tile_data.as_mut_ptr() as *mut _).unwrap();
|
let pointer = NonNull::new(dynamic_tile.tile_data.as_mut_ptr() as *mut _).unwrap();
|
||||||
let tile_reference = TileReference(pointer);
|
let tile_reference = TileReference(pointer);
|
||||||
|
@ -336,7 +343,7 @@ impl VRamManager {
|
||||||
tile_slice.as_ptr() as *const u16,
|
tile_slice.as_ptr() as *const u16,
|
||||||
target_location,
|
target_location,
|
||||||
tile_size_in_half_words,
|
tile_size_in_half_words,
|
||||||
)
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,7 +363,7 @@ impl VRamManager {
|
||||||
/// Copies palettes to the background palettes without any checks.
|
/// Copies palettes to the background palettes without any checks.
|
||||||
pub fn set_background_palettes(&mut self, palettes: &[palette16::Palette16]) {
|
pub fn set_background_palettes(&mut self, palettes: &[palette16::Palette16]) {
|
||||||
for (palette_index, entry) in palettes.iter().enumerate() {
|
for (palette_index, entry) in palettes.iter().enumerate() {
|
||||||
self.set_background_palette(palette_index as u8, entry)
|
self.set_background_palette(palette_index as u8, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue