Add a convienence fill_with method

This commit is contained in:
Gwilym Inzani 2023-08-30 16:22:55 +01:00
parent f0ddfc96b4
commit 3a1f8ed8ed
2 changed files with 21 additions and 14 deletions

View file

@ -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();

View file

@ -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,