//! `Physics` type.

use crate::durandal::{err::*, fixed::Fixed};

/// Reads a `PXpx` chunk.
pub fn read(b: &[u8]) -> ResultS<(Physics, usize)>
{
   read_data! {
      endian: BIG, buf: b, size: 104, start: 0, data {
         let vel_fwd = Fixed[0];
         let vel_bkw = Fixed[4];
         let vel_prp = Fixed[8];
         let acc_nrm = Fixed[12];
         let dec_nrm = Fixed[16];
         let dec_air = Fixed[20];
         let acc_grv = Fixed[24];
         let acc_cli = Fixed[28];
         let vel_trm = Fixed[32];
         let dec_ext = Fixed[36];
         let acc_ang = Fixed[40];
         let dec_ang = Fixed[44];
         let vel_ang = Fixed[48];
         let vel_rec = Fixed[52];
         let fng_vel = Fixed[56];
         let fng_max = Fixed[60];
         let ele_max = Fixed[64];
         let dec_xng = Fixed[68];
         let stp_dta = Fixed[72];
         let stp_amp = Fixed[76];
         let ply_rad = Fixed[80];
         let ply_hei = Fixed[84];
         let ply_dhi = Fixed[88];
         let ply_cam = Fixed[92];
         let ply_spl = Fixed[96];
         let ply_hcm = Fixed[100];
      }
   }

   Ok((Physics{acc_ang, acc_cli, acc_grv, acc_nrm, dec_air, dec_ang, dec_ext,
               dec_nrm, dec_xng, ele_max, fng_max, fng_vel, ply_cam, ply_dhi,
               ply_hcm, ply_hei, ply_rad, ply_spl, stp_amp, stp_dta, vel_ang,
               vel_bkw, vel_fwd, vel_prp, vel_rec, vel_trm}, 104))
}

/// Static physics information.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub struct Physics
{
   pub acc_ang: Fixed,
   pub acc_cli: Fixed,
   pub acc_grv: Fixed,
   pub acc_nrm: Fixed,
   pub dec_air: Fixed,
   pub dec_ang: Fixed,
   pub dec_ext: Fixed,
   pub dec_nrm: Fixed,
   pub dec_xng: Fixed,
   pub ele_max: Fixed,
   pub fng_max: Fixed,
   pub fng_vel: Fixed,
   pub ply_cam: Fixed,
   pub ply_dhi: Fixed,
   pub ply_hcm: Fixed,
   pub ply_hei: Fixed,
   pub ply_rad: Fixed,
   pub ply_spl: Fixed,
   pub stp_amp: Fixed,
   pub stp_dta: Fixed,
   pub vel_ang: Fixed,
   pub vel_bkw: Fixed,
   pub vel_fwd: Fixed,
   pub vel_prp: Fixed,
   pub vel_rec: Fixed,
   pub vel_trm: Fixed,
}

// EOF
