lint and format

gui-branch
an 2019-04-01 09:05:06 -04:00
parent 760143f901
commit 6bc4ca36f4
34 changed files with 211 additions and 170 deletions

View File

@ -115,8 +115,8 @@ macro_rules! rd_impl {
/// evaluated many times, so be careful when specifying it.
/// - `SIZE` is an expression specifying the last index that should be used by
/// this macro in `BUFFER`.
/// - `START` is an expression specifying the index to start at in `BUFFER`.
/// All indices and sizes will have this added to them.
/// - `START` is an expression specifying the index to start at in `BUFFER`. All
/// indices and sizes will have this added to them.
///
/// Following that is a block with the syntax `data { ... }`. All lines within
/// this block have the syntax `let NAME = TYPE[INDEX] OPTS;` where:
@ -139,8 +139,8 @@ macro_rules! rd_impl {
/// `fixed::Fixed::from_bits`, resulting in a `fixed::Fixed` object.
/// - `Unit`: same as `u16`, but the result is passed to
/// `fixed::Unit::from_bits`, resulting in a `fixed::Unit` object.
/// - `OptU16`: same as `u16`, but the result is passed to
/// `OptU16::from`, resulting in an `OptU16` object.
/// - `OptU16`: same as `u16`, but the result is passed to `OptU16::from`,
/// resulting in an `OptU16` object.
/// - The name of a function, which is passed the index range as its only
/// argument. The function's result has the `?` operator applied to it,
/// unless `OPTS` is `no_try`.
@ -175,8 +175,8 @@ macro_rules! rd_impl {
/// }
///
/// assert_eq!(four, 4_u16);
/// assert_eq!(two, 2_u32);
/// assert_eq!(six, 6_u8);
/// assert_eq!(two, 2_u32);
/// assert_eq!(six, 6_u8);
/// assert_eq!(byte, &[2, 0, 0, 0]);
/// # Ok(())
/// # }
@ -226,7 +226,7 @@ pub const fn usize_from_u32(n: u32) -> usize {n as usize}
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::{Ident, ident};
/// use maraiah::durandal::bin::{ident, Ident};
///
/// assert_eq!(ident(b"POLY"), Ident([b'P', b'O', b'L', b'Y']));
/// ```
@ -316,7 +316,8 @@ pub fn i16b(b: &[u8]) -> i16 {i16::from_be_bytes([b[0], b[1]])}
/// # Examples
///
/// ```
/// use maraiah::durandal::{err::*, bin::{rd_array, u16b}};
/// use maraiah::durandal::{bin::{rd_array, u16b},
/// err::*};
///
/// fn read_a_u16(b: &[u8]) -> ResultS<(u16, usize)> {Ok((u16b(b), 2))}
///
@ -523,7 +524,7 @@ impl<'a> PartialEq<[u8; 4]> for &'a Ident
impl<'a> PartialEq<&'a [u8; 4]> for Ident
{
#[inline]
fn eq(&self, o: & &'a [u8; 4]) -> bool {PartialEq::eq(self, *o)}
fn eq(&self, o: &&'a [u8; 4]) -> bool {PartialEq::eq(self, *o)}
}
/// A four-character-code identifier.
@ -533,11 +534,11 @@ impl<'a> PartialEq<&'a [u8; 4]> for Ident
/// ```
/// use maraiah::durandal::bin::Ident;
///
/// 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");
/// 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, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize, serde::Deserialize))]

View File

@ -35,7 +35,8 @@ macro_rules! bail {
/// ```
/// use maraiah::durandal::err::err_msg;
///
/// assert_eq!(format!("{}", err_msg("oh no not things")), "oh no not things");
/// assert_eq!(format!("{}", err_msg("oh no not things")),
/// "oh no not things");
/// ```
pub fn err_msg(msg: &'static str) -> Error {ErrMsg(msg).into()}
@ -46,7 +47,8 @@ pub fn err_msg(msg: &'static str) -> Error {ErrMsg(msg).into()}
/// ```
/// use maraiah::durandal::err::repr_error;
///
/// assert_eq!(format!("{}", repr_error(77)), "representation error (got 77)");
/// assert_eq!(format!("{}", repr_error(77)),
/// "representation error (got 77)");
/// ```
pub fn repr_error<T: Into<i64>>(n: T) -> Error {ReprError::new(n).into()}

View File

@ -1,25 +1,23 @@
//! Foreign function interface utilities.
use crate::durandal::err::*;
pub use std::{ffi::*, os::raw::*, ptr::{null, null_mut}};
pub use std::{ffi::*,
os::raw::*,
ptr::{null, null_mut}};
/// Creates a C string from a literal.
#[macro_export]
macro_rules! c_str {
($s:expr) => {concat!($s, "\0").as_ptr() as $crate::durandal::ffi::NT};
($s:expr) => {
concat!($s, "\0").as_ptr() as $crate::durandal::ffi::NT
};
}
#[inline]
pub const fn null_void() -> *const c_void
{
null()
}
pub const fn null_void() -> *const c_void {null()}
#[inline]
pub const fn null_mut_void() -> *mut c_void
{
null_mut()
}
pub const fn null_mut_void() -> *mut c_void {null_mut()}
impl CStringVec
{
@ -54,17 +52,11 @@ impl CStringVec
/// Returns the FFI pointer.
#[inline]
pub fn as_ptr(&self) -> *const NT
{
self.cv.as_ptr()
}
pub fn as_ptr(&self) -> *const NT {self.cv.as_ptr()}
/// Returns the FFI pointer mutably.
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut NT
{
self.cv.as_mut_ptr()
}
pub fn as_mut_ptr(&mut self) -> *mut NT {self.cv.as_mut_ptr()}
}
impl Default for CStringVec

View File

@ -1,7 +1,9 @@
//! Fixed point numbers.
#![allow(clippy::use_self)]
#![allow(clippy::cast_lossless)]
use std::{fmt::{self, Write}, ops::*};
use std::{fmt::{self, Write},
ops::*};
macro_rules! fixed_ref_unop {
(impl $imp:ident, $method:ident for $t:ty) => {

View File

@ -5,7 +5,7 @@
/// # Examples
///
/// ```
/// use maraiah::durandal::image::{Color8, r5g5b5_to_rgb8};
/// use maraiah::durandal::image::{r5g5b5_to_rgb8, Color8};
///
/// assert_eq!(r5g5b5_to_rgb8(0x2345), Color8::new(64, 208, 40));
/// ```
@ -22,9 +22,10 @@ pub fn r5g5b5_to_rgb8(rgb: u16) -> Color8
/// # Examples
///
/// ```
/// use maraiah::durandal::image::{Color16, r5g5b5_to_rgb16};
/// use maraiah::durandal::image::{r5g5b5_to_rgb16, Color16};
///
/// assert_eq!(r5g5b5_to_rgb16(0x2345), Color16::new(0x4000, 0xD000, 0x2800));
/// assert_eq!(r5g5b5_to_rgb16(0x2345),
/// Color16::new(0x4000, 0xD000, 0x2800));
/// ```
pub fn r5g5b5_to_rgb16(rgb: u16) -> Color16
{

View File

@ -47,7 +47,7 @@ pub fn load_gzip_header(b: &[u8]) -> ResultS<usize>
const FEXTRA: u8 = 1 << 2;
const FNAME: u8 = 1 << 3;
const FCOMMENT: u8 = 1 << 4;
const FRESERVED: u8 = 0xE0;
const FRESERVED: u8 = 0xe0;
read_data! {
endian: LITTLE, buf: b, size: 10, start: 0, data {
@ -57,7 +57,7 @@ pub fn load_gzip_header(b: &[u8]) -> ResultS<usize>
}
}
if id != 0x8B1F || cm != 8 {
if id != 0x8b1f || cm != 8 {
bail!("not gzip format");
}
@ -112,8 +112,10 @@ pub fn load_deflate(b: &[u8]) -> ResultS<(usize, Vec<u8>)>
let mut p = 0;
loop {
let bfinal = read_bits_l(b, p, 1)?; p += 1;
let btype = read_bits_l(b, p, 2)?; p += 2;
let bfinal = read_bits_l(b, p, 1)?;
p += 1;
let btype = read_bits_l(b, p, 2)?;
p += 2;
match btype {
0b10 => p = stream_dynamic(&mut v, b, p)?,
@ -130,19 +132,21 @@ pub fn load_deflate(b: &[u8]) -> ResultS<(usize, Vec<u8>)>
fn stream_dynamic(v: &mut Vec<u8>, b: &[u8], mut p: usize) -> ResultS<usize>
{
const CODE_ORDERING: [usize; 19] = [
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
];
const CODE_ORDERING: [usize; 19] =
[16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
// read header (number of literal alphabet codes, number of distance
// alphabet codes, and number of lengths for decoding the alphabet)
let hlit = read_bits_l(b, p, 5)?; p += 5;
let hdist = read_bits_l(b, p, 5)?; p += 5;
let hclen = read_bits_l(b, p, 4)?; p += 4;
let hlit = read_bits_l(b, p, 5)?;
p += 5;
let hdist = read_bits_l(b, p, 5)?;
p += 5;
let hclen = read_bits_l(b, p, 4)?;
p += 4;
let hlit = 257 + hlit as usize;
let hdist = 1 + hdist as usize;
let hclen = 4 + hclen as usize;
let hlit = 257 + hlit as usize;
let hdist = 1 + hdist as usize;
let hclen = 4 + hclen as usize;
// first, get the huffman coding for the alphabet (which is also compressed)
let mut code_table = [0; 19];
@ -166,7 +170,7 @@ fn stream_dynamic(v: &mut Vec<u8>, b: &[u8], mut p: usize) -> ResultS<usize>
}
// build the length and distance tables from this information
let table_len = HuffmanTable::new(&alphabet[ 0..hlit ])?;
let table_len = HuffmanTable::new(&alphabet[0..hlit])?;
let table_dst = HuffmanTable::new(&alphabet[hlit..hlit + hdist])?;
output_tables(v, b, p, table_len, table_dst)
@ -226,27 +230,38 @@ fn read_alphabet(b: &[u8],
}
16 => {
// copy previous code 3-6 times
if i == 0 {bail!("cannot copy on first alphabet code");}
if i == 0 {
bail!("cannot copy on first alphabet code");
}
let len = usize::from(read_bits_l(b, p, 2)? as u8 + 3);
let lst = alphabet[i - 1];
p += 2;
for _ in 0..len {alphabet[i] = lst; i += 1;}
for _ in 0..len {
alphabet[i] = lst;
i += 1;
}
}
17 => {
// repeat '0' 3-10 times
let len = usize::from(read_bits_l(b, p, 3)? as u8 + 3);
p += 3;
for _ in 0..len {alphabet[i] = 0; i += 1;}
for _ in 0..len {
alphabet[i] = 0;
i += 1;
}
}
18 => {
// repeat '0' 11-138 times
let len = usize::from(read_bits_l(b, p, 7)? as u8 + 11);
p += 7;
for _ in 0..len {alphabet[i] = 0; i += 1;}
for _ in 0..len {
alphabet[i] = 0;
i += 1;
}
}
_ => {
bail!("bad symbol in alphabet");
@ -268,25 +283,22 @@ fn output_tables(v: &mut Vec<u8>,
table_dst: HuffmanTable)
-> ResultS<usize>
{
const LEN_BASE: [usize; 29] = [
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
67, 83, 99, 115, 131, 163, 195, 227, 258
];
const LEN_BASE: [usize; 29] = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19,
23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115,
131, 163, 195, 227, 258];
const LEN_EXTRA_BITS: [u8; 29] = [
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,
5, 5, 5, 5, 0
];
const LEN_EXTRA_BITS: [u8; 29] = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2,
2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
0];
const DST_BASE: [usize; 30] = [
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513,
769, 1025, 1537, 2049, 3073, 4097, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001
];
const DST_BASE: [usize; 30] = [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65,
97, 129, 193, 257, 385, 513, 769, 1025,
1537, 2049, 3073, 4097, 0x1801, 0x2001,
0x3001, 0x4001, 0x6001];
const DST_EXTRA_BITS: [u8; 30] = [
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
11, 11, 12, 12, 13, 13
];
const DST_EXTRA_BITS: [u8; 30] = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13];
loop {
let (bits, sym) = table_len.decode(b, p)?;

View File

@ -57,7 +57,11 @@ pub fn check_macbin(b: &[u8]) -> Option<usize>
}
// if ok, resource fork follows
if crc == u16b(&b[124..]) {Some(128)} else {None}
if crc == u16b(&b[124..]) {
Some(128)
} else {
None
}
}
/// Reads a `MacBin` or `AppleSingle` header if there is one and returns the

View File

@ -1,13 +1,15 @@
//! `SoundRand` type.
use crate::durandal::{err::*, fixed::{Angle, Fixed}};
use crate::durandal::{err::*,
fixed::{Angle, Fixed}};
use bitflags::bitflags;
/// Reads a `bonk` chunk.
pub fn read(b: &[u8]) -> ResultS<(SoundRand, usize)>
{
read_data! {
endian: BIG, buf: b, size: 32, start: 0, data {
let flags = u16[0];
let flags = u16[0] flag SoundRandFlags;
let index = u16[2];
let vol_nrm = u16[4];
let vol_dta = u16[6];
@ -20,9 +22,7 @@ pub fn read(b: &[u8]) -> ResultS<(SoundRand, usize)>
}
}
let no_dir = flags != 0;
Ok((SoundRand{no_dir, index, vol_nrm, vol_dta, prd_nrm, prd_dta, yaw_nrm,
Ok((SoundRand{flags, index, vol_nrm, vol_dta, prd_nrm, prd_dta, yaw_nrm,
yaw_dta, pit_nrm, pit_dta}, 32))
}
@ -31,7 +31,7 @@ pub fn read(b: &[u8]) -> ResultS<(SoundRand, usize)>
#[derive(Debug, Eq, PartialEq)]
pub struct SoundRand
{
pub no_dir: bool,
pub flags: SoundRandFlags,
pub index: u16,
pub vol_nrm: u16,
pub vol_dta: u16,
@ -43,4 +43,13 @@ pub struct SoundRand
pub pit_dta: Fixed,
}
bitflags! {
/// Flags for `SoundRand`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
pub struct SoundRandFlags: u16
{
const NO_DIRECTION = 1;
}
}
// EOF

View File

@ -1,7 +1,7 @@
//! `EndPoint` type.
use crate::durandal::{err::*, fixed::Unit};
use super::pnts;
use crate::durandal::{err::*, fixed::Unit};
use bitflags::bitflags;
/// Reads an `EPNT` chunk.
@ -21,7 +21,7 @@ pub fn read(b: &[u8]) -> ResultS<(Endpoint, usize)>
}
/// Converts a vector of `Endpoint`s to a vector of `Point`s.
pub fn to_pnts(v: &Vec<Endpoint>) -> Vec<pnts::Point>
pub fn to_pnts(v: &[Endpoint]) -> Vec<pnts::Point>
{
v.iter().map(|p| p.pos).collect()
}

View File

@ -1,7 +1,7 @@
//! `Light` type.
use crate::durandal::{err::*, fixed::Fixed};
use super::{ltfn, TICKS_PER_SECOND};
use crate::durandal::{err::*, fixed::Fixed};
use bitflags::bitflags;
/// Reads a `LITE` chunk.

View File

@ -1,8 +1,11 @@
//! `Light` type.
use crate::{durandal::{bin::OptU16, err::*, fixed::{Angle, Fixed, Unit}},
marathon::xfer::TransferMode};
use super::pnts;
use crate::{durandal::{bin::OptU16,
err::*,
fixed::{Angle, Fixed, Unit}},
marathon::xfer::TransferMode};
use bitflags::bitflags;
/// Reads a `medi` chunk.
pub fn read(b: &[u8]) -> ResultS<(Media, usize)>
@ -10,7 +13,7 @@ pub fn read(b: &[u8]) -> ResultS<(Media, usize)>
read_data! {
endian: BIG, buf: b, size: 32, start: 0, data {
let mtype = u16[0] enum MediaType;
let flags = u16[2];
let flags = u16[2] flag MediaFlags;
let control = u16[4];
let dir = Angle[6];
let mag = Unit[8];
@ -24,9 +27,7 @@ pub fn read(b: &[u8]) -> ResultS<(Media, usize)>
}
}
let flr_obs = flags != 0;
Ok((Media{mtype, flr_obs, control, dir, mag, hei_lo, hei_hi, orig, hei_nrm,
Ok((Media{mtype, flags, control, dir, mag, hei_lo, hei_hi, orig, hei_nrm,
min_lt, texture, xfer}, 32))
}
@ -36,7 +37,7 @@ pub fn read(b: &[u8]) -> ResultS<(Media, usize)>
pub struct Media
{
pub mtype: MediaType,
pub flr_obs: bool,
pub flags: MediaFlags,
pub control: u16,
pub dir: Angle,
pub mag: Unit,
@ -62,4 +63,13 @@ c_enum! {
}
}
bitflags! {
/// Flags for `Media`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
pub struct MediaFlags: u16
{
const OBSTRUCT = 1;
}
}
// EOF

View File

@ -1,7 +1,7 @@
//! `Note` type.
use crate::{durandal::err::*, marathon::text::*};
use super::pnts;
use crate::{durandal::err::*, marathon::text::*};
/// Reads a `NOTE` chunk.
pub fn read(b: &[u8]) -> ResultS<(Note, usize)>

View File

@ -1,6 +1,7 @@
//! `Object` type.
use crate::durandal::{err::*, fixed::{Angle, Unit}};
use crate::durandal::{err::*,
fixed::{Angle, Unit}};
use bitflags::bitflags;
/// Reads an `OBJS` chunk.

View File

@ -1,13 +1,14 @@
//! `ObjectFreq` type.
use crate::durandal::err::*;
use bitflags::bitflags;
/// Reads a `plac` chunk.
pub fn read(b: &[u8]) -> ResultS<(ObjectFreq, usize)>
{
read_data! {
endian: BIG, buf: b, size: 12, start: 0, data {
let flags = u16[0];
let flags = u16[0] flag ObjectFreqFlags;
let cnt_ini = u16[2];
let cnt_min = u16[4];
let cnt_max = u16[6];
@ -16,9 +17,7 @@ pub fn read(b: &[u8]) -> ResultS<(ObjectFreq, usize)>
}
}
let rnd_loc = flags != 0;
Ok((ObjectFreq{rnd_loc, cnt_ini, cnt_min, cnt_max, cnt_rnd, chance}, 12))
Ok((ObjectFreq{flags, cnt_ini, cnt_min, cnt_max, cnt_rnd, chance}, 12))
}
/// The difficulty definition for various object types.
@ -26,7 +25,7 @@ pub fn read(b: &[u8]) -> ResultS<(ObjectFreq, usize)>
#[derive(Debug, Eq, PartialEq)]
pub struct ObjectFreq
{
pub rnd_loc: bool,
pub flags: ObjectFreqFlags,
pub cnt_ini: u16,
pub cnt_min: u16,
pub cnt_max: u16,
@ -34,4 +33,13 @@ pub struct ObjectFreq
pub chance: u16,
}
bitflags! {
/// Flags for `ObjectFreq`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
pub struct ObjectFreqFlags: u16
{
const RANDOM_LOCATION = 1;
}
}
// EOF

View File

@ -25,10 +25,7 @@ pub fn write_o(v: Point) -> Vec<u8>
}
/// Reads a `PNTS` chunk.
pub fn read(b: &[u8]) -> ResultS<(Point, usize)>
{
Ok((read_o(b)?, 4))
}
pub fn read(b: &[u8]) -> ResultS<(Point, usize)> {Ok((read_o(b)?, 4))}
/// A point in world-space.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]

View File

@ -1,8 +1,8 @@
//! `Polygon` type.
use super::pnts;
use crate::{durandal::{bin::OptU16, err::*, fixed::Unit},
marathon::xfer::TransferMode};
use super::pnts;
use bitflags::bitflags;
/// Reads a polygon for either M1 or M2.

View File

@ -1,8 +1,8 @@
//! `Side` type.
use super::stex;
use crate::{durandal::{bin::OptU16, err::*, fixed::Fixed},
marathon::xfer::TransferMode};
use super::stex;
use bitflags::bitflags;
/// Reads a `SIDS` chunk.

View File

@ -1,7 +1,8 @@
//! `Terminal` type.
use crate::{durandal::{bin, err::*}, marathon::text};
use super::{trmf, trmg};
use crate::{durandal::{bin, err::*},
marathon::text};
/// Reads a `term` chunk.
pub fn read(b: &[u8]) -> ResultS<(Terminal, usize)>
@ -16,13 +17,15 @@ pub fn read(b: &[u8]) -> ResultS<(Terminal, usize)>
}
}
let encoded = encoded != 0;
let (i_grp, x) = bin::rd_array_num(&b[10..], group_n, trmg::read)?;
let (faces, y) = bin::rd_array_num(&b[10 + x..], face_n, trmf::read)?;
let text = ok!(b.get(10 + x + y..end), "not enough data")?;
let text = if encoded {text::fuck_string(text)} else {text.to_vec()};
let text = if encoded != 0 {
text::fuck_string(text)
} else {
text.to_vec()
};
let mut groups = Vec::with_capacity(group_n);

View File

@ -1,6 +1,8 @@
//! `Attack` type.
use crate::{durandal::{bin::OptU16, err::*, fixed::{Angle, Unit}}};
use crate::durandal::{bin::OptU16,
err::*,
fixed::{Angle, Unit}};
/// Reads an `Attack` object.
pub fn read(b: &[u8]) -> ResultS<Attack>

View File

@ -1,6 +1,6 @@
//! `Damage` type.
use crate::{durandal::{err::*, fixed::Fixed}};
use crate::durandal::{err::*, fixed::Fixed};
use bitflags::bitflags;
/// Reads a `Damage` object.
@ -9,16 +9,14 @@ pub fn read(b: &[u8]) -> ResultS<Damage>
read_data! {
endian: BIG, buf: b, size: 12, start: 0, data {
let dtype = u16[0] enum DamageType;
let flags = u16[2];
let flags = u16[2] flag DamageFlags;
let dmg_base = u16[4];
let dmg_rand = u16[6];
let scale = Fixed[8];
}
}
let alien = flags != 0;
Ok(Damage{dtype, alien, dmg_base, dmg_rand, scale})
Ok(Damage{dtype, flags, dmg_base, dmg_rand, scale})
}
/// A damage definition.
@ -27,7 +25,7 @@ pub fn read(b: &[u8]) -> ResultS<Damage>
pub struct Damage
{
pub dtype: DamageType,
pub alien: bool,
pub flags: DamageFlags,
pub dmg_base: u16,
pub dmg_rand: u16,
pub scale: Fixed,
@ -65,6 +63,15 @@ bitflags! {
}
}
bitflags! {
/// Flags for `Damage`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
pub struct DamageFlags: u16
{
const ALIEN = 1;
}
}
c_enum! {
/// A named type of damage taken by something.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]

View File

@ -1,6 +1,6 @@
//! `Effect` type.
use crate::{durandal::{bin::OptU16, err::*, fixed::Fixed}};
use crate::durandal::{bin::OptU16, err::*, fixed::Fixed};
use bitflags::bitflags;
/// Reads a `FXpx` chunk.

View File

@ -1,6 +1,8 @@
//! `Monster` type.
use crate::{durandal::{bin::OptU16, err::*, fixed::{Fixed, Unit}}};
use crate::durandal::{bin::OptU16,
err::*,
fixed::{Fixed, Unit}};
use bitflags::bitflags;
use super::{attk, damg};

View File

@ -1,6 +1,8 @@
//! `Projectile` type.
use crate::{durandal::{bin::OptU16, err::*, fixed::{Fixed, Unit}}};
use crate::durandal::{bin::OptU16,
err::*,
fixed::{Fixed, Unit}};
use bitflags::bitflags;
use super::damg;

View File

@ -1,6 +1,6 @@
//! `Physics` type.
use crate::{durandal::{err::*, fixed::Fixed}};
use crate::durandal::{err::*, fixed::Fixed};
/// Reads a `PXpx` chunk.
pub fn read(b: &[u8]) -> ResultS<(Physics, usize)>

View File

@ -1,6 +1,6 @@
//! `Monster` type.
use crate::{durandal::{bin::OptU16, err::*, fixed::Unit}};
use crate::durandal::{bin::OptU16, err::*, fixed::Unit};
/// Reads a `Trigger` object.
pub fn read(b: &[u8]) -> ResultS<Trigger>

View File

@ -1,6 +1,6 @@
//! `Weapon` type.
use crate::{durandal::{bin::OptU16, err::*, fixed::Fixed}};
use crate::durandal::{bin::OptU16, err::*, fixed::Fixed};
use bitflags::bitflags;
use super::trig;

View File

@ -32,9 +32,9 @@ fn read_color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()>
/// Reads all color tables.
fn color_tables(b: &[u8],
tab_ofs: usize,
tab_num: usize,
clr_num: usize)
tab_ofs: usize,
tab_num: usize,
clr_num: usize)
-> ResultS<Vec<Vec<ColorShp>>>
{
let end = tab_num * clr_num * 8;

View File

@ -104,8 +104,8 @@ pub fn mac_roman_conv(s: &[u8]) -> String
/// use maraiah::marathon::text::mac_roman_cstr;
///
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0ed"), "Ive awaken");
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0"), "Ive awaken");
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken"), "Ive awaken");
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0"), "Ive awaken");
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken"), "Ive awaken");
/// ```
#[inline]
pub fn mac_roman_cstr(s: &[u8]) -> String
@ -133,12 +133,8 @@ pub fn to_mac_roman(s: &str) -> Vec<u8>
for c in s.chars() {
let c = match c {
'\n' => {
b'\r'
}
'\0'..='\x7f' => {
c as u8
}
'\n' => b'\r',
'\0'..='\x7f' => c as u8,
c => {
if let Some(c) = TR.iter().position(|&o| o == c) {
c as u8 + 0x80
@ -205,19 +201,18 @@ const TR: [char; 128] =
#[test]
fn to_binsize_integrals()
{
assert_eq!(to_binsize(0), "empty");
assert_eq!(to_binsize(1), "1 byte");
assert_eq!(to_binsize(2), "2 bytes");
assert_eq!(to_binsize(999), "999 bytes");
assert_eq!(to_binsize(1000), "1kB");
assert_eq!(to_binsize(1000 * 7), "7kB");
assert_eq!(to_binsize(1000 * 1000), "1MB");
assert_eq!(to_binsize(1000 * 1000 * 7), "7MB");
assert_eq!(to_binsize(1000 * 1000 * 1000), "1GB");
assert_eq!(to_binsize(1000 * 1000 * 1000 * 7), "7GB");
assert_eq!(to_binsize(1000 * 1000 * 1000 * 1000), "1TB");
assert_eq!(to_binsize(0), "empty");
assert_eq!(to_binsize(1), "1 byte");
assert_eq!(to_binsize(2), "2 bytes");
assert_eq!(to_binsize(999), "999 bytes");
assert_eq!(to_binsize(1000), "1kB");
assert_eq!(to_binsize(1000 * 7), "7kB");
assert_eq!(to_binsize(1000 * 1000), "1MB");
assert_eq!(to_binsize(1000 * 1000 * 7), "7MB");
assert_eq!(to_binsize(1000 * 1000 * 1000), "1GB");
assert_eq!(to_binsize(1000 * 1000 * 1000 * 7), "7GB");
assert_eq!(to_binsize(1000 * 1000 * 1000 * 1000), "1TB");
assert_eq!(to_binsize(1000 * 1000 * 1000 * 1000 * 7), "7TB");
}
// EOF

View File

@ -5,8 +5,7 @@ use crate::{durandal::{bin::*, err::*, image},
use std::collections::BTreeMap;
/// Reads all chunks in an entry.
pub fn read_chunks(b: &[u8], old: bool, siz_cnk: usize)
-> ResultS<Vec<Chunk>>
pub fn read_chunks(b: &[u8], old: bool, siz_cnk: usize) -> ResultS<Vec<Chunk>>
{
let mut chunks = Vec::new();
let mut p = 0;

View File

@ -7,17 +7,14 @@
mod block;
mod state;
use crate::durandal::image::*;
use super::{color, draw::*};
use crate::durandal::image::*;
impl MapEditor
{
/// Opens the editor with a new empty map.
#[inline]
pub fn open_new(&mut self)
{
self.map = Some(state::OpenMap::default());
}
pub fn open_new(&mut self) {self.map = Some(state::OpenMap::default());}
/// Opens the editor with an existing map.
pub fn open_buf(&mut self, b: &[u8])
@ -54,24 +51,18 @@ impl MapEditor
let text = &format!("tool: {:?}", st.tool());
d.clear(Color16::new(0, 0, 0));
d.text((dw/2, dh/2), text, color::RED);
d.text((dw / 2, dh / 2), text, color::RED);
}
}
}
/// Returns `true` if `self` is closed.
#[inline]
pub fn is_closed(&self) -> bool
{
self.map.is_none()
}
pub fn is_closed(&self) -> bool {self.map.is_none()}
/// Returns `true` if `self` is opened.
#[inline]
pub fn is_opened(&self) -> bool
{
self.map.is_some()
}
pub fn is_opened(&self) -> bool {self.map.is_some()}
}
impl Default for MapEditor

View File

@ -3,10 +3,7 @@ use crate::marathon::map;
impl Default for Block
{
#[inline]
fn default() -> Self
{
Self{info: map::minf::Minf::default()}
}
fn default() -> Self {Self{info: map::minf::Minf::default()}}
}
/// Copyable, versioned map state.

View File

@ -37,10 +37,7 @@ impl OpenMap
self.blocks.last_mut().unwrap()
}
pub(super) fn tool(&self) -> &Tool
{
&self.tools.0
}
pub(super) fn tool(&self) -> &Tool {&self.tools.0}
pub(super) fn set_tool(&mut self, t: Tool) -> &Tool
{

View File

@ -128,14 +128,18 @@ impl MapEditor
/// Propagates updated information to widgets.
pub fn cause_update(&mut self)
{
unsafe {gtk_widget_queue_draw(self.draw);}
unsafe {
gtk_widget_queue_draw(self.draw);
}
}
/// Sets the drawing area widget.
pub fn set_draw(&mut self, draw: *mut GtkWidget)
{
self.draw = draw;
unsafe {g_object_ref(self.draw as _);}
unsafe {
g_object_ref(self.draw as _);
}
}
}
@ -152,7 +156,9 @@ impl Drop for MapEditor
{
fn drop(&mut self)
{
unsafe {g_object_unref(self.draw as _);}
unsafe {
g_object_unref(self.draw as _);
}
}
}

View File

@ -1,4 +1,5 @@
use maraiah::{durandal::{bin, fixed::*}, marathon::map};
use maraiah::{durandal::{bin, fixed::*},
marathon::map};
include!("data/rand.rs");