Skip to content

Commit

Permalink
Add support for v3.16
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCondron committed Feb 9, 2024
1 parent 97d6075 commit 1aa5ed3
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 9 deletions.
6 changes: 5 additions & 1 deletion gen/resources/frames.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@
{ "name": "hitlag", "type": "f32",
"version": "3.8" },
{ "name": "animation_index", "type": "u32",
"version": "3.11" }
"version": "3.11" },
{ "name": "instance_hit_by", "type": "u16",
"version": "3.16" },
{ "name": "instance_id", "type": "u16",
"version": "3.16" }
],
"Start": [
{ "name": "random_seed", "type": "u32" },
Expand Down
6 changes: 6 additions & 0 deletions src/frame/immutable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ pub struct Post {
pub velocities: Option<Velocities>,
pub hitlag: Option<PrimitiveArray<f32>>,
pub animation_index: Option<PrimitiveArray<u32>>,
pub instance_hit_by: Option<PrimitiveArray<u16>>,
pub instance_id: Option<PrimitiveArray<u16>>,
pub validity: Option<Bitmap>,
}

Expand Down Expand Up @@ -336,6 +338,8 @@ impl Post {
.map(|x| x.transpose_one(i, version)),
hitlag: self.hitlag.as_ref().map(|x| x.values()[i]),
animation_index: self.animation_index.as_ref().map(|x| x.values()[i]),
instance_hit_by: self.instance_hit_by.as_ref().map(|x| x.values()[i]),
instance_id: self.instance_id.as_ref().map(|x| x.values()[i]),
}
}
}
Expand Down Expand Up @@ -364,6 +368,8 @@ impl From<mutable::Post> for Post {
velocities: x.velocities.map(|x| x.into()),
hitlag: x.hitlag.map(|x| x.into()),
animation_index: x.animation_index.map(|x| x.into()),
instance_hit_by: x.instance_hit_by.map(|x| x.into()),
instance_id: x.instance_id.map(|x| x.into()),
validity: x.validity.map(|v| v.into()),
}
}
Expand Down
32 changes: 30 additions & 2 deletions src/frame/immutable/peppi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,19 @@ impl Post {
"animation_index",
DataType::UInt32,
false,
))
));
if version.gte(3, 16) {
fields.push(Field::new(
"instance_hit_by",
DataType::UInt16,
false,
));
fields.push(Field::new(
"instance_id",
DataType::UInt16,
false,
))
}
}
}
}
Expand Down Expand Up @@ -570,7 +582,11 @@ impl Post {
if version.gte(3, 8) {
values.push(self.hitlag.unwrap().boxed());
if version.gte(3, 11) {
values.push(self.animation_index.unwrap().boxed())
values.push(self.animation_index.unwrap().boxed());
if version.gte(3, 16) {
values.push(self.instance_hit_by.unwrap().boxed());
values.push(self.instance_id.unwrap().boxed())
}
}
}
}
Expand Down Expand Up @@ -702,6 +718,18 @@ impl Post {
.unwrap()
.clone()
}),
instance_hit_by: values.get(21).map(|x| {
x.as_any()
.downcast_ref::<PrimitiveArray<u16>>()
.unwrap()
.clone()
}),
instance_id: values.get(22).map(|x| {
x.as_any()
.downcast_ref::<PrimitiveArray<u16>>()
.unwrap()
.clone()
}),
validity: validity,
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/frame/immutable/slippi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ impl Post {
if version.gte(3, 8) {
w.write_f32::<BE>(self.hitlag.as_ref().unwrap().value(i))?;
if version.gte(3, 11) {
w.write_u32::<BE>(self.animation_index.as_ref().unwrap().value(i))?
w.write_u32::<BE>(self.animation_index.as_ref().unwrap().value(i))?;
if version.gte(3, 16) {
w.write_u16::<BE>(
self.instance_hit_by.as_ref().unwrap().value(i),
)?;
w.write_u16::<BE>(self.instance_id.as_ref().unwrap().value(i))?
}
}
}
}
Expand Down Expand Up @@ -333,7 +339,11 @@ impl Post {
if version.gte(3, 8) {
size += size_of::<f32>();
if version.gte(3, 11) {
size += size_of::<u32>()
size += size_of::<u32>();
if version.gte(3, 16) {
size += size_of::<u16>();
size += size_of::<u16>()
}
}
}
}
Expand Down
28 changes: 25 additions & 3 deletions src/frame/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ pub struct Post {
pub velocities: Option<Velocities>,
pub hitlag: Option<MutablePrimitiveArray<f32>>,
pub animation_index: Option<MutablePrimitiveArray<u32>>,
pub instance_hit_by: Option<MutablePrimitiveArray<u16>>,
pub instance_id: Option<MutablePrimitiveArray<u16>>,
pub validity: Option<MutableBitmap>,
}

