diff --git a/ashen/src/asset/color_map.rs b/ashen/src/asset/color_map.rs index 4b19571..30795b3 100644 --- a/ashen/src/asset/color_map.rs +++ b/ashen/src/asset/color_map.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::{error, utils::nom::*}; const COLORS_COUNT: usize = 256; @@ -35,7 +35,7 @@ impl Color { } } -impl AssetParser for Color { +impl AssetParser for Color { type Output = Self; type Context<'ctx> = (); @@ -55,7 +55,7 @@ pub struct ColorMap { pub shades: Box<[[Color; COLORS_COUNT]; SHADES_COUNT]>, } -impl AssetParser for ColorMap { +impl AssetParser for ColorMap { type Output = Self; type Context<'ctx> = (); @@ -155,7 +155,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, color_map) = >::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; output_file( parsed_file_path!("color-map/monsters.png"), diff --git a/ashen/src/asset/gamma_table.rs b/ashen/src/asset/gamma_table.rs index 050536e..96d82d5 100644 --- a/ashen/src/asset/gamma_table.rs +++ b/ashen/src/asset/gamma_table.rs @@ -1,6 +1,6 @@ use std::mem; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::{error, utils::nom::*}; const ROWS_COUNT: usize = 256; @@ -12,7 +12,7 @@ pub struct GammaTable { pub lookups: Box<[[u8; ROWS_COUNT]; COLS_COUNT]>, } -impl AssetParser for GammaTable { +impl AssetParser for GammaTable { type Output = Self; type Context<'ctx> = (); @@ -61,7 +61,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, gamma_table) = >::parser(())(&GAMMA_TABLE_DATA)?; + let (_, gamma_table) = ::parser(())(&GAMMA_TABLE_DATA)?; let gamma_table = gamma_table .lookups diff --git a/ashen/src/asset/mod.rs b/ashen/src/asset/mod.rs index 2f0838c..a3dede5 100644 --- a/ashen/src/asset/mod.rs +++ b/ashen/src/asset/mod.rs @@ -10,55 +10,7 @@ pub mod texture; use crate::utils::nom::{Input, Result}; -/// Definition for all available extensions that the engine can parse. -pub mod extension { - #[sealed::sealed] - pub trait Extension: AsRef + for<'str> TryFrom<&'str str> {} - - #[derive(Debug, thiserror::Error)] - #[error("The provided extension is invalid '{}'", self.0)] - pub struct ExtensionMismatchError(String); - - macro_rules! impl_extension { - ($(#[$docs:meta])+ $name:ident => $ext:literal) => { - $(#[$docs])+ - pub struct $name; - - impl AsRef for $name { - fn as_ref(&self) -> &str { - $ext - } - } - - impl TryFrom<&str> for $name { - type Error = ExtensionMismatchError; - - fn try_from(value: &str) -> Result { - if value == $ext { - Ok(Self) - } else { - Err(ExtensionMismatchError(value.to_owned())) - } - } - } - - #[sealed::sealed] - impl Extension for $name {} - }; - } - - impl_extension!( - /// Wildcard - Wildcard => "*" - ); - - impl_extension!( - /// Extension that implies that the asset comes from ashen's files (packfile). - Pack => "pack" - ); -} - -pub trait AssetParser +pub trait AssetParser where Self: Sized, { diff --git a/ashen/src/asset/model/dat/frame.rs b/ashen/src/asset/model/dat/frame.rs index 3c6f024..8460051 100644 --- a/ashen/src/asset/model/dat/frame.rs +++ b/ashen/src/asset/model/dat/frame.rs @@ -1,7 +1,4 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; // TODO(nenikitov): Should probably be a fancy utility class // With generics for data type and dimension @@ -12,7 +9,7 @@ pub struct Vec3 { pub z: f32, } -impl AssetParser for Vec3 { +impl AssetParser for Vec3 { type Output = Self; type Context<'ctx> = (); @@ -52,7 +49,7 @@ pub struct VertexTransform { origin: Vec3, } -impl AssetParser for ModelVertex { +impl AssetParser for ModelVertex { type Output = Self; type Context<'ctx> = VertexTransform; @@ -97,7 +94,7 @@ pub struct ModelSpecs { pub frame_size: u32, } -impl AssetParser for ModelFrame { +impl AssetParser for ModelFrame { type Output = Self; type Context<'ctx> = ModelSpecs; diff --git a/ashen/src/asset/model/dat/header.rs b/ashen/src/asset/model/dat/header.rs index 74bcb28..7f5f8dc 100644 --- a/ashen/src/asset/model/dat/header.rs +++ b/ashen/src/asset/model/dat/header.rs @@ -1,7 +1,4 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub struct ModelHeader { pub triangle_count: u32, @@ -18,7 +15,7 @@ pub struct ModelHeader { pub locator_nodes: [u8; 16], } -impl AssetParser for ModelHeader { +impl AssetParser for ModelHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/model/dat/sequence.rs b/ashen/src/asset/model/dat/sequence.rs index 067a25c..f603e40 100644 --- a/ashen/src/asset/model/dat/sequence.rs +++ b/ashen/src/asset/model/dat/sequence.rs @@ -1,13 +1,10 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub struct ModelSequence { pub frames: Vec, } -impl AssetParser for ModelSequence { +impl AssetParser for ModelSequence { type Output = Self; // TODO(nenikitov): Maybe refactor it to not accept full input. diff --git a/ashen/src/asset/model/dat/triangle.rs b/ashen/src/asset/model/dat/triangle.rs index d9f5764..f6e636f 100644 --- a/ashen/src/asset/model/dat/triangle.rs +++ b/ashen/src/asset/model/dat/triangle.rs @@ -1,7 +1,4 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub struct ModelPoint { pub vertex_index: u16, @@ -14,7 +11,7 @@ pub struct TextureDimensions { pub height: u32, } -impl AssetParser for ModelPoint { +impl AssetParser for ModelPoint { type Output = Self; type Context<'ctx> = &'ctx TextureDimensions; @@ -39,7 +36,7 @@ pub struct ModelTriangle { pub points: [ModelPoint; 3], } -impl AssetParser for ModelTriangle { +impl AssetParser for ModelTriangle { type Output = Self; type Context<'ctx> = TextureDimensions; diff --git a/ashen/src/asset/model/mod.rs b/ashen/src/asset/model/mod.rs index 606ba71..b9dc44f 100644 --- a/ashen/src/asset/model/mod.rs +++ b/ashen/src/asset/model/mod.rs @@ -8,7 +8,6 @@ use dat::{ }; use super::{ - extension::*, texture::{Texture, TextureSize}, AssetParser, }; @@ -21,7 +20,7 @@ pub struct Model { pub frames: Vec, } -impl AssetParser for Model { +impl AssetParser for Model { type Output = Self; type Context<'ctx> = (); @@ -95,9 +94,9 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, model) = >::parser(())(&MODEL_DATA)?; + let (_, model) = ::parser(())(&MODEL_DATA)?; let palette = { - let (_, color_map) = >::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; color_map.shades[15] }; diff --git a/ashen/src/asset/pack_info.rs b/ashen/src/asset/pack_info.rs index 1906356..44b26b1 100644 --- a/ashen/src/asset/pack_info.rs +++ b/ashen/src/asset/pack_info.rs @@ -1,6 +1,6 @@ use std::ops::Index; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::utils::nom::*; #[derive(Debug)] @@ -9,7 +9,7 @@ pub struct PackInfo { pub size: u32, } -impl AssetParser for PackInfo { +impl AssetParser for PackInfo { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/skybox.rs b/ashen/src/asset/skybox.rs index 15090e0..ee776c8 100644 --- a/ashen/src/asset/skybox.rs +++ b/ashen/src/asset/skybox.rs @@ -1,5 +1,4 @@ use super::{ - extension::*, texture::{Texture, TextureSize}, AssetParser, }; @@ -12,7 +11,7 @@ pub struct Skybox { pub texture: Texture, } -impl AssetParser for Skybox { +impl AssetParser for Skybox { type Output = Self; type Context<'ctx> = (); @@ -51,7 +50,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, skybox) = >::parser(())(&SKYBOX_DATA)?; + let (_, skybox) = ::parser(())(&SKYBOX_DATA)?; output_file( parsed_file_path!("skyboxes/level-1.png"), diff --git a/ashen/src/asset/sound/dat/asset_header.rs b/ashen/src/asset/sound/dat/asset_header.rs index 51fdad0..a5d03a4 100644 --- a/ashen/src/asset/sound/dat/asset_header.rs +++ b/ashen/src/asset/sound/dat/asset_header.rs @@ -1,5 +1,5 @@ use crate::{ - asset::{extension::*, pack_info::PackInfo, AssetParser}, + asset::{pack_info::PackInfo, AssetParser}, utils::nom::*, }; @@ -14,7 +14,7 @@ impl SoundAssetHeader { const HEADER: &'static str = "TSND"; } -impl AssetParser for SoundAssetHeader { +impl AssetParser for SoundAssetHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/chunk_header.rs b/ashen/src/asset/sound/dat/chunk_header.rs index 3990ea4..3b7cbbf 100644 --- a/ashen/src/asset/sound/dat/chunk_header.rs +++ b/ashen/src/asset/sound/dat/chunk_header.rs @@ -1,5 +1,5 @@ use crate::{ - asset::{extension::*, pack_info::PackInfo, AssetParser}, + asset::{pack_info::PackInfo, AssetParser}, utils::nom::*, }; @@ -7,7 +7,7 @@ pub struct SoundChunkHeader { pub infos: Vec, } -impl AssetParser for SoundChunkHeader { +impl AssetParser for SoundChunkHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/pattern_effect.rs b/ashen/src/asset/sound/dat/pattern_effect.rs index b7b91a6..1d1cfe4 100644 --- a/ashen/src/asset/sound/dat/pattern_effect.rs +++ b/ashen/src/asset/sound/dat/pattern_effect.rs @@ -1,8 +1,5 @@ use super::{convert_volume, finetune::FineTune}; -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; #[derive(Debug, Clone, Copy)] pub enum Speed { @@ -130,7 +127,7 @@ impl PatternEffect { } } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = bool; diff --git a/ashen/src/asset/sound/dat/pattern_event.rs b/ashen/src/asset/sound/dat/pattern_event.rs index 73651d8..1edeb04 100644 --- a/ashen/src/asset/sound/dat/pattern_event.rs +++ b/ashen/src/asset/sound/dat/pattern_event.rs @@ -3,10 +3,7 @@ use std::rc::Rc; use bitflags::bitflags; use super::{convert_volume, finetune::FineTune, pattern_effect::PatternEffect, t_instrument::*}; -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; #[derive(Default, PartialEq, Clone, Copy, Debug)] pub enum PatternEventNote { @@ -15,7 +12,7 @@ pub enum PatternEventNote { On(FineTune), } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = bool; @@ -51,7 +48,7 @@ bitflags! { } } -impl AssetParser for PatternEventFlags { +impl AssetParser for PatternEventFlags { type Output = Self; type Context<'ctx> = (); @@ -71,7 +68,7 @@ impl AssetParser for PatternEventFlags { } } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = (bool, &'ctx [Rc]); @@ -105,7 +102,7 @@ impl Default for PatternEventVolume { } } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = bool; @@ -152,7 +149,7 @@ impl PatternEvent { } } -impl AssetParser for PatternEvent { +impl AssetParser for PatternEvent { type Output = Self; type Context<'ctx> = &'ctx [Rc]; diff --git a/ashen/src/asset/sound/dat/t_effect.rs b/ashen/src/asset/sound/dat/t_effect.rs index 1966b12..5ccdf45 100644 --- a/ashen/src/asset/sound/dat/t_effect.rs +++ b/ashen/src/asset/sound/dat/t_effect.rs @@ -5,7 +5,7 @@ use super::{ uncompress, }; use crate::{ - asset::{extension::*, sound::sample::AudioBuffer, AssetParser}, + asset::{sound::sample::AudioBuffer, AssetParser}, utils::nom::*, }; @@ -20,7 +20,7 @@ impl TEffect { } } -impl AssetParser for TEffect { +impl AssetParser for TEffect { type Output = Self; type Context<'ctx> = (); @@ -50,7 +50,7 @@ struct TEffectPointers { sample_data: u32, } -impl AssetParser for TEffectPointers { +impl AssetParser for TEffectPointers { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/t_instrument.rs b/ashen/src/asset/sound/dat/t_instrument.rs index 53972f0..f37cb01 100644 --- a/ashen/src/asset/sound/dat/t_instrument.rs +++ b/ashen/src/asset/sound/dat/t_instrument.rs @@ -4,7 +4,7 @@ use bitflags::bitflags; use super::{convert_volume, finetune::FineTune}; use crate::{ - asset::{extension::*, sound::sample::AudioBuffer, AssetParser}, + asset::{sound::sample::AudioBuffer, AssetParser}, utils::{iterator::CollectArray, nom::*}, }; @@ -16,7 +16,7 @@ bitflags! { } } -impl AssetParser for TInstrumentFlags { +impl AssetParser for TInstrumentFlags { type Output = Self; type Context<'ctx> = (); @@ -68,7 +68,7 @@ impl TInstrumentVolumeEnvelope { } } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = bool; @@ -129,7 +129,7 @@ impl TInstrument { const ENVELOPE_SIZE: usize = 325; } -impl AssetParser for TInstrument { +impl AssetParser for TInstrument { type Output = Self; type Context<'ctx> = &'ctx [Rc]; @@ -214,7 +214,7 @@ pub struct TSample { pub buffer: AudioBuffer, } -impl AssetParser for TSample { +impl AssetParser for TSample { type Output = Self; type Context<'ctx> = &'ctx [i16]; diff --git a/ashen/src/asset/sound/dat/t_song.rs b/ashen/src/asset/sound/dat/t_song.rs index cbef1a4..aaac9e0 100644 --- a/ashen/src/asset/sound/dat/t_song.rs +++ b/ashen/src/asset/sound/dat/t_song.rs @@ -3,10 +3,7 @@ use std::rc::Rc; use itertools::Itertools; use super::{pattern_event::*, t_instrument::*, uncompress}; -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub type PatternRow = Vec; pub type Pattern = Vec; @@ -93,7 +90,7 @@ impl std::fmt::Debug for TSong { } } -impl AssetParser for TSong { +impl AssetParser for TSong { type Output = Self; type Context<'ctx> = (); @@ -188,7 +185,7 @@ struct TSongHeader { bpm: u8, } -impl AssetParser for TSongHeader { +impl AssetParser for TSongHeader { type Output = Self; type Context<'ctx> = (); @@ -232,7 +229,7 @@ struct TSongPointers { sample_data: u32, } -impl AssetParser for TSongPointers { +impl AssetParser for TSongPointers { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/mod.rs b/ashen/src/asset/sound/mod.rs index 946ccdb..f0bc1d9 100644 --- a/ashen/src/asset/sound/mod.rs +++ b/ashen/src/asset/sound/mod.rs @@ -2,7 +2,7 @@ mod dat; pub(crate) mod sample; use self::{dat::mixer::TSongMixer, sample::AudioBuffer}; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::{ asset::sound::dat::{ asset_header::SoundAssetHeader, chunk_header::SoundChunkHeader, t_effect::TEffect, @@ -32,7 +32,7 @@ impl SoundCollection { pub const CHANNEL_COUNT: usize = 1; } -impl AssetParser for SoundCollection { +impl AssetParser for SoundCollection { type Output = Vec; type Context<'ctx> = (); @@ -78,7 +78,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, sounds) = >::parser(())(&SOUND_DATA)?; + let (_, sounds) = ::parser(())(&SOUND_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("sounds/songs/")); diff --git a/ashen/src/asset/string_table.rs b/ashen/src/asset/string_table.rs index 270d723..e4f1d6d 100644 --- a/ashen/src/asset/string_table.rs +++ b/ashen/src/asset/string_table.rs @@ -1,4 +1,4 @@ -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::utils::nom::*; pub struct StringTable { @@ -14,7 +14,7 @@ fn utf_16_string(input: &[u8]) -> Result { }) } -impl AssetParser for StringTable { +impl AssetParser for StringTable { type Output = Self; type Context<'ctx> = (); @@ -42,7 +42,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, string_table) = >::parser(())(&STRING_TABLE_DATA)?; + let (_, string_table) = ::parser(())(&STRING_TABLE_DATA)?; output_file( parsed_file_path!("strings/english-uk.txt"), diff --git a/ashen/src/asset/texture/dat/offset.rs b/ashen/src/asset/texture/dat/offset.rs index c241c80..fc1075c 100644 --- a/ashen/src/asset/texture/dat/offset.rs +++ b/ashen/src/asset/texture/dat/offset.rs @@ -1,7 +1,4 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub struct TextureOffset { pub width: u16, @@ -13,7 +10,7 @@ pub struct TextureOffset { pub next_animation_texture_id: u32, } -impl AssetParser for TextureOffset { +impl AssetParser for TextureOffset { type Context<'ctx> = (); type Output = Self; diff --git a/ashen/src/asset/texture/dat/texture.rs b/ashen/src/asset/texture/dat/texture.rs index dcb4998..62479fc 100644 --- a/ashen/src/asset/texture/dat/texture.rs +++ b/ashen/src/asset/texture/dat/texture.rs @@ -4,7 +4,6 @@ use super::size::TextureSize; use crate::{ asset::{ color_map::{Color, PaletteTexture}, - extension::*, AssetParser, }, utils::nom::*, @@ -16,7 +15,7 @@ pub struct Texture { pub colors: Vec>, } -impl AssetParser for Texture { +impl AssetParser for Texture { type Output = Self; type Context<'ctx> = TextureSize; @@ -52,7 +51,7 @@ pub struct MippedTexture { pub mips: [Texture; 4], } -impl AssetParser for MippedTexture { +impl AssetParser for MippedTexture { type Output = Self; type Context<'ctx> = TextureSize; diff --git a/ashen/src/asset/texture/mod.rs b/ashen/src/asset/texture/mod.rs index 210e4f6..cd6a83a 100644 --- a/ashen/src/asset/texture/mod.rs +++ b/ashen/src/asset/texture/mod.rs @@ -3,7 +3,7 @@ mod dat; use dat::{offset::TextureOffset, texture::MippedTexture}; pub use dat::{size::TextureSize, texture::Texture}; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::utils::{compression::decompress, nom::*}; pub enum TextureMipKind { @@ -18,7 +18,7 @@ pub enum TextureAnimationKind { pub struct TextureOffsetCollection; -impl AssetParser for TextureOffsetCollection { +impl AssetParser for TextureOffsetCollection { type Output = Vec; type Context<'ctx> = (); @@ -34,7 +34,7 @@ impl AssetParser for TextureOffsetCollection { pub struct MippedTextureCollection; -impl AssetParser for MippedTextureCollection { +impl AssetParser for MippedTextureCollection { type Output = Vec; type Context<'ctx> = &'ctx [TextureOffset]; @@ -99,12 +99,12 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, color_map) = >::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; let color_map = &color_map.shades[15]; let (_, offsets) = - >::parser(())(&TEXTURE_INFO_DATA)?; + ::parser(())(&TEXTURE_INFO_DATA)?; let (_, textures) = - >::parser(&offsets)(&TEXTURE_DATA)?; + ::parser(&offsets)(&TEXTURE_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("textures/")); diff --git a/ashen/src/lib.rs b/ashen/src/lib.rs index a6f1160..70efeaa 100644 --- a/ashen/src/lib.rs +++ b/ashen/src/lib.rs @@ -17,13 +17,12 @@ )] #![warn(unused_imports)] #![feature( - // Discussion about possible future alternatives: - // https://github.com/rust-lang/rust/pull/101179 debug_closure_helpers, - duration_consts_float, generic_const_exprs, io_error_more, let_chains, + // Discussion about possible future alternatives: + // https://github.com/rust-lang/rust/pull/101179 maybe_uninit_uninit_array_transpose, )]