Maraiah/src/marathon/phy.rs

115 lines
2.7 KiB
Rust
Raw Normal View History

2019-02-21 12:54:50 -08:00
use crate::{durandal::{bin::*, err::*, fixed::*}};
use bitflags::bitflags;
2019-02-20 20:03:19 -08:00
use serde::Serialize;
pub fn read_pxpx(b: &[u8]) -> ResultS<(Physics, usize)>
{
read_data! {
104, BE in b =>
2019-02-20 20:11:57 -08:00
vel_fwd = Fixed[0];
vel_bkw = Fixed[4];
vel_prp = Fixed[8];
acc_nrm = Fixed[12];
dec_nrm = Fixed[16];
dec_air = Fixed[20];
acc_grv = Fixed[24];
acc_cli = Fixed[28];
vel_trm = Fixed[32];
dec_ext = Fixed[36];
acc_ang = Fixed[40];
dec_ang = Fixed[44];
vel_ang = Fixed[48];
vel_rec = Fixed[52];
fng_vel = Fixed[56];
fng_max = Fixed[60];
ele_max = Fixed[64];
dec_xng = Fixed[68];
stp_dta = Fixed[72];
stp_amp = Fixed[76];
ply_rad = Fixed[80];
ply_hei = Fixed[84];
ply_dhi = Fixed[88];
ply_cam = Fixed[92];
ply_spl = Fixed[96];
ply_hcm = Fixed[100];
2019-02-20 20:03:19 -08:00
}
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))
}
2019-02-21 12:54:50 -08:00
pub fn read_fxpx(b: &[u8]) -> ResultS<(Effect, usize)>
{
read_data! {
14, BE in b =>
collection = u16[0];
shape = u16[2];
pitch = Fixed[4];
flags = u16[8];
2019-02-21 14:11:48 -08:00
delay = OptU16[10];
delay_snd = OptU16[12];
2019-02-21 12:54:50 -08:00
}
2019-02-21 13:12:26 -08:00
let flags = flag_ok!(EffectFlags, flags)?;
2019-02-21 12:54:50 -08:00
Ok((Effect{collection, shape, pitch, flags, delay, delay_snd}, 14))
}
2019-02-20 20:03:19 -08:00
#[derive(Debug, Serialize)]
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,
}
2019-02-21 12:54:50 -08:00
#[derive(Debug, Serialize)]
pub struct Effect
{
pub collection: u16,
pub shape: u16,
pub pitch: Fixed,
pub flags: EffectFlags,
2019-02-21 14:11:48 -08:00
pub delay: OptU16,
pub delay_snd: OptU16,
2019-02-21 12:54:50 -08:00
}
bitflags! {
#[derive(Serialize)]
pub struct EffectFlags: u16
{
const EndOnLoop = 1;
const EndOnXferLoop = 1 << 1;
const SoundOnly = 1 << 2;
const MakeTwinVisible = 1 << 3;
const MediaEffect = 1 << 4;
}
}
2019-02-20 20:03:19 -08:00
// EOF