some minor things

png-branch
an 2019-03-03 00:44:45 -05:00
parent 4570d494ad
commit 1d057d66af
7 changed files with 38 additions and 41 deletions

View File

@ -206,7 +206,7 @@ pub fn rd_ofstable<T, F>(b: &[u8],
mut p: usize, mut p: usize,
num: usize, num: usize,
read: F) read: F)
-> ResultS<Vec<T>> -> ResultS<Vec<T>>
where T: Sized, where T: Sized,
F: Fn(&[u8]) -> ResultS<T> F: Fn(&[u8]) -> ResultS<T>
{ {

View File

@ -13,7 +13,7 @@ fn crc_init() -> [u32; 256]
{ {
let mut t = [0; 256]; let mut t = [0; 256];
for (n, v) in t.iter_mut().enumerate() { 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 t
} }

View File

@ -77,7 +77,7 @@ impl Sound16
/// Creates a new `Sound16` from an unsigned 8-bit stream. /// 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]) 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()); 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. /// 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]) 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); let mut snd = Self::new(rate, lp_beg, lp_end, b.len() / 2);

View File

@ -136,13 +136,12 @@ pub fn read_sids(b: &[u8]) -> ResultS<(Side, usize)>
/// Reads an old `SIDS` chunk. /// Reads an old `SIDS` chunk.
pub fn read_old_sids(b: &[u8]) -> ResultS<(Side, usize)> 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(); Ok((Side{tex_tra: SideTex{tex_id: OptU16::none(), ..side.tex_tra},
side.shade = Fixed::from_int(0); shade: 0.into(),
side.flags.insert(SideFlags::ItemOpt); flags: side.flags | SideFlags::ItemOpt,
..side}, siz))
Ok((side, siz))
} }
/// Reads a `POLY` chunk. /// Reads a `POLY` chunk.
@ -181,26 +180,24 @@ pub fn read_poly(b: &[u8]) -> ResultS<(Polygon, usize)>
/// Reads an old `POLY` chunk. /// Reads an old `POLY` chunk.
pub fn read_old_poly(b: &[u8]) -> ResultS<(Polygon, usize)> 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 { Ok((Polygon{ptype: match poly.ptype {
PolyType::Hill => PolyType::OuchMinor, PolyType::Hill => PolyType::OuchMinor,
PolyType::Base => PolyType::OuchMajor, PolyType::Base => PolyType::OuchMajor,
PolyType::ZoneBorder => PolyType::Glue, PolyType::ZoneBorder => PolyType::Glue,
PolyType::Goal => PolyType::GlueTrigger, PolyType::Goal => PolyType::GlueTrigger,
PolyType::TrigMonsVis => PolyType::GlueSuper, PolyType::TrigMonsVis => PolyType::GlueSuper,
PolyType::TrigMonsInv => PolyType::MustExplore, PolyType::TrigMonsInv => PolyType::MustExplore,
PolyType::TrigMonsDual => PolyType::AutoExit, PolyType::TrigMonsDual => PolyType::AutoExit,
ptype => ptype, ptype => ptype,
}; },
ori_flr: Point{x: 0.into(), y: 0.into()},
poly.ori_flr = Point{x: Unit::from_int(0), y: Unit::from_int(0)}; ori_cei: Point{x: 0.into(), y: 0.into()},
poly.ori_cei = Point{x: Unit::from_int(0), y: Unit::from_int(0)}; med_ind: OptU16::none(),
poly.med_ind = OptU16::none(); snd_amb: OptU16::none(),
poly.snd_amb = OptU16::none(); snd_rnd: OptU16::none(),
poly.snd_rnd = OptU16::none(); ..poly}, siz))
Ok((poly, siz))
} }
/// Reads a `LITE` chunk. /// Reads a `LITE` chunk.
@ -254,12 +251,11 @@ pub fn read_old_lite(b: &[u8]) -> ResultS<(Light, usize)>
LightFunc{ftype: func.ftype, LightFunc{ftype: func.ftype,
prd_nrm: if strobe {prd / 4 + 1} else {func.prd_nrm}, prd_nrm: if strobe {prd / 4 + 1} else {func.prd_nrm},
prd_dta: func.prd_dta, 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} val_dta: func.val_dta}
}; };
Ok((Light{ltype: lite.ltype, Ok((Light{flags,
flags,
phase, phase,
act_pri: old_lfun(&lite.act_pri), act_pri: old_lfun(&lite.act_pri),
act_sec: old_lfun(&lite.act_sec), 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_pri: old_lfun(&lite.ina_pri),
ina_sec: old_lfun(&lite.ina_sec), ina_sec: old_lfun(&lite.ina_sec),
ina_mid: old_lfun(&lite.ina_mid), ina_mid: old_lfun(&lite.ina_mid),
tag: 0}, 32)) tag: 0,
..*lite}, 32))
} }
/// Reads an `OBJS` chunk. /// Reads an `OBJS` chunk.
@ -595,7 +592,7 @@ pub struct Note
} }
/// Static map information. /// Static map information.
#[derive(Debug, PartialEq, serde::Serialize)] #[derive(Debug, Default, PartialEq, serde::Serialize)]
pub struct Minf pub struct Minf
{ {
pub env_code: u16, pub env_code: u16,
@ -639,7 +636,7 @@ bitflags! {
bitflags! { bitflags! {
/// Static environment flags. /// Static environment flags.
#[derive(serde::Serialize)] #[derive(Default, serde::Serialize)]
pub struct EnvFlags: u16 pub struct EnvFlags: u16
{ {
const Vacuum = 1; const Vacuum = 1;
@ -660,7 +657,7 @@ bitflags! {
bitflags! { bitflags! {
/// Static entry point flags. /// Static entry point flags.
#[derive(serde::Serialize)] #[derive(Default, serde::Serialize)]
pub struct EntFlags: u32 pub struct EntFlags: u32
{ {
const Solo = 1; const Solo = 1;
@ -676,7 +673,7 @@ bitflags! {
bitflags! { bitflags! {
/// Static mission flags. /// Static mission flags.
#[derive(serde::Serialize)] #[derive(Default, serde::Serialize)]
pub struct MsnFlags: u16 pub struct MsnFlags: u16
{ {
const Extermination = 1; const Extermination = 1;

View File

@ -7,7 +7,7 @@ fn read_pm_header<'a>(b: &'a [u8],
pack: bool, pack: bool,
clip: bool, clip: bool,
im: &Image8) im: &Image8)
-> ResultS<(&'a [u8], Header)> -> ResultS<(&'a [u8], Header)>
{ {
read_data! { read_data! {
36, BE in b => 36, BE in b =>
@ -185,7 +185,7 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
/// Process a `CopyBits` operation. /// Process a `CopyBits` operation.
fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool) fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool)
-> ResultS<Image8> -> ResultS<Image8>
{ {
let p = if pack {0} else {4}; let p = if pack {0} else {4};
let (b, hdr) = read_pm_header(&b[p..], pack, clip, &im)?; let (b, hdr) = read_pm_header(&b[p..], pack, clip, &im)?;

View File

@ -32,7 +32,7 @@ pub fn color_tables(b: &[u8],
tab_ofs: usize, tab_ofs: usize,
tab_num: usize, tab_num: usize,
clr_num: usize) clr_num: usize)
-> ResultS<Vec<Vec<ColorShp>>> -> ResultS<Vec<Vec<ColorShp>>>
{ {
let end = tab_num * clr_num * 8; let end = tab_num * clr_num * 8;

View File

@ -65,7 +65,7 @@ pub fn read_entries(b: &[u8],
siz_app: usize, siz_app: usize,
siz_ent: usize, siz_ent: usize,
siz_cnk: usize) siz_cnk: usize)
-> ResultS<BTreeMap<u16, Entry>> -> ResultS<BTreeMap<u16, Entry>>
{ {
read_data! { read_data! {
128, BE in b => 128, BE in b =>