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,
num: usize,
read: F)
-> ResultS<Vec<T>>
-> ResultS<Vec<T>>
where T: Sized,
F: Fn(&[u8]) -> ResultS<T>
{

View File

@ -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
}

View File

@ -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);

View File

@ -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;

View File

@ -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<Image8>
/// Process a `CopyBits` operation.
fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool)
-> ResultS<Image8>
-> ResultS<Image8>
{
let p = if pack {0} else {4};
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_num: usize,
clr_num: usize)
-> ResultS<Vec<Vec<ColorShp>>>
-> ResultS<Vec<Vec<ColorShp>>>
{
let end = tab_num * clr_num * 8;

View File

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