1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-20 03:37:47 +00:00

Fix yet more clippy warnings

This commit is contained in:
Joshua Goins 2024-04-20 13:17:11 -04:00
parent 79e6f20d86
commit 6e50f03cd9
11 changed files with 56 additions and 51 deletions

View file

@ -34,7 +34,7 @@ impl ConfigFile {
let mut current_category: Option<String> = None;
for line in reader.lines().flatten() {
for line in reader.lines().map_while(Result::ok) {
if !line.is_empty() && line != "\0" {
if line.contains('<') || line.contains('>') {
// Category

View file

@ -221,9 +221,7 @@ impl DatFile {
/// Reads a standard file block.
fn read_standard_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
let Some(standard_file_info) = file_info.standard_info.as_ref() else {
return None;
};
let standard_file_info = file_info.standard_info.as_ref()?;
let mut blocks: Vec<Block> = Vec::with_capacity(standard_file_info.num_blocks as usize);
@ -251,9 +249,7 @@ impl DatFile {
/// Reads a model file block.
#[cfg(feature = "visual_data")]
fn read_model_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
let Some(model_file_info) = file_info.model_info.as_ref() else {
return None;
};
let model_file_info = file_info.model_info.as_ref()?;
let mut buffer = Cursor::new(Vec::new());
@ -401,9 +397,7 @@ impl DatFile {
/// Reads a texture file block.
fn read_texture_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
let Some(texture_file_info) = file_info.texture_info.as_ref() else {
return None;
};
let texture_file_info = file_info.texture_info.as_ref()?;
let mut data: Vec<u8> = Vec::with_capacity(file_info.file_size as usize);

View file

@ -13,15 +13,13 @@ fn from_u16(from: &mut [u16]) -> &[u8] {
unsafe { std::slice::from_raw_parts(ptr, len) }
}
fn find_needle(installer_file: &Vec<u8>, needle: &str) -> Option<String> {
fn find_needle(installer_file: &[u8], needle: &str) -> Option<String> {
let mut needle: Vec<u16> = needle.encode_utf16().collect();
let bytes = from_u16(&mut needle);
let Some(mut position) = installer_file
let mut position = installer_file
.windows(bytes.len())
.position(|window| window == bytes) else {
return None;
};
.position(|window| window == bytes)?;
let parse_char_at_position = |position: usize| {
let upper = installer_file[position];

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#![allow(clippy::unnecessary_fallible_conversions)] // This wrongly trips on binrw code
use std::io::Cursor;
use binrw::BinRead;

View file

@ -24,7 +24,7 @@ impl EXL {
let cursor = Cursor::new(buffer);
let reader = BufReader::new(cursor);
for line in reader.lines().flatten() {
for line in reader.lines().map_while(Result::ok) {
if let Some((name, value)) = line.split_once(',') {
if let Ok(parsed_value) = value.parse() {
if name == "EXLT" {

View file

@ -36,7 +36,7 @@ enum LayerEntryType
#[brw(magic = 0x3i32)]
LayLight,
#[brw(magic = 0x4i32)]
VFX,
Vfx,
#[brw(magic = 0x5i32)]
PositionMarker,
#[brw(magic = 0x6i32)]
@ -76,7 +76,7 @@ enum LayerEntryType
Weapon = 0x27, //
PopRange = 0x28, // //
ExitRange = 0x29, // //
LVB = 0x2A,
Lvb = 0x2A,
MapRange = 0x2B, // //
NaviMeshRange = 0x2C, // //
EventObject = 0x2D, // //
@ -141,10 +141,10 @@ enum RotationState
#[derive(Debug, PartialEq)]
enum TransformState
{
TransformStatePlay = 0x0,
TransformStateStop = 0x1,
TransformStateReplay = 0x2,
TransformStateReset = 0x3,
Play = 0x0,
Stop = 0x1,
Replay = 0x2,
Reset = 0x3,
}
#[binrw]
@ -152,10 +152,10 @@ enum TransformState
#[derive(Debug, PartialEq)]
enum ColourState
{
ColorStatePlay = 0x0,
ColorStateStop = 0x1,
ColorStateReplay = 0x2,
ColorStateReset = 0x3,
Play = 0x0,
Stop = 0x1,
Replay = 0x2,
Reset = 0x3,
}
#[binrw]
@ -163,12 +163,12 @@ enum ColourState
#[derive(Debug, PartialEq)]
enum TriggerBoxShape
{
TriggerBoxShapeBox = 0x1,
TriggerBoxShapeSphere = 0x2,
TriggerBoxShapeCylinder = 0x3,
TriggerBoxShapeBoard = 0x4,
TriggerBoxShapeMesh = 0x5,
TriggerBoxShapeBoardBothSides = 0x6,
Box = 0x1,
Sphere = 0x2,
Cylinder = 0x3,
Board = 0x4,
Mesh = 0x5,
BoardBothSides = 0x6,
}
#[binrw]
@ -220,9 +220,9 @@ enum PositionMarkerType
#[derive(Debug, PartialEq)]
enum EnvSetShape
{
EnvShapeEllipsoid = 0x1,
EnvShapeCuboid = 0x2,
EnvShapeCylinder = 0x3,
Ellipsoid = 0x1,
Cuboid = 0x2,
Cylinder = 0x3,
}
#[binrw]
@ -262,7 +262,7 @@ enum PopType
#[br(magic = 0x1u8)]
PC = 0x1,
#[br(magic = 0x2u8)]
NPC,
Npc,
#[br(magic = 0x3u8)]
Content,
}
@ -405,6 +405,7 @@ enum SoundEffectType
#[binread]
#[derive(Debug)]
#[br(little)]
#[allow(dead_code)] // most of the fields are unused at the moment
struct LayerHeader {
layer_id: u32,
name_offset: u32,
@ -424,9 +425,7 @@ struct LayerHeader {
is_housing: u8,
version_mask: u16,
#[br(temp)]
padding: u32,
#[br(pad_before = 4)]
ob_set_referenced_list: i32,
ob_set_referenced_list_count: i32,
ob_set_enable_referenced_list: i32,
@ -436,6 +435,7 @@ struct LayerHeader {
#[binread]
#[derive(Debug)]
#[br(little)]
#[allow(dead_code)] // most of the fields are unused at the moment
struct LayerSetReferencedList {
referenced_type: LayerSetReferencedType,
layer_sets: i32,
@ -445,6 +445,7 @@ struct LayerSetReferencedList {
#[binread]
#[derive(Debug)]
#[br(little)]
#[allow(dead_code)] // most of the fields are unused at the moment
struct LgbHeader {
#[br(count = 4)]
file_id: Vec<u8>,
@ -455,6 +456,7 @@ struct LgbHeader {
#[binread]
#[derive(Debug)]
#[br(little)]
#[allow(dead_code)] // most of the fields are unused at the moment
struct LayerChunk {
#[br(count = 4)]
chunk_id: Vec<u8>,
@ -468,6 +470,7 @@ struct LayerChunk {
#[binread]
#[derive(Debug)]
#[br(little)]
#[allow(dead_code)] // most of the fields are unused at the moment
struct InstanceObject {
asset_type: LayerEntryType,
instance_id: u32,
@ -513,7 +516,7 @@ impl Layer {
}
cursor.seek(SeekFrom::Start(old_pos + header.layer_set_referenced_list_offset as u64)).unwrap();
let referenced_list = LayerSetReferencedList::read(&mut cursor).unwrap();
LayerSetReferencedList::read(&mut cursor).unwrap();
for i in 0..header.instance_object_count {
cursor.seek(SeekFrom::Start(old_pos + header.instance_object_offset as u64 + instance_offsets[i as usize] as u64)).unwrap();

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#![allow(clippy::unnecessary_fallible_conversions)] // This wrongly trips on binrw code
use std::io::{Cursor, Seek, SeekFrom};
use std::mem::size_of;
@ -1002,6 +1004,7 @@ impl MDL {
}
}
VertexUsage::Tangent => {
#[allow(clippy::match_single_binding)] // TODO
match element.vertex_type {
/*VertexType::ByteFloat4 => {
MDL::write_tangent(&mut cursor, &vert.binormal).ok()?;

View file

@ -69,6 +69,7 @@ impl MDL {
])
}
#[allow(dead_code)] // We will eventually use this
pub(crate) fn write_half2<T: BinWriterExt>(cursor: &mut T, vec: &[f32; 2]) -> BinResult<()> {
cursor.write_le::<[u16; 2]>(&[
f16::from_f32(vec[0]).to_bits(),

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#![allow(clippy::unnecessary_fallible_conversions)] // This wrongly trips on binrw code
use std::io::Cursor;
use binrw::{BinRead, binrw};
@ -195,11 +197,11 @@ impl Material {
for _ in 0..mat_data.file_header.texture_count {
let mut string = String::new();
let mut next_char = mat_data.strings[offset as usize] as char;
let mut next_char = mat_data.strings[offset] as char;
while next_char != '\0' {
string.push(next_char);
offset += 1;
next_char = mat_data.strings[offset as usize] as char;
next_char = mat_data.strings[offset] as char;
}
texture_paths.push(string);
@ -216,7 +218,7 @@ impl Material {
while next_char != '\0' {
shader_package_name.push(next_char);
offset += 1;
next_char = mat_data.strings[offset as usize] as char;
next_char = mat_data.strings[offset] as char;
}
Some(Material {

View file

@ -464,7 +464,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
fs::create_dir_all(left)?;
let mut new_file =
OpenOptions::new().write(true).create(true).open(filename)?;
OpenOptions::new().write(true).create(true).truncate(false).open(filename)?;
new_file.seek(SeekFrom::Start(add.block_offset as u64))?;
@ -481,7 +481,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
);
let new_file =
OpenOptions::new().write(true).create(true).open(filename)?;
OpenOptions::new().write(true).create(true).truncate(false).open(filename)?;
write_empty_file_block_at(
&new_file,
@ -501,7 +501,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
fs::create_dir_all(left)?;
let new_file =
OpenOptions::new().write(true).create(true).open(filename)?;
OpenOptions::new().write(true).create(true).truncate(false).open(filename)?;
write_empty_file_block_at(
&new_file,
@ -531,6 +531,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
let mut new_file = OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(file_path)?;
if header.header_kind != TargetHeaderKind::Version {
@ -563,6 +564,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
let new_file = OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(&file_path);
if let Ok(mut file) = new_file {

View file

@ -142,11 +142,11 @@ impl Texture {
}
fn decode(src: &[u8], width: usize, height: usize, decode_func: DecodeFunction) -> Vec<u8> {
let mut image: Vec<u32> = vec![0; (width * height) as usize];
let mut image: Vec<u32> = vec![0; width * height];
decode_func(
&src,
width as usize,
height as usize,
src,
width,
height,
&mut image,
)
.unwrap();