clippy saves the world, part 2
parent
d4be08c9e5
commit
d5c273687f
|
@ -1 +1,2 @@
|
||||||
single-char-binding-names-threshold = 10
|
single-char-binding-names-threshold = 10
|
||||||
|
doc-valid-idents = ["QuickDraw"]
|
||||||
|
|
|
@ -157,12 +157,12 @@ pub fn rd_ofstable<T, F>(b: &[u8],
|
||||||
impl OptU16
|
impl OptU16
|
||||||
{
|
{
|
||||||
/// Creates an `OptU16` from a `u16`.
|
/// Creates an `OptU16` from a `u16`.
|
||||||
pub fn from_repr(n: u16) -> OptU16
|
pub fn from_repr(n: u16) -> Self
|
||||||
{
|
{
|
||||||
if n == u16::max_value() {
|
if n == u16::max_value() {
|
||||||
OptU16(None)
|
Self(None)
|
||||||
} else {
|
} else {
|
||||||
OptU16(NonZeroU16::new(n + 1))
|
Self(NonZeroU16::new(n + 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ impl OptU16
|
||||||
|
|
||||||
impl fmt::Debug for OptU16
|
impl fmt::Debug for OptU16
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
match self.get() {
|
match self.get() {
|
||||||
None => write!(f, "None"),
|
None => write!(f, "None"),
|
||||||
|
|
|
@ -20,7 +20,7 @@ macro_rules! c_enum
|
||||||
|
|
||||||
impl $E
|
impl $E
|
||||||
{
|
{
|
||||||
pub fn from_repr(n: $T) -> Result<$E, ReprError>
|
$V fn from_repr(n: $T) -> Result<$E, ReprError>
|
||||||
{
|
{
|
||||||
match n {
|
match n {
|
||||||
$($value => Ok($E::$Enum),)+
|
$($value => Ok($E::$Enum),)+
|
||||||
|
@ -38,7 +38,7 @@ mod test
|
||||||
|
|
||||||
c_enum! {
|
c_enum! {
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum TestEnum: u16
|
enum TestEnum: u16
|
||||||
{
|
{
|
||||||
0 => Zero,
|
0 => Zero,
|
||||||
1 => One,
|
1 => One,
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl Fail for ErrMsg {}
|
||||||
|
|
||||||
impl fmt::Display for ReprError
|
impl fmt::Display for ReprError
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
write!(f, "representation error (got {})", self.0)
|
write!(f, "representation error (got {})", self.0)
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ impl fmt::Display for ReprError
|
||||||
|
|
||||||
impl fmt::Debug for ReprError
|
impl fmt::Debug for ReprError
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
fmt::Display::fmt(self, f)
|
fmt::Display::fmt(self, f)
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,12 @@ impl fmt::Debug for ReprError
|
||||||
|
|
||||||
impl fmt::Display for ErrMsg
|
impl fmt::Display for ErrMsg
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {f.write_str(self.0)}
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {f.write_str(self.0)}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ErrMsg
|
impl fmt::Debug for ErrMsg
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
fmt::Display::fmt(self, f)
|
fmt::Display::fmt(self, f)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ use std::fs;
|
||||||
pub fn validate_folder_path(p: &str) -> ResultS<()>
|
pub fn validate_folder_path(p: &str) -> ResultS<()>
|
||||||
{
|
{
|
||||||
let at = fs::metadata(p)?;
|
let at = fs::metadata(p)?;
|
||||||
if !at.is_dir() {
|
if at.is_dir() {
|
||||||
Err(err_msg("not a directory"))
|
|
||||||
} else {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(err_msg("not a directory"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ macro_rules! define_fixed_type {
|
||||||
pub fn set_bits(&mut self, bits: $UT) {self.0 = bits as $IT}
|
pub fn set_bits(&mut self, bits: $UT) {self.0 = bits as $IT}
|
||||||
pub const fn from_bits(bits: $UT) -> Self {$Type(bits as $IT)}
|
pub const fn from_bits(bits: $UT) -> Self {$Type(bits as $IT)}
|
||||||
pub fn integ(&self) -> $LT {(self.0 >> Self::FRACBITS) as $LT}
|
pub fn integ(&self) -> $LT {(self.0 >> Self::FRACBITS) as $LT}
|
||||||
|
#[allow(trivial_numeric_casts)]
|
||||||
pub fn fract(&self) -> u16 {(self.0 as $UT & Self::FRACMASK) as u16}
|
pub fn fract(&self) -> u16 {(self.0 as $UT & Self::FRACMASK) as u16}
|
||||||
pub fn mul_i(&self, n: $LT) -> Self {$Type(self.0 * $IT::from(n))}
|
pub fn mul_i(&self, n: $LT) -> Self {$Type(self.0 * $IT::from(n))}
|
||||||
pub fn div_i(&self, n: $LT) -> Self {$Type(self.0 / $IT::from(n))}
|
pub fn div_i(&self, n: $LT) -> Self {$Type(self.0 / $IT::from(n))}
|
||||||
|
@ -85,7 +86,7 @@ macro_rules! define_fixed_type {
|
||||||
|
|
||||||
impl fmt::Display for $Type
|
impl fmt::Display for $Type
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
let prec = f.precision().unwrap_or(1);
|
let prec = f.precision().unwrap_or(1);
|
||||||
let widt = f.width().unwrap_or(0);
|
let widt = f.width().unwrap_or(0);
|
||||||
|
@ -106,7 +107,7 @@ macro_rules! define_fixed_type {
|
||||||
|
|
||||||
impl fmt::Debug for $Type
|
impl fmt::Debug for $Type
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
fmt::Display::fmt(self, f)
|
fmt::Display::fmt(self, f)
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub trait Image
|
||||||
fn get(&self, x: usize, y: usize) -> Option<&Self::Output>
|
fn get(&self, x: usize, y: usize) -> Option<&Self::Output>
|
||||||
{
|
{
|
||||||
if x < self.w() && y < self.h() {
|
if x < self.w() && y < self.h() {
|
||||||
Some(&self.index(x, y))
|
Some(self.index(x, y))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ impl Image for Image8
|
||||||
|
|
||||||
impl Color16
|
impl Color16
|
||||||
{
|
{
|
||||||
pub const fn new(r: u16, g: u16, b: u16) -> Color16 {Color16(r, g, b)}
|
pub const fn new(r: u16, g: u16, b: u16) -> Self {Self(r, g, b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Color for Color16
|
impl Color for Color16
|
||||||
|
@ -155,7 +155,7 @@ impl Color for Color16
|
||||||
|
|
||||||
impl Color8
|
impl Color8
|
||||||
{
|
{
|
||||||
pub const fn new(r: u8, g: u8, b: u8) -> Color8 {Color8(r, g, b)}
|
pub const fn new(r: u8, g: u8, b: u8) -> Self {Self(r, g, b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Color for Color8
|
impl Color for Color8
|
||||||
|
|
|
@ -7,11 +7,11 @@ pub fn write_wav(out: &mut impl io::Write, snd: &impl Sound) -> ResultS<()>
|
||||||
{
|
{
|
||||||
let rate = u32::from(snd.rate());
|
let rate = u32::from(snd.rate());
|
||||||
let bps = rate * 2;
|
let bps = rate * 2;
|
||||||
let ssize = snd.len() as u32 * 2;
|
let dat_size = snd.len() as u32 * 2;
|
||||||
let fsize = 36 + ssize;
|
let hdr_size = 36 + dat_size;
|
||||||
|
|
||||||
out.write_all(b"RIFF")?;
|
out.write_all(b"RIFF")?;
|
||||||
out.write_all(&u32::to_le_bytes(fsize))?;
|
out.write_all(&u32::to_le_bytes(hdr_size))?;
|
||||||
out.write_all(b"WAVE")?;
|
out.write_all(b"WAVE")?;
|
||||||
out.write_all(b"fmt ")?;
|
out.write_all(b"fmt ")?;
|
||||||
out.write_all(&u32::to_le_bytes(16))?;
|
out.write_all(&u32::to_le_bytes(16))?;
|
||||||
|
@ -22,7 +22,7 @@ pub fn write_wav(out: &mut impl io::Write, snd: &impl Sound) -> ResultS<()>
|
||||||
out.write_all(&u16::to_le_bytes(2))?; // block alignment
|
out.write_all(&u16::to_le_bytes(2))?; // block alignment
|
||||||
out.write_all(&u16::to_le_bytes(16))?; // bits per sample
|
out.write_all(&u16::to_le_bytes(16))?; // bits per sample
|
||||||
out.write_all(b"data")?;
|
out.write_all(b"data")?;
|
||||||
out.write_all(&u32::to_le_bytes(ssize))?;
|
out.write_all(&u32::to_le_bytes(dat_size))?;
|
||||||
|
|
||||||
for p in 0..snd.len() {
|
for p in 0..snd.len() {
|
||||||
let sample = snd.index(p);
|
let sample = snd.index(p);
|
||||||
|
@ -54,30 +54,30 @@ pub trait Sound
|
||||||
|
|
||||||
impl Sound16
|
impl Sound16
|
||||||
{
|
{
|
||||||
/// Creates a new Sound16.
|
/// Creates a new `Sound16`.
|
||||||
pub fn new(rate: u16, lp_beg: usize, lp_end: usize, len: usize) -> Self
|
pub fn new(rate: u16, lp_beg: usize, lp_end: usize, len: usize) -> Self
|
||||||
{
|
{
|
||||||
Self{rate, lp_beg, lp_end, data: Vec::with_capacity(len)}
|
Self{rate, lp_beg, lp_end, data: Vec::with_capacity(len)}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 = Sound16::new(rate, lp_beg, lp_end, b.len());
|
let mut snd = Self::new(rate, lp_beg, lp_end, b.len());
|
||||||
|
|
||||||
for &sample in b {
|
for &sample in b {
|
||||||
snd.data.push(Sound16::sample_from_8(sample));
|
snd.data.push(Self::sample_from_8(sample));
|
||||||
}
|
}
|
||||||
|
|
||||||
snd
|
snd
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 = Sound16::new(rate, lp_beg, lp_end, b.len() / 2);
|
let mut snd = Self::new(rate, lp_beg, lp_end, b.len() / 2);
|
||||||
|
|
||||||
for i in (0..b.len()).step_by(2) {
|
for i in (0..b.len()).step_by(2) {
|
||||||
snd.data.push(i16::from_le_bytes([b[i], b[i + 1]]));
|
snd.data.push(i16::from_le_bytes([b[i], b[i + 1]]));
|
||||||
|
|
|
@ -35,14 +35,14 @@ pub fn to_binsize(n: u64) -> String
|
||||||
|
|
||||||
// terabytes, gigabytes, megabytes, kilobytes
|
// terabytes, gigabytes, megabytes, kilobytes
|
||||||
for i in (1..=4).rev() {
|
for i in (1..=4).rev() {
|
||||||
if n >= 1000u64.pow(i) {
|
let pow = 1000_u64.pow(i);
|
||||||
let x = n as f64 / 1000f64.powi(i as i32);
|
if n >= pow {
|
||||||
return format!("{:1}{}", x, NAMES[i as usize - 1]);
|
return format!("{:1}{}", n / 1000, NAMES[i as usize - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// or, just bytes
|
// or, just bytes
|
||||||
format!("{} {}", n, if n != 1 {"bytes"} else {"byte"})
|
format!("{} {}", n, if n == 1 {"byte"} else {"bytes"})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encodes or decodes a string in the terminal encryption format.
|
/// Encodes or decodes a string in the terminal encryption format.
|
||||||
|
|
51
src/lib.rs
51
src/lib.rs
|
@ -1,3 +1,54 @@
|
||||||
|
#![deny(anonymous_parameters)] // deny deprecated behaviour, warn otherwise
|
||||||
|
#![deny(bare_trait_objects)]
|
||||||
|
#![deny(elided_lifetimes_in_paths)]
|
||||||
|
#![warn(trivial_casts)]
|
||||||
|
#![warn(trivial_numeric_casts)]
|
||||||
|
#![deny(unreachable_pub)]
|
||||||
|
#![warn(unused_import_braces)]
|
||||||
|
#![warn(unused_qualifications)]
|
||||||
|
#![deny(clippy::all)] // clippy lints, deny all except nontrivial things
|
||||||
|
#![deny(clippy::clone_on_ref_ptr)]
|
||||||
|
#![deny(clippy::copy_iterator)]
|
||||||
|
#![deny(clippy::decimal_literal_representation)]
|
||||||
|
#![deny(clippy::default_trait_access)]
|
||||||
|
#![deny(clippy::doc_markdown)]
|
||||||
|
#![deny(clippy::empty_enum)]
|
||||||
|
#![deny(clippy::empty_line_after_outer_attr)]
|
||||||
|
#![deny(clippy::explicit_into_iter_loop)]
|
||||||
|
#![deny(clippy::explicit_iter_loop)]
|
||||||
|
#![deny(clippy::fallible_impl_from)]
|
||||||
|
#![deny(clippy::filter_map)]
|
||||||
|
#![deny(clippy::float_arithmetic)] // MUAHAHAHAHAHA
|
||||||
|
#![deny(clippy::float_cmp_const)]
|
||||||
|
#![deny(clippy::if_not_else)]
|
||||||
|
#![deny(clippy::invalid_upcast_comparisons)]
|
||||||
|
#![deny(clippy::items_after_statements)]
|
||||||
|
#![deny(clippy::large_digit_groups)]
|
||||||
|
#![deny(clippy::map_flatten)]
|
||||||
|
#![deny(clippy::match_same_arms)]
|
||||||
|
#![deny(clippy::mem_forget)]
|
||||||
|
#![deny(clippy::multiple_inherent_impl)]
|
||||||
|
#![deny(clippy::mut_mut)]
|
||||||
|
#![deny(clippy::mutex_integer)]
|
||||||
|
#![deny(clippy::needless_borrow)]
|
||||||
|
#![deny(clippy::needless_continue)]
|
||||||
|
#![deny(clippy::option_map_unwrap_or)]
|
||||||
|
#![deny(clippy::option_map_unwrap_or_else)]
|
||||||
|
#![deny(clippy::panicking_unwrap)]
|
||||||
|
#![deny(clippy::print_stdout)]
|
||||||
|
#![deny(clippy::pub_enum_variant_names)]
|
||||||
|
#![deny(clippy::replace_consts)]
|
||||||
|
#![deny(clippy::result_map_unwrap_or_else)]
|
||||||
|
#![deny(clippy::result_unwrap_used)]
|
||||||
|
#![deny(clippy::similar_names)]
|
||||||
|
#![deny(clippy::single_match_else)]
|
||||||
|
#![deny(clippy::string_add)]
|
||||||
|
#![deny(clippy::string_add_assign)]
|
||||||
|
#![deny(clippy::unnecessary_unwrap)]
|
||||||
|
#![deny(clippy::unseparated_literal_suffix)]
|
||||||
|
#![deny(clippy::use_self)]
|
||||||
|
#![deny(clippy::used_underscore_binding)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod durandal;
|
pub mod durandal;
|
||||||
pub mod marathon;
|
pub mod marathon;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::durandal::bin::*;
|
use crate::durandal::bin::*;
|
||||||
|
|
||||||
/// Checks for an AppleSingle header. Returns offset to the resource fork.
|
/// Checks for an `AppleSingle` header. Returns offset to the resource fork.
|
||||||
pub fn check_apple_single(b: &[u8]) -> Option<usize>
|
pub fn check_apple_single(b: &[u8]) -> Option<usize>
|
||||||
{
|
{
|
||||||
// check magic numbers
|
// check magic numbers
|
||||||
|
@ -32,7 +32,7 @@ pub fn check_apple_single(b: &[u8]) -> Option<usize>
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks for a MacBinary II header. Returns offset to the resource fork.
|
/// Checks for a `MacBinary II` header. Returns offset to the resource fork.
|
||||||
pub fn check_macbin(b: &[u8]) -> Option<usize>
|
pub fn check_macbin(b: &[u8]) -> Option<usize>
|
||||||
{
|
{
|
||||||
// check legacy version, length, zero fill, and macbin2 version
|
// check legacy version, length, zero fill, and macbin2 version
|
||||||
|
@ -46,10 +46,10 @@ pub fn check_macbin(b: &[u8]) -> Option<usize>
|
||||||
for &byte in b.iter().take(124) {
|
for &byte in b.iter().take(124) {
|
||||||
for j in 8..16 {
|
for j in 8..16 {
|
||||||
let d = u16::from(byte) << j;
|
let d = u16::from(byte) << j;
|
||||||
if (d ^ crc) & 0x8000 != 0 {
|
if (d ^ crc) & 0x8000 == 0 {
|
||||||
crc = crc << 1 ^ 0x1021;
|
|
||||||
} else {
|
|
||||||
crc <<= 1;
|
crc <<= 1;
|
||||||
|
} else {
|
||||||
|
crc = crc << 1 ^ 0x1021;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ pub fn check_macbin(b: &[u8]) -> Option<usize>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a MacBin or AppleSingle header if there is one and returns the
|
/// Reads a `MacBin` or `AppleSingle` header if there is one and returns the
|
||||||
/// offset from the start of the header to the resource fork (if one is found.)
|
/// offset from the start of the header to the resource fork (if one is found.)
|
||||||
pub fn try_mac_header(b: &[u8]) -> usize
|
pub fn try_mac_header(b: &[u8]) -> usize
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,17 +10,17 @@ pub fn read_minf(b: &[u8]) -> ResultS<Minf>
|
||||||
env_code = u16[0];
|
env_code = u16[0];
|
||||||
physi_id = u16[2];
|
physi_id = u16[2];
|
||||||
music_id = u16[4];
|
music_id = u16[4];
|
||||||
msn_flag = u16[6];
|
missi_flags = u16[6];
|
||||||
env_flag = u16[8];
|
envir_flags = u16[8];
|
||||||
levelnam = mac_roman_conv[18..84] nt;
|
level_name = mac_roman_conv[18..84] nt;
|
||||||
ent_flag = u32[84];
|
entry_flags = u32[84];
|
||||||
}
|
}
|
||||||
|
|
||||||
let msn_flag = flag_ok!(MsnFlags, msn_flag)?;
|
let missi_flags = flag_ok!(MsnFlags, missi_flags)?;
|
||||||
let env_flag = flag_ok!(EnvFlags, env_flag)?;
|
let envir_flags = flag_ok!(EnvFlags, envir_flags)?;
|
||||||
let ent_flag = flag_ok!(EntFlags, ent_flag)?;
|
let entry_flags = flag_ok!(EntFlags, entry_flags)?;
|
||||||
Ok(Minf{env_code, physi_id, music_id, msn_flag, env_flag, ent_flag,
|
Ok(Minf{env_code, physi_id, music_id, missi_flags, envir_flags, entry_flags,
|
||||||
levelnam})
|
level_name})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_lightfunc(b: &[u8]) -> ResultS<LightFunc>
|
pub fn read_lightfunc(b: &[u8]) -> ResultS<LightFunc>
|
||||||
|
@ -399,12 +399,12 @@ pub struct Object
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct ObjectFreq
|
pub struct ObjectFreq
|
||||||
{
|
{
|
||||||
rnd_loc: bool,
|
pub rnd_loc: bool,
|
||||||
cnt_ini: u16,
|
pub cnt_ini: u16,
|
||||||
cnt_min: u16,
|
pub cnt_min: u16,
|
||||||
cnt_max: u16,
|
pub cnt_max: u16,
|
||||||
cnt_rnd: u16,
|
pub cnt_rnd: u16,
|
||||||
chance: u16,
|
pub chance: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
@ -465,10 +465,10 @@ pub struct Minf
|
||||||
pub env_code: u16,
|
pub env_code: u16,
|
||||||
pub physi_id: u16,
|
pub physi_id: u16,
|
||||||
pub music_id: u16,
|
pub music_id: u16,
|
||||||
pub msn_flag: MsnFlags,
|
pub missi_flags: MsnFlags,
|
||||||
pub env_flag: EnvFlags,
|
pub envir_flags: EnvFlags,
|
||||||
pub ent_flag: EntFlags,
|
pub entry_flags: EntFlags,
|
||||||
pub levelnam: String,
|
pub level_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
@ -683,7 +683,7 @@ c_enum! {
|
||||||
|
|
||||||
impl std::fmt::Debug for Point
|
impl std::fmt::Debug for Point
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
|
||||||
{
|
{
|
||||||
write!(f, "({}, {})", self.x, self.y)
|
write!(f, "({}, {})", self.x, self.y)
|
||||||
}
|
}
|
||||||
|
|
|
@ -625,7 +625,7 @@ c_enum! {
|
||||||
2 => PistolLeft,
|
2 => PistolLeft,
|
||||||
3 => PistolRight,
|
3 => PistolRight,
|
||||||
4 => SMG,
|
4 => SMG,
|
||||||
65535 => None,
|
0xFFFF => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,7 +669,7 @@ c_enum! {
|
||||||
21 => OxygenDrain,
|
21 => OxygenDrain,
|
||||||
22 => HummerBolt,
|
22 => HummerBolt,
|
||||||
23 => ShotgunProjectile,
|
23 => ShotgunProjectile,
|
||||||
65535 => None,
|
0xFFFF => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use crate::durandal::{bin::*, err::*, image::*};
|
use crate::durandal::{bin::*, err::*, image::*};
|
||||||
use generic_array::*;
|
use generic_array::*;
|
||||||
|
|
||||||
/// Reads a PixMap header.
|
/// Reads a `PixMap` header.
|
||||||
fn read_pm_header<'a>(b: &'a [u8],
|
fn read_pm_header<'a>(b: &'a [u8],
|
||||||
pack: bool,
|
pack: bool,
|
||||||
clip: bool,
|
clip: bool,
|
||||||
|
@ -57,7 +57,7 @@ fn read_pm_header<'a>(b: &'a [u8],
|
||||||
Ok((&b[p..], Header{pitch, pack_t, depth, clut, rle}))
|
Ok((&b[p..], Header{pitch, pack_t, depth, clut, rle}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads an indexed PixMap.
|
/// Reads an indexed `PixMap`.
|
||||||
fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
||||||
{
|
{
|
||||||
let clut = ok!(hdr.clut, "no CLUT in indexed mode")?;
|
let clut = ok!(hdr.clut, "no CLUT in indexed mode")?;
|
||||||
|
@ -98,7 +98,7 @@ fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a R5G5B5 PixMap.
|
/// Reads a R5G5B5 `PixMap`.
|
||||||
fn read_pm_16(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
fn read_pm_16(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
||||||
{
|
{
|
||||||
let mut p = 0;
|
let mut p = 0;
|
||||||
|
@ -133,7 +133,7 @@ fn read_pm_16(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a RGB8 PixMap.
|
/// Reads a RGB8 `PixMap`.
|
||||||
fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
||||||
{
|
{
|
||||||
let mut p = 0;
|
let mut p = 0;
|
||||||
|
@ -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>
|
||||||
{
|
{
|
||||||
|
@ -200,13 +200,7 @@ fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process a CompressedQuickTime operation.
|
/// Load a `PICT` image.
|
||||||
fn read_quicktime_c(_im: Image8, _b: &[u8]) -> ResultS<Image8>
|
|
||||||
{
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Load a PICT image.
|
|
||||||
pub fn load_pict(b: &[u8]) -> ResultS<Image8>
|
pub fn load_pict(b: &[u8]) -> ResultS<Image8>
|
||||||
{
|
{
|
||||||
read_data! {
|
read_data! {
|
||||||
|
@ -246,7 +240,7 @@ pub fn load_pict(b: &[u8]) -> ResultS<Image8>
|
||||||
}
|
}
|
||||||
0x8200 => {
|
0x8200 => {
|
||||||
// CompressedQuickTime
|
// CompressedQuickTime
|
||||||
return read_quicktime_c(im, &b[p..]);
|
unimplemented!();
|
||||||
}
|
}
|
||||||
0x00ff => {
|
0x00ff => {
|
||||||
// OpEndPic
|
// OpEndPic
|
||||||
|
@ -308,7 +302,7 @@ pub fn load_pict(b: &[u8]) -> ResultS<Image8>
|
||||||
Err(err_msg("no image in data"))
|
Err(err_msg("no image in data"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a colorTable structure.
|
/// Read a `ColorTable` structure.
|
||||||
pub fn get_clut(b: &[u8]) -> ResultS<(Vec<Color8>, usize)>
|
pub fn get_clut(b: &[u8]) -> ResultS<(Vec<Color8>, usize)>
|
||||||
{
|
{
|
||||||
read_data! {
|
read_data! {
|
||||||
|
@ -333,7 +327,7 @@ pub fn get_clut(b: &[u8]) -> ResultS<(Vec<Color8>, usize)>
|
||||||
}
|
}
|
||||||
|
|
||||||
// with device mapping, we ignore the index entirely
|
// with device mapping, we ignore the index entirely
|
||||||
let n = if !dev {n} else {i};
|
let n = if dev {i} else {n};
|
||||||
|
|
||||||
*ok!(clut.get_mut(n), "invalid index")? = Color8::new(r, g, b);
|
*ok!(clut.get_mut(n), "invalid index")? = Color8::new(r, g, b);
|
||||||
|
|
||||||
|
@ -411,9 +405,9 @@ pub fn expand_data(b: Vec<u8>, depth: u16) -> ResultS<Vec<u8>>
|
||||||
|
|
||||||
for ch in b {
|
for ch in b {
|
||||||
match depth {
|
match depth {
|
||||||
4 => {for i in (0..=1).rev() {o.push(ch >> (i * 4) & 0xFu8);}}
|
4 => {for i in (0..=1).rev() {o.push(ch >> (i * 4) & 0xF_u8);}}
|
||||||
2 => {for i in (0..=3).rev() {o.push(ch >> (i * 2) & 0x3u8);}}
|
2 => {for i in (0..=3).rev() {o.push(ch >> (i * 2) & 0x3_u8);}}
|
||||||
1 => {for i in (0..=7).rev() {o.push(ch >> i & 0x1u8);}}
|
1 => {for i in (0..=7).rev() {o.push(ch >> i & 0x1_u8);}}
|
||||||
_ => bail!("invalid bit depth"),
|
_ => bail!("invalid bit depth"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,16 +206,16 @@ pub fn read_shapes(b: &[u8]) -> ResultS<Vec<CollectionDef>>
|
||||||
hi_len = u32[p + 16] as usize;
|
hi_len = u32[p + 16] as usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
let c_lo = if lo_ofs != u32::max_value() as usize {
|
let c_lo = if lo_ofs == u32::max_value() as usize {
|
||||||
Some(collection(&b[lo_ofs..lo_ofs + lo_len])?)
|
|
||||||
} else {
|
|
||||||
None
|
None
|
||||||
|
} else {
|
||||||
|
Some(collection(&b[lo_ofs..lo_ofs + lo_len])?)
|
||||||
};
|
};
|
||||||
|
|
||||||
let c_hi = if hi_ofs != u32::max_value() as usize {
|
let c_hi = if hi_ofs == u32::max_value() as usize {
|
||||||
Some(collection(&b[hi_ofs..hi_ofs + hi_len])?)
|
|
||||||
} else {
|
|
||||||
None
|
None
|
||||||
|
} else {
|
||||||
|
Some(collection(&b[hi_ofs..hi_ofs + hi_len])?)
|
||||||
};
|
};
|
||||||
|
|
||||||
cl.push((c_lo, c_hi));
|
cl.push((c_lo, c_hi));
|
||||||
|
|
|
@ -137,7 +137,7 @@ c_enum! {
|
||||||
|
|
||||||
impl fmt::Debug for Group
|
impl fmt::Debug for Group
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
write!(f, "Group{{{:?} {} {}", self.ttype, self.pdata, self.lines)?;
|
write!(f, "Group{{{:?} {} {}", self.ttype, self.pdata, self.lines)?;
|
||||||
if !self.text.is_empty() {
|
if !self.text.is_empty() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::{collections::BTreeMap, fmt};
|
||||||
|
|
||||||
impl Wad<'_>
|
impl Wad<'_>
|
||||||
{
|
{
|
||||||
pub fn new(b: &[u8]) -> ResultS<Wad>
|
pub fn new(b: &[u8]) -> ResultS<Wad<'_>>
|
||||||
{
|
{
|
||||||
read_data! {
|
read_data! {
|
||||||
128, BE in b =>
|
128, BE in b =>
|
||||||
|
@ -27,8 +27,8 @@ impl Wad<'_>
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let entsize = if !is_old {10} else {8 };
|
let entsize = if is_old {8 } else {10};
|
||||||
let cnksize = if !is_old {16} else {12};
|
let cnksize = if is_old {12} else {16};
|
||||||
|
|
||||||
if entsize != wentsize {
|
if entsize != wentsize {
|
||||||
bail!("invalid entry size");
|
bail!("invalid entry size");
|
||||||
|
@ -49,7 +49,7 @@ impl Wad<'_>
|
||||||
index = u16[p + 8];
|
index = u16[p + 8];
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = if !is_old {index} else {i as u16};
|
let index = if is_old {i as u16} else {index};
|
||||||
|
|
||||||
let cnkdata = &b[offset..offset + size];
|
let cnkdata = &b[offset..offset + size];
|
||||||
let chunks = get_chunks(cnkdata, cnksize)?;
|
let chunks = get_chunks(cnkdata, cnksize)?;
|
||||||
|
@ -64,7 +64,7 @@ impl Wad<'_>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_chunks(b: &[u8], cnksize: usize) -> ResultS<ChunkMap>
|
fn get_chunks(b: &[u8], cnksize: usize) -> ResultS<ChunkMap<'_>>
|
||||||
{
|
{
|
||||||
let mut chunks = ChunkMap::new();
|
let mut chunks = ChunkMap::new();
|
||||||
let mut p = 0;
|
let mut p = 0;
|
||||||
|
@ -127,7 +127,7 @@ c_enum! {
|
||||||
|
|
||||||
impl fmt::Debug for Entry<'_>
|
impl fmt::Debug for Entry<'_>
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
write!(f, "Entry{{ ")?;
|
write!(f, "Entry{{ ")?;
|
||||||
for iden in self.chunks.keys() {
|
for iden in self.chunks.keys() {
|
||||||
|
|
Loading…
Reference in New Issue