mirror of
https://github.com/PrimeDecomp/retrotool.git
synced 2026-07-12 18:18:58 -07:00
Build & clippy fixes
This commit is contained in:
@@ -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<CRenderMesh>,
|
||||
#[br(count = (mesh_count + 3) / 4)]
|
||||
#[br(count = mesh_count.div_ceil(4))]
|
||||
pub unk_data_1: Vec<u8>,
|
||||
#[br(count = (mesh_count + 7) / 8)]
|
||||
#[br(count = mesh_count.div_ceil(8))]
|
||||
pub unk_data_2: Vec<u8>,
|
||||
#[bw(try_calc = shorts.len().try_into())]
|
||||
pub short_count: u32,
|
||||
@@ -310,11 +312,11 @@ pub struct SMeshLoadInformation {
|
||||
pub shorts: Vec<u16>,
|
||||
// #[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<SLodInfoOuter>,
|
||||
#[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<SRenderModelLODRule>,
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ const K_CHUNK_MCCD: FourCC = FourCC(*b"MCCD");
|
||||
|
||||
#[binrw]
|
||||
#[derive(Clone, Debug)]
|
||||
#[allow(unused)]
|
||||
struct SModConHeader {
|
||||
unk: u32,
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -605,7 +605,7 @@ fn parse_property_list<R: Read + Seek>(
|
||||
),
|
||||
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 {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
#![allow(clippy::double_parens)]
|
||||
pub mod format;
|
||||
pub mod util;
|
||||
|
||||
@@ -94,7 +94,7 @@ impl<'a> DecompressionState<'a> {
|
||||
|
||||
#[inline]
|
||||
fn read_byte(&mut self) -> Option<u8> {
|
||||
if self.input.len() > 0 {
|
||||
if !self.input.is_empty() {
|
||||
let b = self.input[0];
|
||||
self.input = &self.input[1..];
|
||||
Some(b)
|
||||
|
||||
@@ -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<TextureAsset>,
|
||||
#[allow(unused)]
|
||||
pub extra: Vec<LightProbeExtra>,
|
||||
}
|
||||
|
||||
|
||||
@@ -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<LittleEndian>,
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<LittleEndian>,
|
||||
pub texture: Handle<Image>,
|
||||
@@ -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,
|
||||
|
||||
@@ -89,11 +89,11 @@ fn main() {
|
||||
.add_plugin(DefaultRaycastingPlugin::<ModConRaycastSet>::default())
|
||||
.insert_resource(DefaultPluginState::<ModConRaycastSet>::default().with_debug_cursor())
|
||||
// Diagnostics
|
||||
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_plugin(EntityCountDiagnosticsPlugin::default())
|
||||
.add_plugin(FrameTimeDiagnosticsPlugin)
|
||||
.add_plugin(EntityCountDiagnosticsPlugin)
|
||||
.add_plugin(AssetCountDiagnosticsPlugin::<TextureAsset>::default())
|
||||
.add_plugin(AssetCountDiagnosticsPlugin::<ModelAsset>::default())
|
||||
.add_plugin(SystemInformationDiagnosticsPlugin::default())
|
||||
.add_plugin(SystemInformationDiagnosticsPlugin)
|
||||
// Systems
|
||||
.add_startup_system(setup_egui)
|
||||
.add_system(file_drop.before(load_files))
|
||||
|
||||
@@ -87,7 +87,7 @@ pub fn load_model(asset: &ModelAsset, meshes: &mut Assets<Mesh>) -> Result<Built
|
||||
|
||||
// Process meshes
|
||||
let mut out_meshes = vec![];
|
||||
for (_idx, in_mesh) in mesh.meshes.iter().enumerate() {
|
||||
for in_mesh in mesh.meshes.iter() {
|
||||
let (indices, vert_range) = match &index_buffers[in_mesh.idx_buf_idx as usize] {
|
||||
IndicesSlice::U16(indices) => {
|
||||
let (values, range) =
|
||||
|
||||
@@ -25,6 +25,7 @@ pub struct OpenTab {
|
||||
pub struct TabState {
|
||||
pub open_assets: Vec<AssetRef>,
|
||||
pub open_tab: Option<OpenTab>,
|
||||
#[allow(unused)]
|
||||
pub viewport: Viewport,
|
||||
pub render_layer: u8,
|
||||
pub close_all: Option<NodeIndex>,
|
||||
@@ -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 }
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -52,9 +52,7 @@ impl UiTexture {
|
||||
images: &mut Assets<Image>,
|
||||
textures: &mut EguiUserTextures,
|
||||
) -> Option<Self> {
|
||||
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();
|
||||
|
||||
@@ -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)]
|
||||
|
||||
+23
-20
@@ -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<u8> = 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::validation::Checked<json::mesh::Semantic>, json::Index<json::Accessor>>,
|
||||
BTreeMap<json::validation::Checked<json::mesh::Semantic>, json::Index<json::Accessor>>,
|
||||
> = 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,
|
||||
|
||||
Reference in New Issue
Block a user