From 3a1f8ed8ed08216efadc11d60379fec9883b86cd Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 30 Aug 2023 16:22:55 +0100 Subject: [PATCH] Add a convienence fill_with method --- agb/src/display/example_logo.rs | 15 +-------------- agb/src/display/tiled/map.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/agb/src/display/example_logo.rs b/agb/src/display/example_logo.rs index e7374789..ba92c2ad 100644 --- a/agb/src/display/example_logo.rs +++ b/agb/src/display/example_logo.rs @@ -5,20 +5,7 @@ crate::include_background_gfx!(crate, agb_logo, test_logo => deduplicate "gfx/te pub fn display_logo(map: &mut RegularMap, vram: &mut VRamManager) { vram.set_background_palettes(agb_logo::PALETTES); - let background_tilemap = agb_logo::test_logo.tiles; - - for y in 0..20 { - for x in 0..30 { - let tile_id = y * 30 + x; - - map.set_tile( - vram, - (x as u16, y as u16).into(), - &background_tilemap, - agb_logo::test_logo.tile_settings[tile_id], - ); - } - } + map.fill_with(vram, &agb_logo::test_logo); map.commit(vram); map.show(); diff --git a/agb/src/display/tiled/map.rs b/agb/src/display/tiled/map.rs index b2a83013..48ca05f5 100644 --- a/agb/src/display/tiled/map.rs +++ b/agb/src/display/tiled/map.rs @@ -3,6 +3,7 @@ use core::ops::{Deref, DerefMut}; use crate::bitarray::Bitarray; use crate::display::affine::AffineMatrixBackground; +use crate::display::tile_data::TileData; use crate::display::{Priority, DISPLAY_CONTROL}; use crate::dma::dma_copy16; use crate::fixnum::Vector2D; @@ -188,6 +189,25 @@ impl RegularMap { } } + pub fn fill_with(&mut self, vram: &mut VRamManager, tile_data: &TileData) { + assert!( + tile_data.tile_settings.len() >= 20 * 30, + "Don't have a full screen's worth of tile data" + ); + + for y in 0..20u16 { + for x in 0..30u16 { + let tile_id = y * 30 + x; + self.set_tile( + vram, + (x, y).into(), + &tile_data.tiles, + tile_data.tile_settings[tile_id as usize], + ); + } + } + } + pub fn set_tile( &mut self, vram: &mut VRamManager,