From a73e817f0215c5b6db0717269862fc85ceb82888 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 29 Aug 2023 15:05:57 +0100 Subject: [PATCH] Deduplicate everything in hatwiz --- agb-image-converter/src/deduplicator.rs | 4 +-- .../src/level_display.rs | 15 +++++----- .../the-hat-chooses-the-wizard/src/lib.rs | 29 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/agb-image-converter/src/deduplicator.rs b/agb-image-converter/src/deduplicator.rs index cb20608b..92498b6d 100644 --- a/agb-image-converter/src/deduplicator.rs +++ b/agb-image-converter/src/deduplicator.rs @@ -72,7 +72,7 @@ impl Tile { fn vflipped(&self) -> Self { let mut new_data = self.data; - for y in 0..8 { + for y in 0..4 { for x in 0..8 { new_data.swap(y * 8 + x, (7 - y) * 8 + x); } @@ -85,7 +85,7 @@ impl Tile { let mut new_data = self.data; for y in 0..8 { - for x in 0..8 { + for x in 0..4 { new_data.swap(y * 8 + x, y * 8 + (7 - x)); } } 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 3e87f58b..268d31af 100644 --- a/examples/the-hat-chooses-the-wizard/src/level_display.rs +++ b/examples/the-hat-chooses-the-wizard/src/level_display.rs @@ -3,10 +3,10 @@ use agb::display::{ HEIGHT, WIDTH, }; -const LEVEL_START: u16 = 12 * 28; -const NUMBERS_START: u16 = 12 * 28 + 3; -const HYPHEN: u16 = 12 * 28 + 11; -pub const BLANK: u16 = 11 * 28; +const LEVEL_START: usize = 12 * 28; +const NUMBERS_START: usize = 12 * 28 + 3; +const HYPHEN: usize = 12 * 28 + 11; +pub const BLANK: usize = 11 * 28; pub fn write_level( map: &mut RegularMap, @@ -14,15 +14,16 @@ pub fn write_level( level: u32, tileset: &'_ TileSet<'_>, vram: &mut VRamManager, + tile_settings: &[TileSetting], ) { for (i, &tile) in [ LEVEL_START, LEVEL_START + 1, LEVEL_START + 2, BLANK, - world as u16 + NUMBERS_START - 1, + world as usize + NUMBERS_START - 1, HYPHEN, - level as u16 + NUMBERS_START - 1, + level as usize + NUMBERS_START - 1, ] .iter() .enumerate() @@ -31,7 +32,7 @@ pub fn write_level( vram, (i as u16, 0).into(), tileset, - TileSetting::from_raw(tile), + tile_settings[tile as usize], ); } diff --git a/examples/the-hat-chooses-the-wizard/src/lib.rs b/examples/the-hat-chooses-the-wizard/src/lib.rs index 5a03e89c..7dd67e99 100644 --- a/examples/the-hat-chooses-the-wizard/src/lib.rs +++ b/examples/the-hat-chooses-the-wizard/src/lib.rs @@ -11,7 +11,7 @@ use agb::{ object::{Graphics, OamManaged, Object, Tag, TagMap}, tiled::{ InfiniteScrolledMap, PartialUpdateStatus, RegularBackgroundSize, TileFormat, TileSet, - TileSetting, TiledMap, VRamManager, + TiledMap, VRamManager, }, Priority, HEIGHT, WIDTH, }, @@ -101,7 +101,7 @@ mod map_tiles { } } -agb::include_background_gfx!(tile_sheet, "2ce8f4", background => "gfx/tile_sheet.png"); +agb::include_background_gfx!(tile_sheet, "2ce8f4", background => deduplicate "gfx/tile_sheet.png"); const GRAPHICS: &Graphics = agb::include_aseprite!("gfx/sprites.aseprite"); const TAG_MAP: &TagMap = GRAPHICS.tags(); @@ -801,7 +801,7 @@ pub fn main(mut agb: agb::Gba) -> ! { &mut vram, (x, y).into(), &tileset, - TileSetting::from_raw(level_display::BLANK), + tile_sheet::background.tile_settings[level_display::BLANK], ); } } @@ -846,6 +846,7 @@ pub fn main(mut agb: agb::Gba) -> ! { current_level % 8 + 1, &tileset, &mut vram, + tile_sheet::background.tile_settings, ); world_display.commit(&mut vram); @@ -865,12 +866,11 @@ pub fn main(mut agb: agb::Gba) -> ! { let level = &map_tiles::LEVELS[map_current_level as usize]; ( &tileset, - TileSetting::from_raw( - *level - .background - .get((pos.y * level.dimensions.x as i32 + pos.x) as usize) - .unwrap_or(&0), - ), + tile_sheet::background.tile_settings[*level + .background + .get((pos.y * level.dimensions.x as i32 + pos.x) as usize) + .unwrap_or(&0) + as usize], ) }), ); @@ -884,12 +884,11 @@ pub fn main(mut agb: agb::Gba) -> ! { let level = &map_tiles::LEVELS[map_current_level as usize]; ( &tileset, - TileSetting::from_raw( - *level - .foreground - .get((pos.y * level.dimensions.x as i32 + pos.x) as usize) - .unwrap_or(&0), - ), + tile_sheet::background.tile_settings[*level + .foreground + .get((pos.y * level.dimensions.x as i32 + pos.x) as usize) + .unwrap_or(&0) + as usize], ) }), );