From d3c32ce35146e9be60720dca424905070496baf1 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Thu, 31 Aug 2023 07:53:01 +0100 Subject: [PATCH] Minor optimisation for the show entire screen case --- agb/src/display/tiled/map.rs | 45 +++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/agb/src/display/tiled/map.rs b/agb/src/display/tiled/map.rs index 48ca05f5..84a52d0b 100644 --- a/agb/src/display/tiled/map.rs +++ b/agb/src/display/tiled/map.rs @@ -195,14 +195,23 @@ impl RegularMap { "Don't have a full screen's worth of tile data" ); - for y in 0..20u16 { - for x in 0..30u16 { + assert_eq!( + tile_data.tiles.format(), + self.colours(), + "Cannot set a {:?} colour tile on a {:?} colour background", + tile_data.tiles.format(), + self.colours() + ); + + for y in 0..20 { + for x in 0..30 { let tile_id = y * 30 + x; - self.set_tile( + let tile_pos = y * 32 + x; + self.set_tile_at_pos( vram, - (x, y).into(), + tile_pos, &tile_data.tiles, - tile_data.tile_settings[tile_id as usize], + tile_data.tile_settings[tile_id], ); } } @@ -215,20 +224,28 @@ impl RegularMap { tileset: &TileSet<'_>, tile_setting: TileSetting, ) { - let colours = self.colours(); - if tileset.format() != colours { - panic!( - "Cannot set a {:?} colour tile on a {:?} colour background", - tileset.format(), - colours - ); - } + assert_eq!( + tileset.format(), + self.colours(), + "Cannot set a {:?} colour tile on a {:?} colour background", + tileset.format(), + self.colours() + ); let pos = self.map_size().gba_offset(pos); + self.set_tile_at_pos(vram, pos, tileset, tile_setting); + } + fn set_tile_at_pos( + &mut self, + vram: &mut VRamManager, + pos: usize, + tileset: &TileSet<'_>, + tile_setting: TileSetting, + ) { let old_tile = self.tiles_mut()[pos]; if old_tile != Tile::default() { - vram.remove_tile(old_tile.tile_index(colours)); + vram.remove_tile(old_tile.tile_index(self.colours())); } let tile_index = tile_setting.index();