Expand Down Expand Up @@ -451,6 +453,12 @@ impl Post {
animation_index: version
.gte(3, 11)
.then(|| MutablePrimitiveArray::<u32>::with_capacity(capacity)),
instance_hit_by: version
.gte(3, 16)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
instance_id: version
.gte(3, 16)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
validity: None,
}
}
Expand Down Expand Up @@ -490,7 +498,11 @@ impl Post {
if version.gte(3, 8) {
self.hitlag.as_mut().unwrap().push_null();
if version.gte(3, 11) {
self.animation_index.as_mut().unwrap().push_null()
self.animation_index.as_mut().unwrap().push_null();
if version.gte(3, 16) {
self.instance_hit_by.as_mut().unwrap().push_null();
self.instance_id.as_mut().unwrap().push_null()
}
}
}
}
Expand Down Expand Up @@ -534,8 +546,16 @@ impl Post {
r.read_f32::<BE>()
.map(|x| self.hitlag.as_mut().unwrap().push(Some(x)))?;
if version.gte(3, 11) {
r.read_u32::<BE>()
.map(|x| self.animation_index.as_mut().unwrap().push(Some(x)))?
r.read_u32::<BE>().map(|x| {
self.animation_index.as_mut().unwrap().push(Some(x))
})?;
if version.gte(3, 16) {
r.read_u16::<BE>().map(|x| {
self.instance_hit_by.as_mut().unwrap().push(Some(x))
})?;
r.read_u16::<BE>()
.map(|x| self.instance_id.as_mut().unwrap().push(Some(x)))?
}
}
}
}
Expand Down Expand Up @@ -575,6 +595,8 @@ impl Post {
.map(|x| x.transpose_one(i, version)),
hitlag: self.hitlag.as_ref().map(|x| x.values()[i]),
animation_index: self.animation_index.as_ref().map(|x| x.values()[i]),
instance_hit_by: self.instance_hit_by.as_ref().map(|x| x.values()[i]),
instance_id: self.instance_id.as_ref().map(|x| x.values()[i]),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/frame/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub struct Post {
pub velocities: Option<Velocities>,
pub hitlag: Option<f32>,
pub animation_index: Option<u32>,
pub instance_hit_by: Option<u16>,
pub instance_id: Option<u16>,
}

#[derive(PartialEq, Clone, Copy, Debug, Default)]
Expand Down
2 changes: 1 addition & 1 deletion src/io/slippi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use ser::write;
/// We can read replays with higher versions than this, but that discards information.
/// We don't support writing these replays as a result, though this restriction may be
/// relaxed in the future.
pub const MAX_SUPPORTED_VERSION: Version = Version(3, 15, 0);
pub const MAX_SUPPORTED_VERSION: Version = Version(3, 16, 0);

/// Every .slp file will start with a UBJSON opening brace, `raw` key & type: "{U\x03raw[$U#l"
pub const FILE_SIGNATURE: [u8; 11] = [
Expand Down

0 comments on commit 1aa5ed3

Please sign in to comment.