This commit is contained in:
Robin Appelman 2023-06-08 18:53:23 +02:00
commit 377e1773c0
14 changed files with 2683 additions and 32 deletions

View file

@ -55,7 +55,7 @@ impl Model {
.body_parts
.iter()
.flat_map(|part| part.models.iter())
.flat_map(|model| model.lods.iter().next())
.flat_map(|model| model.lods.first())
.flat_map(|lod| lod.meshes.iter());
vtx_meshes
@ -81,10 +81,10 @@ impl Model {
}
}
fn read_indexes<'a, I: Iterator<Item = usize> + 'static, T: Readable>(
fn read_indexes<I: Iterator<Item = usize> + 'static, T: Readable>(
indexes: I,
data: &'a [u8],
) -> impl Iterator<Item = Result<T, ModelError>> + 'a {
data: &[u8],
) -> impl Iterator<Item = Result<T, ModelError>> + '_ {
indexes
.map(|index| {
data.get(index..).ok_or_else(|| ModelError::OutOfBounds {

View file

@ -26,7 +26,7 @@ impl Mdl {
body_parts: header
.body_part_indexes()
.map(|index| {
let data = data.get(index..).ok_or_else(|| ModelError::OutOfBounds {
let data = data.get(index..).ok_or(ModelError::OutOfBounds {
data: "BodyPart",
offset: index,
})?;

View file

@ -204,7 +204,7 @@ bitflags! {
impl StudioHeader {
pub fn header2_index(&self) -> Option<usize> {
(self.studio_hdr2_index > 0)
.then(|| self.studio_hdr2_index)
.then_some(self.studio_hdr2_index)
.and_then(|index| usize::try_from(index).ok())
}

View file

@ -32,10 +32,10 @@ impl Vvd {
let fixup = fixup?;
let from = fixup.source_vertex_id as usize;
let to = (fixup.source_vertex_id.saturating_add(fixup.vertex_count)) as usize;
vertices.extend_from_slice(&source_vertices.get(from..to).ok_or_else(|| {
vertices.extend_from_slice(source_vertices.get(from..to).ok_or({
ModelError::OutOfBounds {
data: "source_vertices",
offset: to as usize,
offset: to,
}
})?);
}