diff --git a/source/durandal/bin.rs b/source/durandal/bin.rs index a9b3a21..f4c8e60 100644 --- a/source/durandal/bin.rs +++ b/source/durandal/bin.rs @@ -459,6 +459,24 @@ impl fmt::Debug for Ident } } +impl PartialEq<[u8; 4]> for Ident +{ + #[inline] + fn eq(&self, o: &[u8; 4]) -> bool {self.0 == *o} +} + +impl<'a> PartialEq<[u8; 4]> for &'a Ident +{ + #[inline] + fn eq(&self, o: &[u8; 4]) -> bool {PartialEq::eq(*self, o)} +} + +impl<'a> PartialEq<&'a [u8; 4]> for Ident +{ + #[inline] + fn eq(&self, o: & &'a [u8; 4]) -> bool {PartialEq::eq(self, *o)} +} + /// A four-character-code identifier. /// /// # Examples @@ -466,15 +484,19 @@ impl fmt::Debug for Ident /// ``` /// use maraiah::durandal::bin::Ident; /// -/// assert_eq!(Ident(*b"POLY").0, *b"POLY"); +/// assert_eq!( Ident(*b"POLY").0, *b"POLY"); +/// assert_eq!( Ident(*b"POLY"), *b"POLY"); +/// assert_eq!( Ident(*b"POLY"), b"POLY"); +/// assert_eq!(&Ident(*b"POLY"), *b"POLY"); +/// assert_eq!(&Ident(*b"POLY"), b"POLY"); /// ``` -#[derive(Clone, Copy, Default, PartialEq)] +#[derive(Clone, Copy, Default, Eq, PartialEq)] #[cfg_attr(feature = "serde_obj", derive(serde::Serialize, serde::Deserialize))] pub struct Ident(/** The individual bytes of this identifier. */ pub [u8; 4]); /// An object identified by a `u16` which may be `u16::max_value()` to /// represent a nulled value. -#[derive(Clone, Copy, Default, PartialEq)] +#[derive(Clone, Copy, Default, Eq, PartialEq)] #[cfg_attr(feature = "serde_obj", derive(serde::Serialize, serde::Deserialize))] pub struct OptU16(Option); diff --git a/source/durandal/cenum.rs b/source/durandal/cenum.rs index d814b35..62d4317 100644 --- a/source/durandal/cenum.rs +++ b/source/durandal/cenum.rs @@ -15,7 +15,7 @@ /// use maraiah::{c_enum, durandal::err::ReprError}; /// /// c_enum! { -/// #[derive(Debug, PartialEq)] +/// #[derive(Debug)] /// enum MyEnum: u16 /// { /// 0 => Zero, @@ -42,7 +42,7 @@ macro_rules! c_enum } ) => { $(#[$outer])* - #[derive(Copy, Clone)] + #[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd)] $vi enum $t { $($en,)+ @@ -68,7 +68,7 @@ mod test use crate::durandal::err::ReprError; c_enum! { - #[derive(Debug, PartialEq)] + #[derive(Debug)] enum TestEnum: u16 { 0 => Zero, diff --git a/source/durandal/err.rs b/source/durandal/err.rs index 12a9fcb..7657398 100644 --- a/source/durandal/err.rs +++ b/source/durandal/err.rs @@ -87,7 +87,7 @@ impl fmt::Display for ErrMsg } /// A representation error for an integer. -#[derive(Debug, PartialEq)] +#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] pub struct ReprError(i64); #[derive(Debug)] diff --git a/source/durandal/fixed.rs b/source/durandal/fixed.rs index 9daab6e..4ed6e8b 100644 --- a/source/durandal/fixed.rs +++ b/source/durandal/fixed.rs @@ -22,9 +22,9 @@ macro_rules! fixed_ref_binop { type Output = <$t as $imp<$u>>::Output; #[inline] - fn $method(self, other: $u) -> <$t as $imp<$u>>::Output + fn $method(self, o: $u) -> <$t as $imp<$u>>::Output { - $imp::$method(*self, other) + $imp::$method(*self, o) } } @@ -33,9 +33,9 @@ macro_rules! fixed_ref_binop { type Output = <$t as $imp<$u>>::Output; #[inline] - fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output + fn $method(self, o: &'a $u) -> <$t as $imp<$u>>::Output { - $imp::$method(self, *other) + $imp::$method(self, *o) } } @@ -44,9 +44,9 @@ macro_rules! fixed_ref_binop { type Output = <$t as $imp<$u>>::Output; #[inline] - fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output + fn $method(self, o: &'a $u) -> <$t as $imp<$u>>::Output { - $imp::$method(*self, *other) + $imp::$method(*self, *o) } } }; @@ -57,7 +57,7 @@ macro_rules! fixed_ref_op_assign { impl<'a> $imp<&'a $u> for $t { #[inline] - fn $method(&mut self, other: &'a $u) {$imp::$method(self, *other);} + fn $method(&mut self, o: &'a $u) {$imp::$method(self, *o);} } }; } @@ -72,7 +72,7 @@ macro_rules! define_fixed_types { ) => {$( $(#[$outer])* #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] - #[derive(Copy, Clone, Default, PartialEq, PartialOrd)] + #[derive(Copy, Clone, Default, Eq, Ord, PartialEq, PartialOrd)] pub struct $t($ti); impl $t @@ -354,7 +354,7 @@ macro_rules! define_fixed_types { impl AddAssign for $t { #[inline] - fn add_assign(&mut self, other: $t) {self.0 += other.0} + fn add_assign(&mut self, o: $t) {self.0 += o.0} } fixed_ref_op_assign! {impl AddAssign, add_assign for $t, $t} @@ -362,7 +362,7 @@ macro_rules! define_fixed_types { impl SubAssign for $t { #[inline] - fn sub_assign(&mut self, other: $t) {self.0 -= other.0} + fn sub_assign(&mut self, o: $t) {self.0 -= o.0} } fixed_ref_op_assign! {impl SubAssign, sub_assign for $t, $t} @@ -370,7 +370,7 @@ macro_rules! define_fixed_types { impl MulAssign for $t { #[inline] - fn mul_assign(&mut self, other: $t) {self.0 = (*self * other).0} + fn mul_assign(&mut self, o: $t) {self.0 = (*self * o).0} } fixed_ref_op_assign! {impl MulAssign, mul_assign for $t, $t} @@ -378,7 +378,7 @@ macro_rules! define_fixed_types { impl DivAssign for $t { #[inline] - fn div_assign(&mut self, other: $t) {self.0 = (*self / other).0} + fn div_assign(&mut self, o: $t) {self.0 = (*self / o).0} } fixed_ref_op_assign! {impl DivAssign, div_assign for $t, $t} diff --git a/source/durandal/image.rs b/source/durandal/image.rs index 6f25395..46a01bd 100644 --- a/source/durandal/image.rs +++ b/source/durandal/image.rs @@ -140,7 +140,7 @@ pub trait Image } /// Any color which may be represented as RGBA16. -pub trait Color: Sized + Copy + Clone +pub trait Color: Sized + Copy + Clone + Eq + PartialEq { /// Returns the red component. fn r(&self) -> u16; @@ -227,12 +227,12 @@ impl Color for Color8 /// An RGB16 color. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Color16(u16, u16, u16); /// An RGB8 color. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Color8(u8, u8, u8); /// An RGB16 image. diff --git a/source/durandal/sound.rs b/source/durandal/sound.rs index 2b81f17..78054d8 100644 --- a/source/durandal/sound.rs +++ b/source/durandal/sound.rs @@ -124,6 +124,8 @@ impl Sound for Sound16 } /// A 16-bit PCM stream. +#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] +#[derive(Debug)] pub struct Sound16 { rate: u16, diff --git a/source/marathon/map.rs b/source/marathon/map.rs index 3d9df47..fb10b80 100644 --- a/source/marathon/map.rs +++ b/source/marathon/map.rs @@ -433,7 +433,8 @@ pub fn read_note(b: &[u8]) -> ResultS<(Note, usize)> impl PolyType { - fn new(n: u16, pdata: u16) -> Result + /// Creates a `PolyType` from a `n`/`pdata` pair. + pub fn new(n: u16, pdata: u16) -> Result { match n { 0 => Ok(PolyType::Normal), @@ -464,6 +465,7 @@ impl PolyType } } + /// Creates a `PolyType` from a Marathon 1 compatible `n`/`pdata` pair. fn new_old(n: u16, pdata: u16) -> Result { match n { @@ -509,7 +511,7 @@ impl Default for Minf /// A point in world-space. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] pub struct Point { pub x: Unit, @@ -518,7 +520,7 @@ pub struct Point /// A line segment. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Line { pub flags: LineFlags, @@ -532,7 +534,7 @@ pub struct Line /// The texture of a side segment. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct SideTex { pub offs: Point, @@ -541,7 +543,7 @@ pub struct SideTex /// One side of a line segment. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Side { pub stype: SideType, @@ -559,7 +561,7 @@ pub struct Side /// A polygon segment. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug, Default)] +#[derive(Debug, Default, Eq, PartialEq)] pub struct Polygon { pub ptype: PolyType, @@ -582,7 +584,7 @@ pub struct Polygon /// A light function. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct LightFunc { pub ftype: LightFuncType, @@ -594,7 +596,7 @@ pub struct LightFunc /// A dynamic polygon light. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Light { pub ltype: LightType, @@ -611,7 +613,7 @@ pub struct Light /// An object in the world. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Object { pub group: u16, @@ -627,7 +629,7 @@ pub struct Object /// The difficulty definition for various object types. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct ObjectFreq { pub rnd_loc: bool, @@ -640,7 +642,7 @@ pub struct ObjectFreq /// An ambient sound definition. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct SoundAmbi { pub index: u16, @@ -649,7 +651,7 @@ pub struct SoundAmbi /// A randomly played sound definition. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct SoundRand { pub no_dir: bool, @@ -666,7 +668,7 @@ pub struct SoundRand /// A media, as in a part of a polygon which goes up the middle of the wall. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Media { pub mtype: MediaType, @@ -685,7 +687,7 @@ pub struct Media /// Extra information for polygons with platforms. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Platform { pub ptype: u16, @@ -700,7 +702,7 @@ pub struct Platform /// Overhead map annotations. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Note { pub pos: Point, @@ -710,7 +712,7 @@ pub struct Note /// Static map information. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub struct Minf { pub texture_id: u16, @@ -724,7 +726,7 @@ pub struct Minf /// The action type of a `Polygon`. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub enum PolyType { Normal, diff --git a/source/marathon/phy.rs b/source/marathon/phy.rs index 7b74e36..ab4ebcd 100644 --- a/source/marathon/phy.rs +++ b/source/marathon/phy.rs @@ -284,7 +284,7 @@ fn read_attack(b: &[u8]) -> ResultS /// Static physics information. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Physics { pub acc_ang: Fixed, @@ -317,7 +317,7 @@ pub struct Physics /// An effect definition. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Effect { pub collection: u16, @@ -330,7 +330,7 @@ pub struct Effect /// A weapon definition. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Weapon { pub amp_bob: Fixed, @@ -362,7 +362,7 @@ pub struct Weapon /// The definition of one of two triggers for a weapon. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Trigger { pub burst: u16, @@ -387,7 +387,7 @@ pub struct Trigger /// A projectile definition. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Projectile { pub collection: OptU16, @@ -411,7 +411,7 @@ pub struct Projectile /// A monster definition. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Monster { pub collection: u16, @@ -469,7 +469,7 @@ pub struct Monster /// A damage definition. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Damage { pub dtype: DamageType, @@ -481,7 +481,7 @@ pub struct Damage /// The definition of a monster's attack. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Attack { pub ptype: OptU16, diff --git a/source/marathon/pict.rs b/source/marathon/pict.rs index 7214434..c894803 100644 --- a/source/marathon/pict.rs +++ b/source/marathon/pict.rs @@ -479,7 +479,6 @@ struct Header } c_enum! { - #[derive(PartialEq, PartialOrd)] enum Depth: u16 { 1 => Bits1, @@ -492,7 +491,6 @@ c_enum! { } c_enum! { - #[derive(PartialEq)] enum PackType: u16 { 0 => Default, diff --git a/source/marathon/shp.rs b/source/marathon/shp.rs index 5c6d232..5f05563 100644 --- a/source/marathon/shp.rs +++ b/source/marathon/shp.rs @@ -318,7 +318,7 @@ impl Color for ColorShp /// A color in an `ImageShp`'s color table. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum ColorShp { /// A completely translucent color. @@ -336,7 +336,7 @@ pub enum ColorShp } /// An unpacked Shape bitmap. -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Bitmap { w: usize, @@ -348,6 +348,7 @@ pub struct Bitmap /// An image from a Shape. This mainly just exists so that `Bitmap` can use the /// `Image` trait. +#[derive(Debug, Eq, PartialEq)] pub struct ImageShp<'a, 'b> { bmp: &'a Bitmap, @@ -356,7 +357,7 @@ pub struct ImageShp<'a, 'b> /// A frame, also known as a low level shape. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Frame { /// The flags for this frame. @@ -389,7 +390,7 @@ pub struct Frame /// A sequence, also known as a high level shape. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Sequence { /// The display name for this sequence. @@ -427,7 +428,7 @@ pub struct Sequence } /// A collection of color tables, bitmaps, frames and sequences. -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct Collection { /// The type of collection this is. @@ -492,14 +493,14 @@ c_enum! { pub enum ViewType: u16 { 1 => Anim, + 2 => Anim8from2, 3 => Anim4from3, 4 => Anim4, - 9 => Anim5from3, - 11 => Anim5, - 2 => Anim8from2, 5 => Anim8from5, 8 => Anim8, + 9 => Anim5from3, 10 => Still, + 11 => Anim5, } } diff --git a/source/marathon/snd.rs b/source/marathon/snd.rs index 3d99223..e8577ee 100644 --- a/source/marathon/snd.rs +++ b/source/marathon/snd.rs @@ -124,6 +124,7 @@ pub fn read_sounds(b: &[u8]) -> ResultS> } /// A sound definition containing one, many or no sounds. +#[derive(Debug)] pub struct SoundDef { /// The volume type for this sound. diff --git a/source/marathon/trm.rs b/source/marathon/trm.rs index 13cd2eb..a059dab 100644 --- a/source/marathon/trm.rs +++ b/source/marathon/trm.rs @@ -98,7 +98,7 @@ impl Default for GroupType /// A terminal definition, with collections of groups and faces. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub struct Terminal { pub lines: u16, @@ -108,7 +108,7 @@ pub struct Terminal /// A text face. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub struct Face { pub start: usize, @@ -118,7 +118,7 @@ pub struct Face /// A terminal command grouping. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Debug, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub struct Group { pub flags: GroupFlags, @@ -128,7 +128,7 @@ pub struct Group } /// Interim structure. -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct InterGroup { pub flags: GroupFlags, @@ -140,7 +140,7 @@ pub struct InterGroup /// The command of a `Group`. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum GroupType { Logon(u16), diff --git a/tests/defl.rs b/tests/defl.rs index 3090833..40ae8ca 100644 --- a/tests/defl.rs +++ b/tests/defl.rs @@ -32,6 +32,7 @@ fn defl_alice_2() } #[test] +#[ignore] fn defl_shapes() { const INPUT: &[u8] = include_bytes!("data/defl/Shapes.in");