From 9e8318cdf9c77f68bfcdb79818635bc71d457763 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 27 Mar 2022 21:38:12 +0100 Subject: [PATCH] Rearrange methods to make a bit more sense --- agb/src/display/tiled/vram_manager.rs | 96 +++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/agb/src/display/tiled/vram_manager.rs b/agb/src/display/tiled/vram_manager.rs index 41c85b06..3b4aa57a 100644 --- a/agb/src/display/tiled/vram_manager.rs +++ b/agb/src/display/tiled/vram_manager.rs @@ -177,54 +177,6 @@ impl<'a> VRamManager<'a> { TileReference(NonNull::new(ptr as *mut _).unwrap()) } - fn copy_tile_to_location( - &self, - tile_set_ref: TileSetReference, - tile_id: u16, - tile_reference: TileReference, - ) { - let tile_slice = if let ArenaStorageItem::Data(data, generation) = - &self.tilesets[tile_set_ref.id as usize] - { - debug_assert_eq!( - *generation, tile_set_ref.generation, - "Stale tile data requested" - ); - - let tile_offset = (tile_id as usize) * data.format.tile_size(); - &data.tiles[tile_offset..(tile_offset + data.format.tile_size())] - } else { - panic!("Target tile set ref must point to an existing tile set reference") - }; - - let tile_size_in_half_words = tile_slice.len() / 2; - - let target_location = tile_reference.0.as_ptr() as *mut _; - - unsafe { - dma_copy16( - tile_slice.as_ptr() as *const u16, - target_location, - tile_size_in_half_words, - ) - }; - } - - pub fn replace_tile( - &mut self, - source_tile_set_ref: TileSetReference, - source_tile: u16, - target_tile_set_ref: TileSetReference, - target_tile: u16, - ) { - if let Some(&reference) = self - .tile_set_to_vram - .get(&(source_tile_set_ref.id, source_tile)) - { - self.copy_tile_to_location(target_tile_set_ref, target_tile, reference); - } - } - pub(crate) fn add_tile(&mut self, tile_set_ref: TileSetReference, tile: u16) -> TileIndex { let reference = self.tile_set_to_vram.get(&(tile_set_ref.id, tile)); @@ -277,6 +229,54 @@ impl<'a> VRamManager<'a> { self.reference_counts[index].1 = None; } + pub fn replace_tile( + &mut self, + source_tile_set_ref: TileSetReference, + source_tile: u16, + target_tile_set_ref: TileSetReference, + target_tile: u16, + ) { + if let Some(&reference) = self + .tile_set_to_vram + .get(&(source_tile_set_ref.id, source_tile)) + { + self.copy_tile_to_location(target_tile_set_ref, target_tile, reference); + } + } + + fn copy_tile_to_location( + &self, + tile_set_ref: TileSetReference, + tile_id: u16, + tile_reference: TileReference, + ) { + let tile_slice = if let ArenaStorageItem::Data(data, generation) = + &self.tilesets[tile_set_ref.id as usize] + { + debug_assert_eq!( + *generation, tile_set_ref.generation, + "Stale tile data requested" + ); + + let tile_offset = (tile_id as usize) * data.format.tile_size(); + &data.tiles[tile_offset..(tile_offset + data.format.tile_size())] + } else { + panic!("Target tile set ref must point to an existing tile set reference") + }; + + let tile_size_in_half_words = tile_slice.len() / 2; + + let target_location = tile_reference.0.as_ptr() as *mut _; + + unsafe { + dma_copy16( + tile_slice.as_ptr() as *const u16, + target_location, + tile_size_in_half_words, + ) + }; + } + /// Copies raw palettes to the background palette without any checks. pub fn set_background_palette_raw(&mut self, palette: &[u16]) { unsafe {