diff --git a/agb/src/display/tiled/infinite_scrolled_map.rs b/agb/src/display/tiled/infinite_scrolled_map.rs index 56a4cfde..e50d184e 100644 --- a/agb/src/display/tiled/infinite_scrolled_map.rs +++ b/agb/src/display/tiled/infinite_scrolled_map.rs @@ -9,7 +9,7 @@ use crate::{ pub struct InfiniteScrolledMap<'a> { map: MapLoan<'a, RegularMap>, - tile: Box) -> (&'a TileSet<'a>, TileSetting)>, + tile: Box) -> (&'a TileSet<'a>, TileSetting) + 'a>, current_pos: Vector2D, offset: Vector2D, @@ -26,7 +26,7 @@ pub enum PartialUpdateStatus { impl<'a> InfiniteScrolledMap<'a> { pub fn new( map: MapLoan<'a, RegularMap>, - tile: Box) -> (&'a TileSet<'a>, TileSetting)>, + tile: Box) -> (&'a TileSet<'a>, TileSetting) + 'a>, ) -> Self { Self { map, diff --git a/examples/the-hat-chooses-the-wizard/src/level_display.rs b/examples/the-hat-chooses-the-wizard/src/level_display.rs index 867a5244..4019ad55 100644 --- a/examples/the-hat-chooses-the-wizard/src/level_display.rs +++ b/examples/the-hat-chooses-the-wizard/src/level_display.rs @@ -1,5 +1,5 @@ use agb::display::{ - tiled::{RegularMap, TileSetReference, TileSetting, VRamManager}, + tiled::{RegularMap, TileSet, TileSetting, VRamManager}, HEIGHT, WIDTH, }; @@ -12,7 +12,7 @@ pub fn write_level( map: &mut RegularMap, world: u32, level: u32, - tile_set_ref: TileSetReference, + tileset: &'_ TileSet<'_>, vram: &mut VRamManager, ) { for (i, &tile) in [ @@ -30,7 +30,7 @@ pub fn write_level( map.set_tile( vram, (i as u16, 0).into(), - tile_set_ref, + &tileset, TileSetting::from_raw(tile), ); } diff --git a/examples/the-hat-chooses-the-wizard/src/main.rs b/examples/the-hat-chooses-the-wizard/src/main.rs index 1589e1b4..65c63571 100644 --- a/examples/the-hat-chooses-the-wizard/src/main.rs +++ b/examples/the-hat-chooses-the-wizard/src/main.rs @@ -783,17 +783,14 @@ fn main(mut agb: agb::Gba) -> ! { let mut splash_screen = tiled.background(Priority::P0); let mut world_display = tiled.background(Priority::P0); - let tile_set_ref = vram.add_tileset(TileSet::new( - tile_sheet::background.tiles, - TileFormat::FourBpp, - )); + let tileset = TileSet::new(tile_sheet::background.tiles, TileFormat::FourBpp); for y in 0..32u16 { for x in 0..32u16 { world_display.set_tile( &mut vram, (x, y).into(), - tile_set_ref, + &tileset, TileSetting::from_raw(level_display::BLANK), ); } @@ -837,7 +834,7 @@ fn main(mut agb: agb::Gba) -> ! { &mut world_display, current_level / 8 + 1, current_level % 8 + 1, - tile_set_ref, + &tileset, &mut vram, ); @@ -849,12 +846,13 @@ fn main(mut agb: agb::Gba) -> ! { vblank.wait_for_vblank(); mixer.after_vblank(); + let map_current_level = current_level; let mut background = InfiniteScrolledMap::new( tiled.background(Priority::P2), - Box::new(move |pos: Vector2D| { - let level = &map_tiles::LEVELS[current_level as usize]; + Box::new(|pos: Vector2D| { + let level = &map_tiles::LEVELS[map_current_level as usize]; ( - tile_set_ref, + &tileset, TileSetting::from_raw( *level .background @@ -866,10 +864,10 @@ fn main(mut agb: agb::Gba) -> ! { ); let mut foreground = InfiniteScrolledMap::new( tiled.background(Priority::P0), - Box::new(move |pos: Vector2D| { - let level = &map_tiles::LEVELS[current_level as usize]; + Box::new(|pos: Vector2D| { + let level = &map_tiles::LEVELS[map_current_level as usize]; ( - tile_set_ref, + &tileset, TileSetting::from_raw( *level .foreground diff --git a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs index 4605d74d..b39e39f9 100644 --- a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs +++ b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs @@ -19,22 +19,19 @@ pub fn show_splash_screen( vram: &mut VRamManager, ) { map.set_scroll_pos((0u16, 0u16).into()); - let (tile_set_ref, palette) = match which { + let (tileset, palette) = match which { SplashScreen::Start => { - let tile_set_ref = vram.add_tileset(TileSet::new( - splash_screens::splash.tiles, - TileFormat::FourBpp, - )); + let tileset = TileSet::new(splash_screens::splash.tiles, TileFormat::FourBpp); - (tile_set_ref, splash_screens::splash.palettes) + (tileset, splash_screens::splash.palettes) } SplashScreen::End => { - let tile_set_ref = vram.add_tileset(TileSet::new( + let tileset = TileSet::new( splash_screens::thanks_for_playing.tiles, TileFormat::FourBpp, - )); + ); - (tile_set_ref, splash_screens::thanks_for_playing.palettes) + (tileset, splash_screens::thanks_for_playing.palettes) } }; @@ -60,7 +57,7 @@ pub fn show_splash_screen( map.set_tile( vram, (x, y).into(), - tile_set_ref, + &tileset, TileSetting::from_raw(y * 30 + x), ); } @@ -108,6 +105,4 @@ pub fn show_splash_screen( map.hide(); map.clear(vram); - - vram.remove_tileset(tile_set_ref); } diff --git a/examples/the-purple-night/src/main.rs b/examples/the-purple-night/src/main.rs index 6ab5aa03..b881e24b 100644 --- a/examples/the-purple-night/src/main.rs +++ b/examples/the-purple-night/src/main.rs @@ -2223,18 +2223,15 @@ fn game_with_level(gba: &mut agb::Gba) { vram.set_background_palettes(background::background.palettes); - let tileset_ref = vram.add_tileset(TileSet::new( - background::background.tiles, - TileFormat::FourBpp, - )); + let tileset = TileSet::new(background::background.tiles, TileFormat::FourBpp); let object = gba.display.object.get(); let backdrop = InfiniteScrolledMap::new( background.background(Priority::P2), - Box::new(move |pos| { + Box::new(|pos| { ( - tileset_ref, + &tileset, TileSetting::from_raw( *tilemap::BACKGROUND_MAP .get((pos.x + tilemap::WIDTH * pos.y) as usize) @@ -2246,9 +2243,9 @@ fn game_with_level(gba: &mut agb::Gba) { let foreground = InfiniteScrolledMap::new( background.background(Priority::P0), - Box::new(move |pos| { + Box::new(|pos| { ( - tileset_ref, + &tileset, TileSetting::from_raw( *tilemap::FOREGROUND_MAP .get((pos.x + tilemap::WIDTH * pos.y) as usize) @@ -2260,9 +2257,9 @@ fn game_with_level(gba: &mut agb::Gba) { let clouds = InfiniteScrolledMap::new( background.background(Priority::P3), - Box::new(move |pos| { + Box::new(|pos| { ( - tileset_ref, + &tileset, TileSetting::from_raw( *tilemap::CLOUD_MAP .get((pos.x + tilemap::WIDTH * pos.y) as usize)