From 22167ac608a1d782a178f60ad6d23233f75a8f25 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sat, 16 Nov 2024 10:36:14 +1100 Subject: [PATCH] add OwnedTileSet --- agb/src/display/tiled/mod.rs | 2 +- agb/src/display/tiled/vram_manager.rs | 33 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/agb/src/display/tiled/mod.rs b/agb/src/display/tiled/mod.rs index 2d8c614e..10f3524d 100644 --- a/agb/src/display/tiled/mod.rs +++ b/agb/src/display/tiled/mod.rs @@ -14,7 +14,7 @@ pub use map::{AffineMap, MapLoan, RegularMap, TiledMap}; pub use tiled0::Tiled0; pub use tiled1::Tiled1; pub use tiled2::Tiled2; -pub use vram_manager::{DynamicTile, TileFormat, TileIndex, TileSet, VRamManager}; +pub use vram_manager::{DynamicTile, OwnedTileSet, TileFormat, TileIndex, TileSet, VRamManager}; use map::TRANSPARENT_TILE_INDEX; diff --git a/agb/src/display/tiled/vram_manager.rs b/agb/src/display/tiled/vram_manager.rs index 4339d56b..b49b6ce5 100644 --- a/agb/src/display/tiled/vram_manager.rs +++ b/agb/src/display/tiled/vram_manager.rs @@ -60,6 +60,39 @@ impl<'a> TileSet<'a> { fn reference(&self) -> NonNull<[u8]> { self.tiles.into() } + + pub fn to_owned(&self) -> OwnedTileSet { + OwnedTileSet { + tiles: self.tiles.to_vec(), + format: self.format, + } + } +} + +pub struct OwnedTileSet { + tiles: Vec, + format: TileFormat, +} + +impl OwnedTileSet { + pub fn tile_set(&self) -> TileSet<'_> { + TileSet { + tiles: &self.tiles, + format: self.format, + } + } + + pub fn tiles(&self) -> &[u8] { + &self.tiles + } + + pub fn tiles_mut(&mut self) -> &mut [u8] { + &mut self.tiles + } + + pub fn format(&self) -> TileFormat { + self.format + } } #[derive(Debug, Clone, Copy)]