Remove tile size

This commit is contained in:
Gwilym Inzani 2023-04-13 22:18:13 +01:00
parent 11891e574f
commit 498236d064
3 changed files with 10 additions and 33 deletions

View file

@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::{Colour, Colours, TileSize}; use crate::{Colour, Colours};
pub(crate) trait Config { pub(crate) trait Config {
fn crate_prefix(&self) -> String; fn crate_prefix(&self) -> String;
@ -10,6 +10,5 @@ pub(crate) trait Config {
pub(crate) trait Image { pub(crate) trait Image {
fn filename(&self) -> String; fn filename(&self) -> String;
fn tile_size(&self) -> TileSize;
fn colours(&self) -> Colours; fn colours(&self) -> Colours;
} }

View file

@ -26,25 +26,12 @@ use image_loader::Image;
use colour::Colour; use colour::Colour;
#[derive(Debug, Clone, Copy)]
pub(crate) enum TileSize {
Tile8,
}
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub(crate) enum Colours { pub(crate) enum Colours {
Colours16, Colours16,
Colours256, Colours256,
} }
impl TileSize {
fn to_size(self) -> usize {
match self {
TileSize::Tile8 => 8,
}
}
}
struct BackgroundGfxOption { struct BackgroundGfxOption {
module_name: String, module_name: String,
file_name: String, file_name: String,
@ -56,10 +43,6 @@ impl config::Image for BackgroundGfxOption {
self.file_name.clone() self.file_name.clone()
} }
fn tile_size(&self) -> TileSize {
TileSize::Tile8
}
fn colours(&self) -> Colours { fn colours(&self) -> Colours {
self.colours self.colours
} }
@ -191,7 +174,7 @@ fn include_gfx_from_config(
match settings.colours() { match settings.colours() {
Colours::Colours16 => { 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 { if image.width % tile_size != 0 || image.height % tile_size != 0 {
panic!("Image size not a multiple of tile size"); panic!("Image size not a multiple of tile size");
} }
@ -203,7 +186,7 @@ fn include_gfx_from_config(
config.transparent_colour(), 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_offsets.insert(name, assignment_offset);
assignment_offset += num_tiles; assignment_offset += num_tiles;
} }
@ -395,7 +378,6 @@ fn convert_image(
optimisation_results, optimisation_results,
&image, &image,
&image_filename.to_string_lossy(), &image_filename.to_string_lossy(),
settings.tile_size(),
crate_prefix.to_owned(), crate_prefix.to_owned(),
assignment_offset, assignment_offset,
) )
@ -449,10 +431,9 @@ fn palette_tile_data(
.collect(); .collect();
let mut tile_data = Vec::new(); let mut tile_data = Vec::new();
let tile_size = TileSize::Tile8;
for image in images { 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); let tile_data = collapse_to_4bpp(&tile_data);
@ -472,11 +453,10 @@ fn collapse_to_4bpp(tile_data: &[u8]) -> Vec<u8> {
fn add_image_to_tile_data( fn add_image_to_tile_data(
tile_data: &mut Vec<u8>, tile_data: &mut Vec<u8>,
image: &Image, image: &Image,
tile_size: TileSize,
optimiser: &Palette16OptimisationResults, optimiser: &Palette16OptimisationResults,
assignment_offset: usize, assignment_offset: usize,
) { ) {
let tile_size = tile_size.to_size(); let tile_size = 8;
let tiles_x = image.width / tile_size; let tiles_x = image.width / tile_size;
let tiles_y = image.height / 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( fn add_image_256_to_tile_data(
tile_data: &mut Vec<u8>, tile_data: &mut Vec<u8>,
image: &Image, image: &Image,
tile_size: TileSize,
optimiser: &Palette16OptimisationResults, optimiser: &Palette16OptimisationResults,
) { ) {
let tile_size = tile_size.to_size(); let tile_size = 8;
let tiles_x = image.width / tile_size; let tiles_x = image.width / tile_size;
let tiles_y = image.height / tile_size; let tiles_y = image.height / tile_size;

View file

@ -1,5 +1,5 @@
use crate::palette16::Palette16OptimisationResults; 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 crate::{image_loader::Image, ByteString};
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
@ -38,7 +38,6 @@ pub(crate) fn generate_code(
results: &Palette16OptimisationResults, results: &Palette16OptimisationResults,
image: &Image, image: &Image,
image_filename: &str, image_filename: &str,
tile_size: TileSize,
crate_prefix: String, crate_prefix: String,
assignment_offset: Option<usize>, assignment_offset: Option<usize>,
) -> TokenStream { ) -> TokenStream {
@ -48,11 +47,11 @@ pub(crate) fn generate_code(
let (tile_data, assignments) = if let Some(assignment_offset) = assignment_offset { let (tile_data, assignments) = if let Some(assignment_offset) = assignment_offset {
let mut tile_data = Vec::new(); 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 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 let assignments = results
.assignments .assignments
@ -66,7 +65,7 @@ pub(crate) fn generate_code(
} else { } else {
let mut tile_data = Vec::new(); 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![]) (tile_data, vec![])
}; };