Skip to content

Commit

Permalink
Fix LargeWorldCoordinates detection
Browse files Browse the repository at this point in the history
  • Loading branch information
scottanderson authored and localcc committed Dec 17, 2024
1 parent 969c4e3 commit d667bc9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 36 deletions.
15 changes: 0 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,6 @@ pub struct GvasFile {
pub properties: HashableIndexMap<String, Property>,
}

trait GvasHeaderTrait {
fn use_large_world_coordinates(&self) -> bool;
}

impl GvasHeaderTrait for GvasHeader {
fn use_large_world_coordinates(&self) -> bool {
match self {
GvasHeader::Version2 { .. } => false,
GvasHeader::Version3 { .. } => true,
}
}
}

impl GvasFile {
/// Read GvasFile from a binary file
///
Expand Down Expand Up @@ -476,7 +463,6 @@ impl GvasFile {
let mut options = PropertyOptions {
hints,
properties_stack: &mut vec![],
large_world_coordinates: header.use_large_world_coordinates(),
custom_versions: header.get_custom_versions(),
};

Expand Down Expand Up @@ -536,7 +522,6 @@ impl GvasFile {
let mut options = PropertyOptions {
hints: &HashMap::new(),
properties_stack: &mut vec![],
large_world_coordinates: self.header.use_large_world_coordinates(),
custom_versions: self.header.get_custom_versions(),
};

Expand Down
2 changes: 0 additions & 2 deletions src/properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ pub struct PropertyOptions<'a> {
pub properties_stack: &'a mut Vec<String>,
/// Custom versions
pub custom_versions: &'a HashableIndexMap<Guid, u32>,
/// Enables large world coordinates.
pub large_world_coordinates: bool,
}

impl PropertyOptions<'_> {
Expand Down
32 changes: 18 additions & 14 deletions src/properties/struct_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use indexmap::IndexMap;

use crate::{
cursor_ext::{ReadExt, WriteExt},
custom_version::FUE5ReleaseStreamObjectVersion,
error::{DeserializeError, Error, SerializeError},
properties::{name_property::NameProperty, struct_types::LinearColor},
scoped_stack_entry::ScopedStackEntry,
types::map::HashableIndexMap,
types::Guid,
types::{map::HashableIndexMap, Guid},
};

use super::{
Expand Down Expand Up @@ -238,7 +238,8 @@ impl PropertyTrait for StructPropertyValue {
match self {
StructPropertyValue::Vector2F(vector) => {
validate!(
!options.large_world_coordinates,
!options
.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates),
"Vector2F not supported when LWC is enabled, use Vector2D",
);
cursor.write_f32::<LittleEndian>(vector.x.0)?;
Expand All @@ -247,7 +248,7 @@ impl PropertyTrait for StructPropertyValue {
}
StructPropertyValue::Vector2D(vector) => {
validate!(
options.large_world_coordinates,
options.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates),
"Vector2D not supported when LWC is disabled, use Vector2F",
);
cursor.write_f64::<LittleEndian>(vector.x.0)?;
Expand All @@ -256,7 +257,8 @@ impl PropertyTrait for StructPropertyValue {
}
StructPropertyValue::VectorF(vector) => {
validate!(
!options.large_world_coordinates,
!options
.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates),
"VectorF not supported when LWC is enabled, use VectorD",
);
cursor.write_f32::<LittleEndian>(vector.x.0)?;
Expand All @@ -266,7 +268,7 @@ impl PropertyTrait for StructPropertyValue {
}
StructPropertyValue::VectorD(vector) => {
validate!(
options.large_world_coordinates,
options.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates),
"VectorD not supported when LWC is disabled, use VectorF",
);
cursor.write_f64::<LittleEndian>(vector.x.0)?;
Expand All @@ -276,7 +278,8 @@ impl PropertyTrait for StructPropertyValue {
}
StructPropertyValue::RotatorF(rotator) => {
validate!(
!options.large_world_coordinates,
!options
.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates),
"RotatorF not supported when LWC is enabled, use RotatorD",
);
cursor.write_f32::<LittleEndian>(rotator.pitch.0)?;
Expand All @@ -286,7 +289,7 @@ impl PropertyTrait for StructPropertyValue {
}
StructPropertyValue::RotatorD(rotator) => {
validate!(
options.large_world_coordinates,
options.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates),
"RotatorD not supported when LWC is disabled, use RotatorF",
);
cursor.write_f64::<LittleEndian>(rotator.pitch.0)?;
Expand All @@ -296,7 +299,8 @@ impl PropertyTrait for StructPropertyValue {
}
StructPropertyValue::QuatF(quat) => {
validate!(
!options.large_world_coordinates,
!options
.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates),
"QuatF not supported when LWC is enabled, use QuatD",
);
cursor.write_f32::<LittleEndian>(quat.x.0)?;
Expand All @@ -307,7 +311,7 @@ impl PropertyTrait for StructPropertyValue {
}
StructPropertyValue::QuatD(quat) => {
validate!(
options.large_world_coordinates,
options.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates),
"QuatD not supported when LWC is disabled, use QuatF",
);
cursor.write_f64::<LittleEndian>(quat.x.0)?;
Expand Down Expand Up @@ -412,7 +416,7 @@ impl StructPropertyValue {
cursor: &mut R,
options: &mut PropertyOptions,
) -> Result<Self, Error> {
match options.large_world_coordinates {
match options.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates) {
true => Ok(Self::QuatD(QuatD::new(
cursor.read_f64::<LittleEndian>()?,
cursor.read_f64::<LittleEndian>()?,
Expand All @@ -432,7 +436,7 @@ impl StructPropertyValue {
cursor: &mut R,
options: &mut PropertyOptions,
) -> Result<Self, Error> {
match options.large_world_coordinates {
match options.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates) {
true => Ok(Self::RotatorD(RotatorD::new(
cursor.read_f64::<LittleEndian>()?,
cursor.read_f64::<LittleEndian>()?,
Expand All @@ -450,7 +454,7 @@ impl StructPropertyValue {
cursor: &mut R,
options: &mut PropertyOptions,
) -> Result<Self, Error> {
match options.large_world_coordinates {
match options.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates) {
true => Ok(Self::Vector2D(Vector2D::new(
cursor.read_f64::<LittleEndian>()?,
cursor.read_f64::<LittleEndian>()?,
Expand All @@ -466,7 +470,7 @@ impl StructPropertyValue {
cursor: &mut R,
options: &mut PropertyOptions,
) -> Result<Self, Error> {
match options.large_world_coordinates {
match options.supports_version(FUE5ReleaseStreamObjectVersion::LargeWorldCoordinates) {
true => Ok(Self::VectorD(VectorD::new(
cursor.read_f64::<LittleEndian>()?,
cursor.read_f64::<LittleEndian>()?,
Expand Down
3 changes: 0 additions & 3 deletions tests/gvas_tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ fn test_invalid_array_index() {
let mut options = PropertyOptions {
hints: &HashMap::new(),
properties_stack: &mut Vec::new(),
large_world_coordinates: false,
custom_versions: &HashableIndexMap::new(),
};

Expand Down Expand Up @@ -156,7 +155,6 @@ fn test_invalid_terminator() {
let mut options = PropertyOptions {
hints: &HashMap::new(),
properties_stack: &mut Vec::new(),
large_world_coordinates: false,
custom_versions: &HashableIndexMap::new(),
};

Expand Down Expand Up @@ -265,7 +263,6 @@ fn test_invalid_length() {
let mut options = PropertyOptions {
hints: &HashMap::new(),
properties_stack: &mut Vec::new(),
large_world_coordinates: false,
custom_versions: &HashableIndexMap::new(),
};

Expand Down
1 change: 0 additions & 1 deletion tests/gvas_tests/name_arrayindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fn name_property_with_array_index() {
let mut options = PropertyOptions {
hints: &HashMap::new(),
properties_stack: &mut Vec::new(),
large_world_coordinates: false,
custom_versions: &HashableIndexMap::new(),
};
let mut writer = Cursor::new(Vec::new());
Expand Down
1 change: 0 additions & 1 deletion tests/gvas_tests/test_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ macro_rules! test_property {
let mut options = PropertyOptions {
hints: &HashMap::new(),
properties_stack: &mut Vec::new(),
large_world_coordinates: false,
custom_versions: &HashableIndexMap::new(),
};

Expand Down

0 comments on commit d667bc9

Please sign in to comment.