From 3fa5b4467f15ff7dcad46fc5bb91d70c3ca84953 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 1 Aug 2022 01:38:17 +0100 Subject: [PATCH 1/4] support sprites that are not square in include_aseprite --- agb-image-converter/src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index c9c58898..139c7aad 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -115,15 +115,12 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream { for frame in frames { let width = frame.width(); - assert!(width == frame.height() && width.is_power_of_two() && width <= 64); + let height = frame.height(); + assert!(width.is_power_of_two() && width <= 64); + assert!(height.is_power_of_two() && height <= 64); let image = Image::load_from_dyn_image(frame); - add_to_optimiser( - &mut optimiser, - &image, - width as usize, - Some(transparent_colour), - ); + add_to_optimiser(&mut optimiser, &image, 8, Some(transparent_colour)); images.push(image); } } @@ -293,7 +290,7 @@ fn palete_tile_data( let mut tile_data = Vec::new(); for image in images { - let tile_size = image.height; + let tile_size = 8; let tiles_x = image.width / tile_size; let tiles_y = image.height / tile_size; From 0409a20527fec0a99561e961bd81e7097b0b81d3 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 1 Aug 2022 01:38:26 +0100 Subject: [PATCH 2/4] add examples demonstrating this --- agb/examples/gfx/tall.aseprite | Bin 0 -> 662 bytes agb/examples/gfx/wide.aseprite | Bin 0 -> 702 bytes agb/examples/sprites.rs | 6 +++++- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 agb/examples/gfx/tall.aseprite create mode 100644 agb/examples/gfx/wide.aseprite diff --git a/agb/examples/gfx/tall.aseprite b/agb/examples/gfx/tall.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..532c264d31b71a18a2674eb2e957959b0e0d329d GIT binary patch literal 662 zcmb`FODIH99EXp=Ocov+V&#Oea}ANmh%7u3nmn>#nlWV(c_dP1k|LYgh&&d`BZ;-L zu(41c3ndyBC<+TT9vg<^yMriO=XSsQzyEW)zwexTCk;YeEQN>|Avr>X5Dw0tK~HZo zAM?}v$10Be7r!x>YUI6foF*BJ{FQP_ogn2`C-K)zuv9`M$!u7fUI3kWnb2F856`<& zp>N&^@3&{*>q8ElzOII@Ee+;Qbij(X3|L!{0?h?^&|>L@TFWqO>bQjVSp}O9uHfET z04jzMv+EmhWM~w&xm>WZt`_zckHa;y8T#t&@MLfkdZ)_ac&DaZEFetZcS*q_SONOD zBaSu7_#%rbnm8he9cp+Xg%LWsi&9viKtACl6H6w6q!E>L_EN~&C$YR#EpvXF-5(v44I!oMVV3C{Q%B_uG0Vj literal 0 HcmV?d00001 diff --git a/agb/examples/gfx/wide.aseprite b/agb/examples/gfx/wide.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..c1bdd226fecfc245b28832a4e137d74cac0a2f92 GIT binary patch literal 702 zcmb`FQAkr!9EXo>x`!ADVr($FrwHvyw<*SQbfNNLsT3kJS&*_d^*$_&2qS7DT4~UF z5F#fu7(wXt#YpMF7l|Iio+OzIY*cSKNKB$Bx9`q|La!Y--~HeJx!m7(&b^C=g!ufT zL`YH2ED=J4nEQjC(PXuJzxf}lGvxpNQC3JT(+ zdf0T*3&S24jQJbkdVdv6C&DndGy(IQ4e;5wOHf;M!c*fB*xXkO+nP^6x7Pzz^(J(7 z4Z%Pp3xjbTUS0kQ-)DB9&JZF#GY^OFJ%D|h20Q(2@YdNem~y*ex+4fz@4SJrrx)PZ zb*HYe0kd)Ll7daJ1N3o69BY*EMHW*uaYPV1)bK(IBXkTGUB?0i@(CxISTYGDjVQ%P zk|tOjCArpKhICbPWBcdei;r?Oiw@uUrpHvJa<8rP?e>Q8_Y6!1f}yRb)m)b_ zJ+Zat)YFP}X(jpai~I0%dvd$tm6CQW*d}&=efltXfAqEDb4(w-(mfJUU196^Zg19C zk?((NKUViLq|VkiYUs8xok4-lQp9sA1z-T*lGQ_8BJ_hM5^-g+#gDZ BzncI6 literal 0 HcmV?d00001 diff --git a/agb/examples/sprites.rs b/agb/examples/sprites.rs index b0b5941b..0ae5ffb5 100644 --- a/agb/examples/sprites.rs +++ b/agb/examples/sprites.rs @@ -8,7 +8,9 @@ use alloc::vec::Vec; const GRAPHICS: &Graphics = agb::include_aseprite!( "examples/gfx/objects.aseprite", - "examples/gfx/boss.aseprite" + "examples/gfx/boss.aseprite", + "examples/gfx/wide.aseprite", + "examples/gfx/tall.aseprite" ); const SPRITES: &[Sprite] = GRAPHICS.sprites(); const TAG_MAP: &TagMap = GRAPHICS.tags(); @@ -102,6 +104,8 @@ fn main(mut gba: agb::Gba) -> ! { loop { all_tags(&gfx); + gfx.commit(); all_sprites(&gfx); + gfx.commit(); } } From 9410f6ed1d6c7eb0218548b54cc3a86f9bef6aed Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 1 Aug 2022 12:07:50 +0100 Subject: [PATCH 3/4] update docs --- agb/src/display/object.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 09ab9275..3888a8af 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -163,9 +163,7 @@ macro_rules! align_bytes { /// Includes sprites found in the referenced aseprite files. Can include /// multiple at once and optimises palettes of all included in the single call -/// together. Currently limited to square sprites that match a supported -/// dimension of the GBA, see [Size] for supported sizes. Returns a reference to -/// [Graphics]. +/// together. See [Size] for supported sizes. Returns a reference to [Graphics]. /// /// ```rust,no_run /// # #![no_std] From ca64a2bb786e466b137508f8a7bd2eb41c85f008 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 1 Aug 2022 12:08:22 +0100 Subject: [PATCH 4/4] perform check in proc macro for size can give a better error message, pointing at the file that contains the bad sizes --- agb-image-converter/src/lib.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index 139c7aad..1cd8356b 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -116,8 +116,13 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream { for frame in frames { let width = frame.width(); let height = frame.height(); - assert!(width.is_power_of_two() && width <= 64); - assert!(height.is_power_of_two() && height <= 64); + assert!( + valid_sprite_size(width, height), + "File {} contains sprites with unrepresentable size {}x{}", + filename.display(), + width, + height + ); let image = Image::load_from_dyn_image(frame); add_to_optimiser(&mut optimiser, &image, 8, Some(transparent_colour)); @@ -398,3 +403,21 @@ mod tests { assert_eq!(AnimationDirection::PingPong as usize, 2); } } + +fn valid_sprite_size(width: u32, height: u32) -> bool { + match (width, height) { + (8, 8) => true, + (16, 16) => true, + (32, 32) => true, + (64, 64) => true, + (16, 8) => true, + (32, 8) => true, + (32, 16) => true, + (64, 32) => true, + (8, 16) => true, + (8, 32) => true, + (16, 32) => true, + (32, 64) => true, + (_, _) => false, + } +}