Skip to content

Commit

Permalink
Lets not duplicate the Keyframer structs in every file that uses them
Browse files Browse the repository at this point in the history
  • Loading branch information
widberg committed Sep 25, 2023
1 parent 0ca65e0 commit d8ef812
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 336 deletions.
77 changes: 5 additions & 72 deletions bff/src/class/animation/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
@@ -1,85 +1,18 @@
use binrw::BinRead;
use serde::Serialize;
use serde_big_array::BigArray;
use crate::keyframer::{KeyframerFloatComp, KeyframerVec3fComp, KeyframerMessage, KeyframerRot, KeyframerBezierRot};

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::name::Name;

#[derive(BinRead, Debug, Serialize)]
struct RotFrame {
time: f32,
rot: [i16; 4],
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerRot {
rot_frames: DynArray<RotFrame>,
}

#[derive(BinRead, Debug, Serialize)]
struct BezierRotFrame {
time: f32,
#[serde(with = "BigArray")]
data: [u8; 36],
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerBezierRot {
bezier_rot_frames: DynArray<BezierRotFrame>,
}

#[derive(BinRead, Debug, Serialize)]
struct Vec3CompFrame {
time: f32,
i16s: [i16; 10],
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerVec3Comp {
unknown: u16,
vec3_comp_frames: DynArray<Vec3CompFrame>,
}

#[derive(BinRead, Debug, Serialize)]
struct FloatCompFrame {
time: f32,
i16s: [i16; 4],
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerFloatComp {
unknown: u16,
float_comp_frames: DynArray<FloatCompFrame>,
}

#[derive(BinRead, Debug, Serialize)]
struct Message {
unknown0: u32,
unknown1: u32,
unknown2: u32,
unknown3: f32,
crc32: Name,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyMessage {
time: f32,
messages: DynArray<Message>,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerMessage {
key_messages: DynArray<KeyMessage>,
}

#[derive(BinRead, Debug, Serialize)]
struct AnimationNode {
unknown: u16,
keyframer_rot: KeyframerRot,
keyframer_bezier_rot: KeyframerBezierRot,
keyframer_scale: KeyframerVec3Comp,
keyframer_translation: KeyframerVec3Comp,
keyframer_scale: KeyframerVec3fComp,
keyframer_translation: KeyframerVec3fComp,
keyframer_message: KeyframerMessage,
}

Expand All @@ -104,8 +37,8 @@ struct AnimationNodeModifier {
struct AnimationMaterial {
keyframer_float_comp0: KeyframerFloatComp,
keyframer_float_comp1: KeyframerFloatComp,
keyframer_vec3_comp0: KeyframerVec3Comp,
keyframer_vec3_comp1: KeyframerVec3Comp,
keyframer_vec3_comp0: KeyframerVec3fComp,
keyframer_vec3_comp1: KeyframerVec3fComp,
keyframer_float_comp2: KeyframerFloatComp,
}

Expand Down
75 changes: 1 addition & 74 deletions bff/src/class/animation/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,8 @@ use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::{NumeratorFloat, Vec3f};
use crate::name::Name;

type KeyframerRot = KeyframerNoFlagsTpl<KeyRot>;
type KeyframerBezierRot = KeyframerNoFlagsTpl<KeyBezierRot>;
type KeyRot = KeyLinearTpl<QuatComp>;
type KeyBezierRot = KeyTgtTpl<Vec3f>;
type QuatComp = [NumeratorFloat<i16, 2000>; 4];
type Vec3Comp = [NumeratorFloat<i16, 4096>; 3];
type KeyVec3fComp = KeyTgtTpl<Vec3Comp>;
type KeyframerVec3fComp = KeyframerTpl<KeyVec3fComp>;
type KeyframerMessage = KeyframerNoFlagsTpl<KeyMessage>;
type KeyMessage = KeyLinearTpl<DynArray<Message>>;
type KeyframerFloatComp = KeyframerTpl<KeyFloatComp>;
type KeyFloatComp = KeyTgtTpl<i16>;

#[derive(BinRead, Debug, Serialize)]
struct Message {
message_class: u32,
reciever_name: Name,
c: u32,
parameter: f32,
message_name: Name,
}

#[derive(BinRead, Debug, Serialize)]
#[br(repr = u16)]
enum KeyframerInterpolationType {
Smooth = 0x01,
Linear = 0x02,
Square = 0x03,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerTpl<TKey>
where
for<'a> TKey: BinRead + Serialize + 'a,
for<'a> <TKey as BinRead>::Args<'a>: Clone + Default,
{
interpolation_type: KeyframerInterpolationType,
keyframes: DynArray<TKey>,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerNoFlagsTpl<TKey>
where
for<'a> TKey: BinRead + Serialize + 'a,
for<'a> <TKey as BinRead>::Args<'a>: Clone + Default,
{
keyframes: DynArray<TKey>,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyTgtTpl<T>
where
for<'a> T: BinRead + Serialize + 'a,
for<'a> <T as BinRead>::Args<'a>: Clone + Default,
{
time: f32,
value: T,
tangent_in: T,
#[br(align_after = 4)]
tangent_out: T,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyLinearTpl<T>
where
for<'a> T: BinRead + Serialize + 'a,
for<'a> <T as BinRead>::Args<'a>: Clone + Default,
{
time: f32,
#[br(align_after = 4)]
value: T,
}
use crate::keyframer::{KeyframerFloatComp, KeyframerVec3fComp, KeyframerMessage, KeyframerRot, KeyframerBezierRot};

#[derive(BinRead, Debug, Serialize)]
struct AnimationNode {
Expand Down
76 changes: 1 addition & 75 deletions bff/src/class/material_anim/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,8 @@ use serde::ser::SerializeStruct;
use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::{Vec2f, Vec3f, Vec4f};
use crate::name::Name;

type KeyFlag = KeyLinearTpl<u32>;
type KeyHdl = KeyLinearTpl<Name>;
type KeyFloatLinearComp = KeyLinearTpl<i16>;
type KeyVec2fLinear = KeyLinearTpl<Vec2f>;
type KeyVec3fLinear = KeyLinearTpl<Vec3f>;
type KeyVec4fLinear = KeyLinearTpl<Vec4f>;
type KeyframerFlag = KeyframerNoFlagsTpl<KeyFlag>;
type KeyframerHdl = KeyframerNoFlagsTpl<KeyHdl>;
type KeyframerFloatLinearComp = KeyframerTpl<KeyFloatLinearComp>;
type KeyframerVec2fLinear = KeyframerTpl<KeyVec2fLinear>;
type KeyframerVec3fLinear = KeyframerTpl<KeyVec3fLinear>;
type KeyframerVec4fLinear = KeyframerTpl<KeyVec4fLinear>;

#[derive(BinRead, Debug, Serialize)]
struct Message {
message_class: u32,
reciever_name: Name,
c: u32,
parameter: f32,
message_name: Name,
}

#[derive(BinRead, Debug, Serialize)]
#[br(repr = u16)]
enum KeyframerInterpolationType {
Smooth = 0x01,
Linear = 0x02,
Square = 0x03,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerTpl<TKey>
where
for<'a> TKey: BinRead + Serialize + 'a,
for<'a> <TKey as BinRead>::Args<'a>: Clone + Default,
{
interpolation_type: KeyframerInterpolationType,
keyframes: DynArray<TKey>,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerNoFlagsTpl<TKey>
where
for<'a> TKey: BinRead + Serialize + 'a,
for<'a> <TKey as BinRead>::Args<'a>: Clone + Default,
{
keyframes: DynArray<TKey>,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyTgtTpl<T>
where
for<'a> T: BinRead + Serialize + 'a,
for<'a> <T as BinRead>::Args<'a>: Clone + Default,
{
time: f32,
value: T,
tangent_in: T,
#[br(align_after = 4)]
tangent_out: T,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyLinearTpl<T>
where
for<'a> T: BinRead + Serialize + 'a,
for<'a> <T as BinRead>::Args<'a>: Clone + Default,
{
time: f32,
#[br(align_after = 4)]
value: T,
}
use crate::keyframer::{KeyframerFlag, KeyframerFloatLinearComp, KeyframerHdl, KeyframerVec2fLinear, KeyframerVec3fLinear, KeyframerVec4fLinear};

#[serialize_bits]
#[bitsize(8)]
Expand Down
41 changes: 2 additions & 39 deletions bff/src/class/particles/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,9 @@ use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::{Mat4f, Quat, Vec2f, Vec3f, Vec4f};
use crate::math::{Mat4f, Quat, Vec3f};
use crate::name::Name;

type KeyFloatLinear = KeyLinearTpl<f32>;
type KeyVec2fLinear = KeyLinearTpl<Vec2f>;
type KeyVec3fLinear = KeyLinearTpl<Vec3f>;
type KeyVec4fLinear = KeyLinearTpl<Vec4f>;
type KeyframerFloatLinear = KeyframerTpl<KeyFloatLinear>;
type KeyframerVec2fLinear = KeyframerTpl<KeyVec2fLinear>;
type KeyframerVec3fLinear = KeyframerTpl<KeyVec3fLinear>;
type KeyframerVec4fLinear = KeyframerTpl<KeyVec4fLinear>;

#[derive(BinRead, Debug, Serialize)]
struct KeyLinearTpl<T>
where
for<'a> T: BinRead + Serialize + 'a,
for<'a> <T as BinRead>::Args<'a>: Clone + Default,
{
time: f32,
#[br(align_after = 4)]
value: T,
}

#[derive(BinRead, Debug, Serialize)]
#[br(repr = u16)]
enum KeyframerInterpolationType {
Smooth = 0x01,
Linear = 0x02,
Square = 0x03,
}

#[derive(BinRead, Debug, Serialize)]
struct KeyframerTpl<TKey>
where
for<'a> TKey: BinRead + Serialize + 'a,
for<'a> <TKey as BinRead>::Args<'a>: Clone + Default,
{
interpolation_type: KeyframerInterpolationType,
keyframes: DynArray<TKey>,
}
use crate::keyframer::{KeyframerFloatLinear, KeyframerVec2fLinear, KeyframerVec3fLinear, KeyframerVec4fLinear};

#[serialize_bits]
#[bitsize(32)]
Expand Down
Loading

0 comments on commit d8ef812

Please sign in to comment.