Skip to content

Commit

Permalink
chore: add ci workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Crauzer committed Oct 23, 2024
1 parent 0e28e40 commit 4c5375b
Show file tree
Hide file tree
Showing 25 changed files with 666 additions and 106 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
override: true

- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Check formatting
run: cargo fmt -- --check

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Cargo.lock

# Nix build artifacts/direnv stuff
.direnv
result
result

bin
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ impl Frame {
self.joint_id & 0x3fff
}
pub fn transform_type(&self) -> TransformType {
TransformType::try_from_primitive((self.joint_id >> 14) as u8).expect("invalid transform type")
TransformType::try_from_primitive((self.joint_id >> 14) as u8)
.expect("invalid transform type")
}
}

Expand All @@ -23,4 +24,4 @@ pub enum TransformType {
Rotation = 0,
Translation = 1,
Scale = 2,
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use glam::{Vec3};
use crate::core::animation::{AnimationAsset};
use crate::core::animation::asset::compressed::frame::Frame;
use crate::core::animation::asset::compressed::read::AnimationFlags;
use crate::core::animation::asset::error_metric::ErrorMetric;
use crate::core::animation::AnimationAsset;
use glam::Vec3;

mod frame;
mod read;
mod write;
mod frame;

#[derive(Clone, Debug)]
pub struct Compressed {
Expand Down
22 changes: 8 additions & 14 deletions crates/league-toolkit/src/core/animation/asset/compressed/read.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::io::{Read, Seek, SeekFrom};
use std::mem::size_of;
use bitflags::bitflags;
use byteorder::ReadBytesExt;
use num_enum::{FromPrimitive, IntoPrimitive, TryFromPrimitive};
use crate::core::animation::{asset, Compressed};
use crate::core::animation::asset::compressed::frame::Frame;
use crate::core::animation::asset::error_metric::ErrorMetric;
use crate::core::animation::AssetParseError::{InvalidField, InvalidFileVersion, MissingData};
use crate::util::ReaderExt;
use crate::core::animation::{asset, Compressed};
use bitflags::bitflags;
use std::io::{Read, Seek, SeekFrom};
use std::mem::size_of;

bitflags! {
#[derive(Clone, Debug)]
Expand All @@ -31,7 +28,6 @@ impl Compressed {
return Err(InvalidFileVersion(version));
}


let resource_size = reader.read_u32::<LE>()?;
let format_token = reader.read_u32::<LE>()?;
let flags = reader.read_u32::<LE>()?;
Expand Down Expand Up @@ -87,9 +83,7 @@ impl Compressed {
if align_of > 0 && (p & (align_of - 1)) != 0 {
panic!("bad alignment!");
}
let frame = unsafe {
std::mem::transmute::<_, Frame>(frame)
};
let frame = unsafe { std::mem::transmute::<_, Frame>(frame) };
frames.push(frame);
}

Expand All @@ -99,10 +93,10 @@ impl Compressed {
true => 24,
false => 48,
};
let mut jump_caches = Vec::with_capacity(jump_cache_count as usize * jump_frame_size * joint_count as usize);
let mut jump_caches =
Vec::with_capacity(jump_cache_count as usize * jump_frame_size * joint_count as usize);
reader.read_exact(&mut jump_caches)?;


Ok(Self {
flags,
duration,
Expand All @@ -120,4 +114,4 @@ impl Compressed {
joints,
})
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::io::{Write};
use crate::core::animation;
use crate::core::animation::Compressed;
use std::io::Write;

impl Compressed {
pub fn to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> animation::Result<()> {
use byteorder::{LE, WriteBytesExt as _};
use crate::util::WriterExt as _;
unimplemented!("TODO: animation::asset::Compressed writing");
}
}
}
14 changes: 10 additions & 4 deletions crates/league-toolkit/src/core/animation/asset/error_metric.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use byteorder::{ReadBytesExt, LE};
use std::io;
use std::io::Read;
use byteorder::{LE, ReadBytesExt};

// Represents the optimization settings of a transform component
#[derive(Clone, Debug)]
Expand All @@ -22,10 +22,16 @@ impl Default for ErrorMetric {

impl ErrorMetric {
pub fn new(margin: f32, discontinuity_threshold: f32) -> Self {
Self { margin, discontinuity_threshold }
Self {
margin,
discontinuity_threshold,
}
}

pub fn from_reader<R: Read + ?Sized>(reader: &mut R) -> io::Result<Self> {
Ok(Self::new(reader.read_f32::<LE>()?, reader.read_f32::<LE>()?))
Ok(Self::new(
reader.read_f32::<LE>()?,
reader.read_f32::<LE>()?,
))
}
}
}
13 changes: 8 additions & 5 deletions crates/league-toolkit/src/core/animation/asset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ mod error_metric;

pub use error::*;

use error::AssetParseError::UnknownAssetType;
use std::io;
use std::io::{Read, Seek, SeekFrom};
use error::AssetParseError::UnknownAssetType;
use crate::util::ReaderExt;

#[derive(Clone, Debug)]
pub enum AnimationAsset {
Expand All @@ -35,20 +34,24 @@ impl AnimationAsset {
let asset_type = Self::identify_from_reader(reader)?;
reader.seek(SeekFrom::Start(0))?;
match asset_type {
AnimationAssetType::Uncompressed => Uncompressed::from_reader(reader).map(Self::Uncompressed),
AnimationAssetType::Uncompressed => {
Uncompressed::from_reader(reader).map(Self::Uncompressed)
}
AnimationAssetType::Compressed => Compressed::from_reader(reader).map(Self::Compressed),
AnimationAssetType::Unknown => Err(UnknownAssetType),
}
}

pub fn identify_from_reader<R: Read + ?Sized>(reader: &mut R) -> io::Result<AnimationAssetType> {
pub fn identify_from_reader<R: Read + ?Sized>(
reader: &mut R,
) -> io::Result<AnimationAssetType> {
let mut magic = [0_u8; 8];
reader.read_exact(&mut magic)?;

Ok(match &magic {
b"r3d2anmd" => AnimationAssetType::Uncompressed,
b"r3d2canm" => AnimationAssetType::Compressed,
_ => AnimationAssetType::Unknown
_ => AnimationAssetType::Unknown,
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ impl Into<AnimationAsset> for Uncompressed {
fn into(self) -> AnimationAsset {
AnimationAsset::Uncompressed(self)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::io::Read;
use crate::core::animation::{asset, Uncompressed};
use std::io::Read;

impl Uncompressed {
pub fn from_reader<R: Read + ?Sized>(reader: &mut R) -> asset::Result<Self> {
use crate::util::ReaderExt as _;
use byteorder::{ReadBytesExt as _, LE};
unimplemented!("TODO: animation::asset::Uncompressed reading");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::io::{Write};
use crate::core::animation;
use crate::core::animation::Uncompressed;
use std::io::Write;

impl Uncompressed {
pub fn to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> animation::Result<()> {
use byteorder::{LE, WriteBytesExt as _};
use crate::util::WriterExt as _;
unimplemented!("TODO: animation::asset::Uncompressed writing");
}
}
}
2 changes: 1 addition & 1 deletion crates/league-toolkit/src/core/animation/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ pub enum ParseError {
Utf8Error(#[from] std::str::Utf8Error),
}

pub type Result<T> = core::result::Result<T, ParseError>;
pub type Result<T> = core::result::Result<T, ParseError>;
6 changes: 1 addition & 5 deletions crates/league-toolkit/src/core/animation/joint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::io::{Read, Seek};
use byteorder::ReadBytesExt;
use glam::{Mat4, Quat, Vec3};
use crate::util::ReaderExt;

mod builder;
pub mod legacy;
mod read;
mod write;
mod builder;

pub use builder::Builder;

Expand All @@ -25,7 +22,6 @@ pub struct Joint {
inverse_bind_translation: Vec3,
inverse_bind_scale: Vec3,
inverse_bind_rotation: Quat,

}

impl Joint {
Expand Down
6 changes: 2 additions & 4 deletions crates/league-toolkit/src/core/animation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ pub mod error;

pub use error::*;

pub mod rig;
pub mod asset;
pub mod rig;

pub use asset::{AnimationAsset, AnimationAssetType, AssetParseError, Uncompressed, Compressed};
pub use asset::{AnimationAsset, AnimationAssetType, AssetParseError, Compressed, Uncompressed};

pub use rig::*;


Loading

0 comments on commit 4c5375b

Please sign in to comment.