Skip to content

Commit

Permalink
Small fixes and note about how fucked names are
Browse files Browse the repository at this point in the history
  • Loading branch information
widberg committed Oct 11, 2023
1 parent d22aceb commit 6191133
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 28 deletions.
13 changes: 3 additions & 10 deletions bff/src/bigfile/v1_06_63_02_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::names::NameType::Asobo32;
use crate::names::{Name, NameType};
use crate::platforms::Platform;
use crate::traits::BigFileIo;
use crate::versions::{Version, VersionTriple};
use crate::versions::Version;
use crate::BffResult;

#[binrw::parser(reader, endian)]
Expand Down Expand Up @@ -292,11 +292,7 @@ impl BigFileIo for BigFileV1_06_63_02PC {
padded_size,
data_size,
working_buffer_offset,
first_object_name: block
.objects
.first()
.map(|r| r.name)
.unwrap_or(Name::default()),
first_object_name: block.objects.first().map(|r| r.name).unwrap_or_default(),
// TODO: Calculate checksum using Asobo Alternate on the unpadded block while writing
checksum: block.checksum,
});
Expand Down Expand Up @@ -477,10 +473,7 @@ impl BigFileIo for BigFileV1_06_63_02PC {
.iter()
.map(|x| x.padded_size)
.sum::<u32>(),
version_triple: bigfile
.manifest
.version_triple
.unwrap_or(VersionTriple::default()),
version_triple: bigfile.manifest.version_triple.unwrap_or_default(),
block_descriptions,
pool_manifest_padded_size,
pool_offset,
Expand Down
13 changes: 3 additions & 10 deletions bff/src/bigfile/v1_08_40_02_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::names::NameType::Asobo32;
use crate::names::{Name, NameType};
use crate::platforms::Platform;
use crate::traits::BigFileIo;
use crate::versions::{Version, VersionTriple};
use crate::versions::Version;
use crate::{BffResult, Endian};

#[binrw::parser(reader, endian)]
Expand Down Expand Up @@ -236,11 +236,7 @@ impl BigFileIo for BigFileV1_08_40_02PC {
padded_size,
data_size,
working_buffer_offset,
first_object_name: block
.objects
.first()
.map(|r| r.name)
.unwrap_or(Name::default()),
first_object_name: block.objects.first().map(|r| r.name).unwrap_or_default(),
// TODO: Calculate checksum using Asobo Alternate on the unpadded block while writing
checksum: block.checksum,
});
Expand All @@ -253,10 +249,7 @@ impl BigFileIo for BigFileV1_08_40_02PC {
block_working_buffer_capacity_even,
block_working_buffer_capacity_odd,
total_padded_block_size: end as u32 - 2048,
version_triple: bigfile
.manifest
.version_triple
.unwrap_or(VersionTriple::default()),
version_triple: bigfile.manifest.version_triple.unwrap_or_default(),
block_descriptions,
};
header.write_options(writer, endian, ())?;
Expand Down
2 changes: 1 addition & 1 deletion bff/src/bigfile/v1_22_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<const HAS_VERSION_TRIPLE: bool> BigFileIo for BigFileV1_22PC<HAS_VERSION_TR
bigfile
.manifest
.version_triple
.unwrap_or(VersionTriple::default())
.unwrap_or_default()
.write_options(writer, endian, ())?;
writer.seek(SeekFrom::Start(end))?;

Expand Down
4 changes: 1 addition & 3 deletions bff/src/macros/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ macro_rules! classes {
}

pub fn class_names() -> Vec<&'static str> {
let mut names = Vec::new();
$(names.push(<$class as crate::traits::NamedClass<&'static str>>::NAME);)*
names
vec![$(<$class as crate::traits::NamedClass<&'static str>>::NAME,)*]
}
};
}
Expand Down
6 changes: 5 additions & 1 deletion bff/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl Names {
}
}

impl<'a> Default for Names {
impl Default for Names {
fn default() -> Self {
let mut names = Self {
name_type: NameType::Asobo32,
Expand All @@ -291,6 +291,10 @@ impl<'a> Default for Names {
}
}

// TODO: This should NOT be a global. It should be passed around as a parameter to the serialize
// and deserialize functions. Doing that with derive is a bit tricky though.
// https://docs.rs/serde_state/latest/serde_state/ outdated.
// Until this is done bff is not thread safe.
static NAMES: Lazy<Mutex<Names>> = Lazy::new(|| Mutex::new(Names::default()));

pub fn names() -> &'static Mutex<Names> {
Expand Down
5 changes: 2 additions & 3 deletions bff/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ impl ReferencedNames for Name {
}
}

#[impl_for_tuples(12)]
#[impl_for_tuples(1, 12)]
impl ReferencedNames for Tuple {
fn names(&self) -> HashSet<Name> {
let mut names = HashSet::new();
for_tuples!( #( names.extend(&self.Tuple.names()); )* );
#[allow(clippy::let_and_return)]
names
}
}
Expand Down Expand Up @@ -173,7 +172,7 @@ macro_rules! impl_referenced_names {
}
}

impl_referenced_names!(bool, f32, f64, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, String);
impl_referenced_names!((), bool, f32, f64, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, String);

// this should be const https://github.com/rust-lang/rust/issues/67792
pub trait NameHashFunction {
Expand Down

0 comments on commit 6191133

Please sign in to comment.