diff --git a/lib/src/format/cmdl.rs b/lib/src/format/cmdl.rs index 327a0f0..b9702b5 100644 --- a/lib/src/format/cmdl.rs +++ b/lib/src/format/cmdl.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + use std::{io::Cursor, marker::PhantomData}; use anyhow::{bail, ensure, Result}; @@ -300,9 +302,9 @@ pub struct SMeshLoadInformation { pub mesh_count: u32, #[br(count = mesh_count)] pub meshes: Vec, - #[br(count = (mesh_count + 3) / 4)] + #[br(count = mesh_count.div_ceil(4))] pub unk_data_1: Vec, - #[br(count = (mesh_count + 7) / 8)] + #[br(count = mesh_count.div_ceil(8))] pub unk_data_2: Vec, #[bw(try_calc = shorts.len().try_into())] pub short_count: u32, @@ -310,11 +312,11 @@ pub struct SMeshLoadInformation { pub shorts: Vec, // #[bw(try_calc = lod_info.len().try_into())] pub lod_count: u8, - #[br(count = lod_count)] + #[br(count = lod_count as usize)] pub lod_info: Vec, #[bw(calc = if lod_rules.is_empty() { 0 } else { 1 })] pub has_lod_rules: u32, - #[br(if(has_lod_rules == 1), count(lod_count))] + #[br(if(has_lod_rules == 1), count(lod_count as usize))] pub lod_rules: Vec, } diff --git a/lib/src/format/mcon.rs b/lib/src/format/mcon.rs index 36a2aa8..04ef273 100644 --- a/lib/src/format/mcon.rs +++ b/lib/src/format/mcon.rs @@ -20,6 +20,7 @@ const K_CHUNK_MCCD: FourCC = FourCC(*b"MCCD"); #[binrw] #[derive(Clone, Debug)] +#[allow(unused)] struct SModConHeader { unk: u32, } diff --git a/lib/src/format/pack.rs b/lib/src/format/pack.rs index 465dedf..5d1436a 100644 --- a/lib/src/format/pack.rs +++ b/lib/src/format/pack.rs @@ -444,7 +444,10 @@ where O: ByteOrderExt + 'static ensure!(asset_entry.asset_type == form.id); ensure!(asset_entry.version.get() == form.reader_version.get()); ensure!(asset_entry.other_version.get() == form.writer_version.get()); - ensure!(form.size.get() == 0 || asset_entry.decompressed_size.get() == form.size.get() + 32 /* RFRM */); + ensure!( + form.size.get() == 0 + || asset_entry.decompressed_size.get() == form.size.get() + 32 /* RFRM */ + ); } let asset_id = asset_entry.asset_id.get(); diff --git a/lib/src/format/room.rs b/lib/src/format/room.rs index c143f0c..b4545f0 100644 --- a/lib/src/format/room.rs +++ b/lib/src/format/room.rs @@ -605,7 +605,7 @@ fn parse_property_list( ), None => (None, None), }; - let value = value.unwrap_or_else(|| ConstructedPropertyValue::Unknown(data)); + let value = value.unwrap_or(ConstructedPropertyValue::Unknown(data)); properties.push(ConstructedProperty { id, name, value }); } Ok(ConstructedPropertyValue::PropertyList(Box::new(ConstructedPropertyList { diff --git a/lib/src/format/txtr.rs b/lib/src/format/txtr.rs index 41e00d7..bc37356 100644 --- a/lib/src/format/txtr.rs +++ b/lib/src/format/txtr.rs @@ -764,8 +764,8 @@ pub fn decompress_image( | ETextureFormat::RgbaAstc12x10Srgb | ETextureFormat::RgbaAstc12x12Srgb => { let (bw, bh, _) = format.block_size(); - let rw = (w + (bw as u32 - 1)) / bw as u32; - let rh = (h + (bh as u32 - 1)) / bh as u32; + let rw = w.div_ceil(bw as u32); + let rh = h.div_ceil(bh as u32); ensure!(data.len() == rw as usize * rh as usize * 16); let mut image = RgbaImage::new(w, h); astc_decode::astc_decode( diff --git a/lib/src/lib.rs b/lib/src/lib.rs index bcba061..97871f5 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,2 +1,3 @@ +#![allow(clippy::double_parens)] pub mod format; pub mod util; diff --git a/lib/src/util/lzss.rs b/lib/src/util/lzss.rs index ab44240..48a9848 100644 --- a/lib/src/util/lzss.rs +++ b/lib/src/util/lzss.rs @@ -94,7 +94,7 @@ impl<'a> DecompressionState<'a> { #[inline] fn read_byte(&mut self) -> Option { - if self.input.len() > 0 { + if !self.input.is_empty() { let b = self.input[0]; self.input = &self.input[1..]; Some(b) diff --git a/retrotool-gui/src/loaders/lightprobe.rs b/retrotool-gui/src/loaders/lightprobe.rs index 63b6e9c..a2e7cb9 100644 --- a/retrotool-gui/src/loaders/lightprobe.rs +++ b/retrotool-gui/src/loaders/lightprobe.rs @@ -18,8 +18,10 @@ use crate::{ #[derive(Debug, Clone, bevy::reflect::TypeUuid)] #[uuid = "f5d65a8b-ffcc-47ea-8c9d-1ab30cca723c"] pub struct LightProbeAsset { + #[allow(unused)] pub head: LightProbeBundleHeader, pub textures: Vec, + #[allow(unused)] pub extra: Vec, } diff --git a/retrotool-gui/src/loaders/material.rs b/retrotool-gui/src/loaders/material.rs index 44fcf61..1d58c49 100644 --- a/retrotool-gui/src/loaders/material.rs +++ b/retrotool-gui/src/loaders/material.rs @@ -9,6 +9,7 @@ use zerocopy::LittleEndian; #[derive(Debug, Clone, bevy::reflect::TypeUuid)] #[uuid = "83269869-1209-408e-8835-bc6f2496e82a"] pub struct MaterialAsset { + #[allow(unused)] pub inner: ModelData, } diff --git a/retrotool-gui/src/loaders/package.rs b/retrotool-gui/src/loaders/package.rs index b395570..efc77fa 100644 --- a/retrotool-gui/src/loaders/package.rs +++ b/retrotool-gui/src/loaders/package.rs @@ -58,16 +58,13 @@ impl AssetIo for RetroAssetIo { let Some(package_path) = package_path else { return Err(AssetIoError::NotFound(path.to_owned())); }; - read_asset(&package_path, id).map_err(|e| { - AssetIoError::Io(std::io::Error::new(std::io::ErrorKind::Other, e)) - }) + read_asset(&package_path, id) + .map_err(|e| AssetIoError::Io(std::io::Error::other(e))) }) } else if path.extension() == Some("pak".as_ref()) { // Load pak header only Box::pin(async move { - read_pak_header(path).map_err(|e| { - AssetIoError::Io(std::io::Error::new(std::io::ErrorKind::Other, e)) - }) + read_pak_header(path).map_err(|e| AssetIoError::Io(std::io::Error::other(e))) }) } else { self.default.load_path(path) diff --git a/retrotool-gui/src/loaders/texture.rs b/retrotool-gui/src/loaders/texture.rs index 7ab8982..6538df1 100644 --- a/retrotool-gui/src/loaders/texture.rs +++ b/retrotool-gui/src/loaders/texture.rs @@ -27,6 +27,7 @@ use crate::AssetRef; #[derive(Debug, Clone, bevy::reflect::TypeUuid)] #[uuid = "83269869-1209-408e-8835-bc6f2496e828"] pub struct TextureAsset { + #[allow(unused)] pub asset_ref: AssetRef, pub inner: TextureData, pub texture: Handle, @@ -151,8 +152,8 @@ fn texture_slice_to_image( if let TextureFormat::Astc { .. } = format { // Round up width / height to ASTC block size // wgpu requires it, but should it? - width = (width + (bw as u32 - 1)) / bw as u32 * bw as u32; - height = (height + (bh as u32 - 1)) / bh as u32 * bh as u32; + width = width.div_ceil(bw as u32) * bw as u32; + height = height.div_ceil(bh as u32) * bh as u32; } Image { data, @@ -208,8 +209,8 @@ fn texture_to_image( // Round up width / height to ASTC block size // wgpu requires it, but should it? let (bx, by, _) = data.head.format.block_size(); - width = (width + (bx as u32 - 1)) / bx as u32 * bx as u32; - height = (height + (by as u32 - 1)) / by as u32 * by as u32; + width = width.div_ceil(bx as u32) * bx as u32; + height = height.div_ceil(by as u32) * by as u32; } Ok(Image { data: image_data, diff --git a/retrotool-gui/src/main.rs b/retrotool-gui/src/main.rs index 1eb35f7..fd4e067 100644 --- a/retrotool-gui/src/main.rs +++ b/retrotool-gui/src/main.rs @@ -89,11 +89,11 @@ fn main() { .add_plugin(DefaultRaycastingPlugin::::default()) .insert_resource(DefaultPluginState::::default().with_debug_cursor()) // Diagnostics - .add_plugin(FrameTimeDiagnosticsPlugin::default()) - .add_plugin(EntityCountDiagnosticsPlugin::default()) + .add_plugin(FrameTimeDiagnosticsPlugin) + .add_plugin(EntityCountDiagnosticsPlugin) .add_plugin(AssetCountDiagnosticsPlugin::::default()) .add_plugin(AssetCountDiagnosticsPlugin::::default()) - .add_plugin(SystemInformationDiagnosticsPlugin::default()) + .add_plugin(SystemInformationDiagnosticsPlugin) // Systems .add_startup_system(setup_egui) .add_system(file_drop.before(load_files)) diff --git a/retrotool-gui/src/render/model.rs b/retrotool-gui/src/render/model.rs index 5c8a2fc..7f163ca 100644 --- a/retrotool-gui/src/render/model.rs +++ b/retrotool-gui/src/render/model.rs @@ -87,7 +87,7 @@ pub fn load_model(asset: &ModelAsset, meshes: &mut Assets) -> Result { let (values, range) = diff --git a/retrotool-gui/src/tabs/mod.rs b/retrotool-gui/src/tabs/mod.rs index 84c1b5d..4904105 100644 --- a/retrotool-gui/src/tabs/mod.rs +++ b/retrotool-gui/src/tabs/mod.rs @@ -25,6 +25,7 @@ pub struct OpenTab { pub struct TabState { pub open_assets: Vec, pub open_tab: Option, + #[allow(unused)] pub viewport: Viewport, pub render_layer: u8, pub close_all: Option, @@ -49,6 +50,7 @@ pub trait EditorTab: Send + Sync { fn title(&self) -> egui::WidgetText; + #[allow(unused)] fn id(&self) -> String; fn clear_background(&self) -> bool { true } diff --git a/retrotool-gui/src/tabs/project.rs b/retrotool-gui/src/tabs/project.rs index 3067c7e..fa0b42f 100644 --- a/retrotool-gui/src/tabs/project.rs +++ b/retrotool-gui/src/tabs/project.rs @@ -155,8 +155,7 @@ impl EditorTabSystem for ProjectTab { .iter() .filter(|e| { search.is_empty() - || (search.as_bytes().len() == 4 - && e.kind.0.eq_ignore_ascii_case(search.as_bytes())) + || (search.len() == 4 && e.kind.0.eq_ignore_ascii_case(search.as_bytes())) || e.names.iter().any(|n| n.to_ascii_lowercase().contains(search)) || e.id.to_string().contains(search) }) diff --git a/retrotool-gui/src/tabs/texture.rs b/retrotool-gui/src/tabs/texture.rs index 3549523..7003c5c 100644 --- a/retrotool-gui/src/tabs/texture.rs +++ b/retrotool-gui/src/tabs/texture.rs @@ -52,9 +52,7 @@ impl UiTexture { images: &mut Assets, textures: &mut EguiUserTextures, ) -> Option { - let Some(image) = images.get(&handle) else { - return None; - }; + let image = images.get(&handle)?; let width = image.texture_descriptor.size.width; let height = image.texture_descriptor.size.height; let weak_handle = handle.clone_weak(); diff --git a/retrotool/src/cmd/clsn.rs b/retrotool/src/cmd/clsn.rs index 1410960..c5ab63f 100644 --- a/retrotool/src/cmd/clsn.rs +++ b/retrotool/src/cmd/clsn.rs @@ -1,3 +1,5 @@ +#![allow(clippy::double_parens)] + use std::{ fs::File, io::{Cursor, Write}, @@ -52,6 +54,7 @@ pub struct Vertices { #[binrw] #[derive(Clone, Debug)] +#[allow(unused)] pub struct Materials { pub count: u32, #[br(count = count)] @@ -60,6 +63,7 @@ pub struct Materials { #[binrw] #[derive(Clone, Debug)] +#[allow(unused)] pub struct CCollisionMaterial { orientation: u32, material_type: u32, @@ -88,6 +92,7 @@ pub struct Triangles { #[binrw] #[derive(Clone, Debug)] +#[allow(unused)] pub struct AABoxTreeNode { bounds: CAABox, start: u32, @@ -100,6 +105,7 @@ pub struct AABoxTreeNode { #[binrw] #[derive(Clone, Debug)] +#[allow(unused)] pub struct OBBoxTreeNode { bounds: COBBox, start: u32, @@ -112,6 +118,7 @@ pub struct OBBoxTreeNode { #[binrw] #[derive(Clone, Debug)] +#[allow(unused)] pub struct AABoxCollisionTree { count: u32, #[br(count = count)] @@ -120,6 +127,7 @@ pub struct AABoxCollisionTree { #[binrw] #[derive(Clone, Debug)] +#[allow(unused)] pub struct OBBoxCollisionTree { count: u32, #[br(count = count)] diff --git a/retrotool/src/cmd/cmdl.rs b/retrotool/src/cmd/cmdl.rs index 7719c34..ef4e304 100644 --- a/retrotool/src/cmd/cmdl.rs +++ b/retrotool/src/cmd/cmdl.rs @@ -1,7 +1,8 @@ +#![allow(clippy::double_parens)] + use std::{ - collections::HashMap, - fs, - fs::{DirBuilder, File}, + collections::{BTreeMap, HashMap}, + fs::{self, DirBuilder, File}, io::{Cursor, Read, Write}, path::{Path, PathBuf}, }; @@ -9,7 +10,7 @@ use std::{ use anyhow::{bail, ensure, Result}; use argh::FromArgs; use binrw::{binrw, BinReaderExt, BinWriterExt, Endian}; -use gltf_json as json; +use gltf_json::{self as json, buffer::Stride, validation::USize64}; use half::f16; use image::ColorType; use json::validation::Checked::Valid; @@ -182,7 +183,7 @@ fn convert(args: ConvertArgs) -> Result<()> { let mut reader = Cursor::new(&**buf); let mut out_buf: Vec = vec![0; info.vertex_count as usize * info.out_stride as usize]; let mut w = Cursor::new(&mut *out_buf); - let mut tmp_buf = vec![0u8; 16]; // max size of attribute + let mut tmp_buf = [0u8; 16]; // max size of attribute let mut in_buf = vec![0u8; info.in_stride as usize]; for _ in 0..info.vertex_count as usize { reader.read_exact(&mut in_buf)?; @@ -223,7 +224,7 @@ fn convert(args: ConvertArgs) -> Result<()> { let file_name = format!("vtxbuf{idx}.bin"); fs::write(args.out_dir.join(&file_name), buf)?; json_buffers.push(json::Buffer { - byte_length: buf.len() as u32, + byte_length: buf.len().into(), extensions: Default::default(), extras: Default::default(), name: None, @@ -234,7 +235,7 @@ fn convert(args: ConvertArgs) -> Result<()> { let file_name = format!("idxbuf{idx}.bin"); fs::write(args.out_dir.join(&file_name), buf)?; json_buffers.push(json::Buffer { - byte_length: buf.len() as u32, + byte_length: buf.len().into(), extensions: Default::default(), extras: Default::default(), name: None, @@ -246,11 +247,11 @@ fn convert(args: ConvertArgs) -> Result<()> { let mut json_buffer_views = Vec::new(); let mut json_accessors = Vec::new(); let mut json_attributes: Vec< - HashMap, json::Index>, + BTreeMap, json::Index>, > = Vec::new(); for buf_info in &vbuf.info { let num_buffers = buf_info.num_buffers as usize; - let mut attribute_map = HashMap::new(); + let mut attribute_map = BTreeMap::new(); for idx in 0..num_buffers { let target_vtx_buf = cur_buf + idx; let info = &buf_infos[target_vtx_buf]; @@ -258,7 +259,7 @@ fn convert(args: ConvertArgs) -> Result<()> { buffer: json::Index::new(target_vtx_buf as u32), byte_length: json_buffers[target_vtx_buf].byte_length, byte_offset: None, - byte_stride: Some(info.out_stride), + byte_stride: Some(Stride(info.out_stride as usize)), extensions: Default::default(), extras: Default::default(), name: Some(format!("Vertex buffer view {target_vtx_buf}")), @@ -267,8 +268,8 @@ fn convert(args: ConvertArgs) -> Result<()> { for attribute in &info.attributes { let accessor = json::Accessor { buffer_view: Some(json::Index::new(target_vtx_buf as u32)), - byte_offset: attribute.out_offset, - count: info.vertex_count, + byte_offset: Some(USize64(attribute.out_offset as u64)), + count: USize64(info.vertex_count as u64), component_type: Valid(json::accessor::GenericComponentType( match attribute.out_format { EVertexDataFormat::R8Unorm @@ -545,7 +546,7 @@ fn convert(args: ConvertArgs) -> Result<()> { let mut f = File::create(out_dir.join(format!("{}.png", texture.id)))?; let mut p = png::Encoder::new(&mut f, image.width(), image.height()); if txtr.head.format.is_srgb() { - p.set_srgb(SrgbRenderingIntent::Perceptual); + p.set_source_srgb(SrgbRenderingIntent::Perceptual); } p.set_color(match image.color() { ColorType::L8 | ColorType::L16 => png::ColorType::Grayscale, @@ -783,13 +784,15 @@ fn convert(args: ConvertArgs) -> Result<()> { let index_accessor_idx = json_accessors.len() as u32; json_accessors.push(json::Accessor { buffer_view: Some(json::Index::new(index_buf_idx)), - byte_offset: mesh.index_start - * match index_type { - EBufferType::U8 => 1, - EBufferType::U16 => 2, - EBufferType::U32 => 4, - }, - count: mesh.index_count, + byte_offset: Some(USize64( + mesh.index_start as u64 + * match index_type { + EBufferType::U8 => 1, + EBufferType::U16 => 2, + EBufferType::U32 => 4, + }, + )), + count: USize64(mesh.index_count as u64), component_type: Valid(json::accessor::GenericComponentType(match index_type { EBufferType::U8 => json::accessor::ComponentType::U8, EBufferType::U16 => json::accessor::ComponentType::U16,