From 498236d064b3227a407321b2b53f5f9d3ba10d4a Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Thu, 13 Apr 2023 22:18:13 +0100 Subject: [PATCH] Remove tile size --- agb-image-converter/src/config.rs | 3 +-- agb-image-converter/src/lib.rs | 31 ++++------------------- agb-image-converter/src/rust_generator.rs | 9 +++---- 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/agb-image-converter/src/config.rs b/agb-image-converter/src/config.rs index daa112b9..814fced2 100644 --- a/agb-image-converter/src/config.rs +++ b/agb-image-converter/src/config.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use crate::{Colour, Colours, TileSize}; +use crate::{Colour, Colours}; pub(crate) trait Config { fn crate_prefix(&self) -> String; @@ -10,6 +10,5 @@ pub(crate) trait Config { pub(crate) trait Image { fn filename(&self) -> String; - fn tile_size(&self) -> TileSize; fn colours(&self) -> Colours; } diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index d1a786f0..c8d9c9f3 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -26,25 +26,12 @@ use image_loader::Image; use colour::Colour; -#[derive(Debug, Clone, Copy)] -pub(crate) enum TileSize { - Tile8, -} - #[derive(Debug, Clone, Copy)] pub(crate) enum Colours { Colours16, Colours256, } -impl TileSize { - fn to_size(self) -> usize { - match self { - TileSize::Tile8 => 8, - } - } -} - struct BackgroundGfxOption { module_name: String, file_name: String, @@ -56,10 +43,6 @@ impl config::Image for BackgroundGfxOption { self.file_name.clone() } - fn tile_size(&self) -> TileSize { - TileSize::Tile8 - } - fn colours(&self) -> Colours { self.colours } @@ -191,7 +174,7 @@ fn include_gfx_from_config( match settings.colours() { Colours::Colours16 => { - let tile_size = settings.tile_size().to_size(); + let tile_size = 8; if image.width % tile_size != 0 || image.height % tile_size != 0 { panic!("Image size not a multiple of tile size"); } @@ -203,7 +186,7 @@ fn include_gfx_from_config( config.transparent_colour(), ); - let num_tiles = image.width * image.height / settings.tile_size().to_size().pow(2); + let num_tiles = image.width * image.height / 8usize.pow(2); assignment_offsets.insert(name, assignment_offset); assignment_offset += num_tiles; } @@ -395,7 +378,6 @@ fn convert_image( optimisation_results, &image, &image_filename.to_string_lossy(), - settings.tile_size(), crate_prefix.to_owned(), assignment_offset, ) @@ -449,10 +431,9 @@ fn palette_tile_data( .collect(); let mut tile_data = Vec::new(); - let tile_size = TileSize::Tile8; for image in images { - add_image_to_tile_data(&mut tile_data, image, tile_size, optimiser, 0) + add_image_to_tile_data(&mut tile_data, image, optimiser, 0) } let tile_data = collapse_to_4bpp(&tile_data); @@ -472,11 +453,10 @@ fn collapse_to_4bpp(tile_data: &[u8]) -> Vec { fn add_image_to_tile_data( tile_data: &mut Vec, image: &Image, - tile_size: TileSize, optimiser: &Palette16OptimisationResults, assignment_offset: usize, ) { - let tile_size = tile_size.to_size(); + let tile_size = 8; let tiles_x = image.width / tile_size; let tiles_y = image.height / tile_size; @@ -502,10 +482,9 @@ fn add_image_to_tile_data( fn add_image_256_to_tile_data( tile_data: &mut Vec, image: &Image, - tile_size: TileSize, optimiser: &Palette16OptimisationResults, ) { - let tile_size = tile_size.to_size(); + let tile_size = 8; let tiles_x = image.width / tile_size; let tiles_y = image.height / tile_size; diff --git a/agb-image-converter/src/rust_generator.rs b/agb-image-converter/src/rust_generator.rs index 84b5632d..49c55001 100644 --- a/agb-image-converter/src/rust_generator.rs +++ b/agb-image-converter/src/rust_generator.rs @@ -1,5 +1,5 @@ use crate::palette16::Palette16OptimisationResults; -use crate::{add_image_256_to_tile_data, add_image_to_tile_data, collapse_to_4bpp, TileSize}; +use crate::{add_image_256_to_tile_data, add_image_to_tile_data, collapse_to_4bpp}; use crate::{image_loader::Image, ByteString}; use proc_macro2::TokenStream; @@ -38,7 +38,6 @@ pub(crate) fn generate_code( results: &Palette16OptimisationResults, image: &Image, image_filename: &str, - tile_size: TileSize, crate_prefix: String, assignment_offset: Option, ) -> TokenStream { @@ -48,11 +47,11 @@ pub(crate) fn generate_code( let (tile_data, assignments) = if let Some(assignment_offset) = assignment_offset { let mut tile_data = Vec::new(); - add_image_to_tile_data(&mut tile_data, image, tile_size, results, assignment_offset); + add_image_to_tile_data(&mut tile_data, image, results, assignment_offset); let tile_data = collapse_to_4bpp(&tile_data); - let num_tiles = image.width * image.height / tile_size.to_size().pow(2); + let num_tiles = image.width * image.height / 8usize.pow(2); let assignments = results .assignments @@ -66,7 +65,7 @@ pub(crate) fn generate_code( } else { let mut tile_data = Vec::new(); - add_image_256_to_tile_data(&mut tile_data, image, tile_size, results); + add_image_256_to_tile_data(&mut tile_data, image, results); (tile_data, vec![]) };