From 1d057d66afb580a39bbbd6e2c933928426918f42 Mon Sep 17 00:00:00 2001 From: Marrub Date: Sun, 3 Mar 2019 00:44:45 -0500 Subject: [PATCH] some minor things --- source/durandal/bin.rs | 2 +- source/durandal/crc.rs | 2 +- source/durandal/sound.rs | 4 +-- source/marathon/map.rs | 63 +++++++++++++++++++--------------------- source/marathon/pict.rs | 4 +-- source/marathon/shp.rs | 2 +- source/marathon/wad.rs | 2 +- 7 files changed, 38 insertions(+), 41 deletions(-) diff --git a/source/durandal/bin.rs b/source/durandal/bin.rs index 138081c..91197b5 100644 --- a/source/durandal/bin.rs +++ b/source/durandal/bin.rs @@ -206,7 +206,7 @@ pub fn rd_ofstable(b: &[u8], mut p: usize, num: usize, read: F) - -> ResultS> + -> ResultS> where T: Sized, F: Fn(&[u8]) -> ResultS { diff --git a/source/durandal/crc.rs b/source/durandal/crc.rs index 0b0f25b..1e13490 100644 --- a/source/durandal/crc.rs +++ b/source/durandal/crc.rs @@ -13,7 +13,7 @@ fn crc_init() -> [u32; 256] { let mut t = [0; 256]; for (n, v) in t.iter_mut().enumerate() { - *v = (0..8).fold(u32::from(n), crc_accum); + *v = (0..8).fold(n as u32, crc_accum); } t } diff --git a/source/durandal/sound.rs b/source/durandal/sound.rs index 9b0b802..4052598 100644 --- a/source/durandal/sound.rs +++ b/source/durandal/sound.rs @@ -77,7 +77,7 @@ impl Sound16 /// Creates a new `Sound16` from an unsigned 8-bit stream. pub fn new_from_8(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) - -> Self + -> Self { let mut snd = Self::new(rate, lp_beg, lp_end, b.len()); @@ -90,7 +90,7 @@ impl Sound16 /// Creates a new `Sound16` from a signed 16-bit stream. pub fn new_from_16(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) - -> Self + -> Self { let mut snd = Self::new(rate, lp_beg, lp_end, b.len() / 2); diff --git a/source/marathon/map.rs b/source/marathon/map.rs index c4b5283..e05cade 100644 --- a/source/marathon/map.rs +++ b/source/marathon/map.rs @@ -136,13 +136,12 @@ pub fn read_sids(b: &[u8]) -> ResultS<(Side, usize)> /// Reads an old `SIDS` chunk. pub fn read_old_sids(b: &[u8]) -> ResultS<(Side, usize)> { - let (mut side, siz) = read_sids(b)?; + let (side, siz) = read_sids(b)?; - side.tex_tra.tex_id = OptU16::none(); - side.shade = Fixed::from_int(0); - side.flags.insert(SideFlags::ItemOpt); - - Ok((side, siz)) + Ok((Side{tex_tra: SideTex{tex_id: OptU16::none(), ..side.tex_tra}, + shade: 0.into(), + flags: side.flags | SideFlags::ItemOpt, + ..side}, siz)) } /// Reads a `POLY` chunk. @@ -181,26 +180,24 @@ pub fn read_poly(b: &[u8]) -> ResultS<(Polygon, usize)> /// Reads an old `POLY` chunk. pub fn read_old_poly(b: &[u8]) -> ResultS<(Polygon, usize)> { - let (mut poly, siz) = read_poly(b)?; + let (poly, siz) = read_poly(b)?; - poly.ptype = match poly.ptype { - PolyType::Hill => PolyType::OuchMinor, - PolyType::Base => PolyType::OuchMajor, - PolyType::ZoneBorder => PolyType::Glue, - PolyType::Goal => PolyType::GlueTrigger, - PolyType::TrigMonsVis => PolyType::GlueSuper, - PolyType::TrigMonsInv => PolyType::MustExplore, - PolyType::TrigMonsDual => PolyType::AutoExit, - ptype => ptype, - }; - - poly.ori_flr = Point{x: Unit::from_int(0), y: Unit::from_int(0)}; - poly.ori_cei = Point{x: Unit::from_int(0), y: Unit::from_int(0)}; - poly.med_ind = OptU16::none(); - poly.snd_amb = OptU16::none(); - poly.snd_rnd = OptU16::none(); - - Ok((poly, siz)) + Ok((Polygon{ptype: match poly.ptype { + PolyType::Hill => PolyType::OuchMinor, + PolyType::Base => PolyType::OuchMajor, + PolyType::ZoneBorder => PolyType::Glue, + PolyType::Goal => PolyType::GlueTrigger, + PolyType::TrigMonsVis => PolyType::GlueSuper, + PolyType::TrigMonsInv => PolyType::MustExplore, + PolyType::TrigMonsDual => PolyType::AutoExit, + ptype => ptype, + }, + ori_flr: Point{x: 0.into(), y: 0.into()}, + ori_cei: Point{x: 0.into(), y: 0.into()}, + med_ind: OptU16::none(), + snd_amb: OptU16::none(), + snd_rnd: OptU16::none(), + ..poly}, siz)) } /// Reads a `LITE` chunk. @@ -254,12 +251,11 @@ pub fn read_old_lite(b: &[u8]) -> ResultS<(Light, usize)> LightFunc{ftype: func.ftype, prd_nrm: if strobe {prd / 4 + 1} else {func.prd_nrm}, prd_dta: func.prd_dta, - val_nrm: if func.val_nrm > Fixed::from_int(0) {max} else {min}, + val_nrm: if func.val_nrm > 0.into() {max} else {min}, val_dta: func.val_dta} }; - Ok((Light{ltype: lite.ltype, - flags, + Ok((Light{flags, phase, act_pri: old_lfun(&lite.act_pri), act_sec: old_lfun(&lite.act_sec), @@ -267,7 +263,8 @@ pub fn read_old_lite(b: &[u8]) -> ResultS<(Light, usize)> ina_pri: old_lfun(&lite.ina_pri), ina_sec: old_lfun(&lite.ina_sec), ina_mid: old_lfun(&lite.ina_mid), - tag: 0}, 32)) + tag: 0, + ..*lite}, 32)) } /// Reads an `OBJS` chunk. @@ -595,7 +592,7 @@ pub struct Note } /// Static map information. -#[derive(Debug, PartialEq, serde::Serialize)] +#[derive(Debug, Default, PartialEq, serde::Serialize)] pub struct Minf { pub env_code: u16, @@ -639,7 +636,7 @@ bitflags! { bitflags! { /// Static environment flags. - #[derive(serde::Serialize)] + #[derive(Default, serde::Serialize)] pub struct EnvFlags: u16 { const Vacuum = 1; @@ -660,7 +657,7 @@ bitflags! { bitflags! { /// Static entry point flags. - #[derive(serde::Serialize)] + #[derive(Default, serde::Serialize)] pub struct EntFlags: u32 { const Solo = 1; @@ -676,7 +673,7 @@ bitflags! { bitflags! { /// Static mission flags. - #[derive(serde::Serialize)] + #[derive(Default, serde::Serialize)] pub struct MsnFlags: u16 { const Extermination = 1; diff --git a/source/marathon/pict.rs b/source/marathon/pict.rs index 3cf7b7d..999c217 100644 --- a/source/marathon/pict.rs +++ b/source/marathon/pict.rs @@ -7,7 +7,7 @@ fn read_pm_header<'a>(b: &'a [u8], pack: bool, clip: bool, im: &Image8) - -> ResultS<(&'a [u8], Header)> + -> ResultS<(&'a [u8], Header)> { read_data! { 36, BE in b => @@ -185,7 +185,7 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS /// Process a `CopyBits` operation. fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool) - -> ResultS + -> ResultS { let p = if pack {0} else {4}; let (b, hdr) = read_pm_header(&b[p..], pack, clip, &im)?; diff --git a/source/marathon/shp.rs b/source/marathon/shp.rs index 96dd9af..29a8090 100644 --- a/source/marathon/shp.rs +++ b/source/marathon/shp.rs @@ -32,7 +32,7 @@ pub fn color_tables(b: &[u8], tab_ofs: usize, tab_num: usize, clr_num: usize) - -> ResultS>> + -> ResultS>> { let end = tab_num * clr_num * 8; diff --git a/source/marathon/wad.rs b/source/marathon/wad.rs index 681821f..12107b8 100644 --- a/source/marathon/wad.rs +++ b/source/marathon/wad.rs @@ -65,7 +65,7 @@ pub fn read_entries(b: &[u8], siz_app: usize, siz_ent: usize, siz_cnk: usize) - -> ResultS> + -> ResultS> { read_data! { 128, BE in b =>