maraiah: reorganize project

master
an 2019-06-13 21:09:07 -04:00
parent 25d5ac1314
commit dafa691002
78 changed files with 275 additions and 247 deletions

View File

@ -7,22 +7,15 @@ is derived from the Japanese transliteration of "Mariah," and is pronounced
## `maraiah`
The basis of this project is the Rust project `maraiah` which provides functions
and structures to build applications which work with Marathon's data. It is
subdivided into two libraries: `maraiah-durandal` and `maraiah-marathon`.
Ideally these would be separate libraries but Cargo is woefully unable to do so
for varying reasons. They will be treated as separate in this document.
and structures to build applications which work with Marathon's data.
## `maraiah-durandal`
The `durandal` library is a set of almost fully portable tools written in Rust,
Maraiah comes with a set of almost fully portable tools written in Rust,
including binary file reading, safe C-like `enum` reading, improved error
handling, FFI tools, fixed point numbers, and image and sound structures.
## `maraiah-marathon`
`marathon` is a library for working with various data formats, primarily
Maraiah also comes with APIs for working with various data formats, primarily
Marathon's. It also handles Macintosh PICT files, Portable PixMap, TARGA, RIFF
WAVE and other formats.
WAVE, and more.
## `maraiah-leela`
@ -31,4 +24,4 @@ the underlying Maraiah library.
## `maraiah-tycho`
`tycho` is a map editor written in C++ and Rust using Qt for GUI.
`tycho` is a map editor written in C++ and Rust using Qt.

View File

@ -1,6 +1,6 @@
//! Binary data conversion utilities.
use crate::durandal::err::*;
use crate::err::*;
use std::{convert::{TryFrom, TryInto}, fmt, num::NonZeroU16};
#[doc(hidden)]
@ -159,7 +159,7 @@ macro_rules! rd_impl {
///
/// ```
/// # #[macro_use] extern crate maraiah;
/// # use maraiah::durandal::err::*;
/// # use maraiah::err::*;
/// let buffer = &[4, 0, 2, 0, 0, 0, 6];
///
/// read_data! {
@ -211,7 +211,7 @@ macro_rules! check_data {
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::usize_from_u32;
/// use maraiah::bin::usize_from_u32;
///
/// assert_eq!(usize_from_u32(777u32), 777usize);
/// ```
@ -230,7 +230,7 @@ pub fn usize_from_u32(n: u32) -> usize
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::{ident, Ident};
/// use maraiah::bin::{ident, Ident};
///
/// assert_eq!(ident(b"POLY"), Ident([b'P', b'O', b'L', b'Y']));
/// ```
@ -249,7 +249,7 @@ pub fn ident(b: &[u8]) -> Ident
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::u32b;
/// use maraiah::bin::u32b;
///
/// assert_eq!(u32b(&[0x00, 0x0B, 0xDE, 0x31]), 777_777u32);
/// ```
@ -268,7 +268,7 @@ pub fn u32b(b: &[u8]) -> u32
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::u16b;
/// use maraiah::bin::u16b;
///
/// assert_eq!(u16b(&[0x1E, 0x61]), 7_777u16);
/// ```
@ -287,7 +287,7 @@ pub fn u16b(b: &[u8]) -> u16
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::i32b;
/// use maraiah::bin::i32b;
///
/// assert_eq!(i32b(&[0xFF, 0x89, 0x52, 0x0F]), -7_777_777i32);
/// ```
@ -306,7 +306,7 @@ pub fn i32b(b: &[u8]) -> i32
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::i16b;
/// use maraiah::bin::i16b;
///
/// assert_eq!(i16b(&[0xE1, 0x9F]), -7_777i16);
/// ```
@ -335,8 +335,7 @@ pub fn i16b(b: &[u8]) -> i16
/// # Examples
///
/// ```
/// use maraiah::durandal::{bin::{rd_array, u16b},
/// err::*};
/// use maraiah::{bin::{rd_array, u16b}, err::*};
///
/// fn read_a_u16(b: &[u8]) -> ResultS<(u16, usize)> {Ok((u16b(b), 2))}
///
@ -446,7 +445,7 @@ impl Into<u16> for OptU16
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::OptU16;
/// use maraiah::bin::OptU16;
///
/// let u16_max = u16::max_value();
///
@ -473,7 +472,7 @@ impl OptU16
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::OptU16;
/// use maraiah::bin::OptU16;
///
/// assert_eq!(OptU16::none(), OptU16::from(u16::max_value()));
/// ```
@ -485,7 +484,7 @@ impl OptU16
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::OptU16;
/// use maraiah::bin::OptU16;
///
/// assert_eq!(OptU16::from(500u16).get(), Some(500u16));
/// assert_eq!(OptU16::from(u16::max_value()).get(), None);
@ -551,7 +550,7 @@ impl<'a> PartialEq<&'a [u8; 4]> for Ident
/// # Examples
///
/// ```
/// use maraiah::durandal::bin::Ident;
/// use maraiah::bin::Ident;
///
/// assert_eq!(Ident(*b"POLY").0, *b"POLY");
/// assert_eq!(Ident(*b"POLY"), *b"POLY");

View File

@ -1,6 +1,6 @@
//! Bit streams.
use crate::durandal::err::*;
use crate::err::*;
/// Reads `width` bits from `b` starting at bit `cr_bit` into an integer, most
/// significant bit first.

View File

@ -12,7 +12,7 @@
/// # Examples
///
/// ```
/// use maraiah::{c_enum, durandal::err::ReprError};
/// use maraiah::{c_enum, err::ReprError};
/// use std::convert::TryFrom;
///
/// c_enum! {
@ -53,7 +53,7 @@ macro_rules! c_enum
#[allow(unused_qualifications)]
impl std::convert::TryFrom<$ti> for $t
{
type Error = $crate::durandal::err::ReprError;
type Error = $crate::err::ReprError;
/// Returns, if representable, the variant of `Self` from `n`.
fn try_from(n: $ti) -> Result<Self, Self::Error>
@ -70,7 +70,7 @@ macro_rules! c_enum
#[cfg(test)]
mod test
{
use crate::durandal::err::ReprError;
use crate::err::ReprError;
use std::convert::TryFrom;
c_enum! {

View File

@ -26,7 +26,7 @@ fn crc_init() -> [u32; 256]
/// # Examples
///
/// ```
/// use maraiah::durandal::cksum::adler32;
/// use maraiah::cksum::adler32;
///
/// assert_eq!(adler32(b"Lorem ipsum dolor sit amet"), 0x83D5_09C5);
/// ```
@ -50,7 +50,7 @@ pub fn adler32(b: &[u8]) -> u32
/// # Examples
///
/// ```
/// use maraiah::durandal::cksum::crc32;
/// use maraiah::cksum::crc32;
///
/// assert_eq!(crc32(b"Lorem ipsum dolor sit amet", !0), 0x5F29_D461);
/// ```

View File

@ -1,6 +1,6 @@
//! DEFLATE loader.
use crate::durandal::{bit::*, err::*};
use crate::{bit::*, err::*};
use std::cmp::Ordering;
/// Loads a ZLIB file header.

View File

@ -1,19 +0,0 @@
//! Library for utilities.
#[macro_use]
pub mod ffi;
#[macro_use]
pub mod err;
#[macro_use]
pub mod cenum;
#[macro_use]
pub mod bin;
pub mod bit;
pub mod cksum;
pub mod file;
pub mod fixed;
pub mod image;
pub mod sound;
// EOF

View File

@ -33,7 +33,7 @@ macro_rules! bail {
/// # Examples
///
/// ```
/// use maraiah::durandal::err::err_msg;
/// use maraiah::err::err_msg;
///
/// assert_eq!(format!("{}", err_msg("oh no not things")),
/// "oh no not things");
@ -45,7 +45,7 @@ pub fn err_msg(msg: &'static str) -> Error {ErrMsg(msg).into()}
/// # Examples
///
/// ```
/// use maraiah::durandal::err::repr_error;
/// use maraiah::err::repr_error;
///
/// assert_eq!(format!("{}", repr_error(77)),
/// "representation error (got 77)");
@ -59,7 +59,7 @@ impl ReprError
/// # Examples
///
/// ```
/// use maraiah::durandal::err::ReprError;
/// use maraiah::err::ReprError;
///
/// let err = ReprError::new(7);
///

View File

@ -1,6 +1,6 @@
//! Foreign function interface utilities.
use crate::durandal::err::*;
use crate::err::*;
pub use std::{ffi::*,
os::raw::*,
ptr::{null, null_mut}};
@ -9,7 +9,7 @@ pub use std::{ffi::*,
#[macro_export]
macro_rules! c_str {
($s:expr) => {
concat!($s, "\0").as_ptr() as $crate::durandal::ffi::NT
concat!($s, "\0").as_ptr() as $crate::ffi::NT
};
}

View File

@ -1,6 +1,6 @@
//! File utilities.
use crate::durandal::err::*;
use crate::err::*;
use std::fs;
/// Confirms that the path `p` is a folder.

View File

@ -2,8 +2,7 @@
#![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

@ -1,11 +1,15 @@
//! Image and color representations.
pub mod pict;
pub mod ppm;
pub mod tga;
/// Creates a RGB8 color from a R5G5B5 format color.
///
/// # Examples
///
/// ```
/// use maraiah::durandal::image::{r5g5b5_to_rgb8, Color8};
/// use maraiah::image::{r5g5b5_to_rgb8, Color8};
///
/// assert_eq!(r5g5b5_to_rgb8(0x2345), Color8::new(64, 208, 40));
/// ```
@ -22,7 +26,7 @@ pub fn r5g5b5_to_rgb8(rgb: u16) -> Color8
/// # Examples
///
/// ```
/// use maraiah::durandal::image::{r5g5b5_to_rgb16, Color16};
/// use maraiah::image::{r5g5b5_to_rgb16, Color16};
///
/// assert_eq!(r5g5b5_to_rgb16(0x2345),
/// Color16::new(0x4000, 0xD000, 0x2800));
@ -40,7 +44,7 @@ pub fn r5g5b5_to_rgb16(rgb: u16) -> Color16
/// # Examples
///
/// ```
/// use maraiah::durandal::image;
/// use maraiah::image;
///
/// let inpl = image::r5g5b5_to_rgb8(0x2345);
/// let inph = image::r5g5b5_to_rgb16(0x2345);

View File

@ -4,7 +4,7 @@ pub mod clut;
pub mod pm;
pub mod rle;
use crate::durandal::{bin::*, err::*, image::*};
use crate::{bin::*, err::*, image::*};
/// Load a `PICT` image.
pub fn read(b: &[u8]) -> ResultS<Image8>

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT color lookup tables.
use crate::durandal::{err::*, image::*};
use crate::{err::*, image::*};
/// Read a `ColorTable` structure.
pub fn read(b: &[u8]) -> ResultS<(Vec<Color8>, usize)>

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT `PixMap` areas.
use crate::{durandal::{err::*, image::*}, marathon::pict::pm};
use crate::{err::*, image::{*, pict::pm}};
/// Process a `CopyBits` operation.
pub fn read(im: Image8, b: &[u8], pack: bool, clip: bool) -> ResultS<Image8>

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT `PixMap` headers.
use crate::{durandal::{bin::*, err::*, image::*}, marathon::pict};
use crate::{bin::*, err::*, image::*};
use std::convert::TryFrom;
/// Reads a `PixMap` header.

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT indexed `PixMap`s.
use crate::{durandal::{err::*, image::*}, marathon::pict::{pm, rle}};
use crate::{err::*, image::{*, pict::{pm, rle}}};
/// Reads an indexed `PixMap`.
pub fn read(mut im: Image8,

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT R5G5B5 `PixMap`s.
use crate::{durandal::{bin::u16b, err::*, image::*}, marathon::pict::{pm, rle}};
use crate::{bin::u16b, err::*, image::{*, pict::{pm, rle}}};
/// Reads a R5G5B5 `PixMap`.
pub fn read(mut im: Image8,

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT RGB8 `PixMap`s.
use crate::{durandal::{err::*, image::*}, marathon::pict::{pm, rle}};
use crate::{err::*, image::{*, pict::{pm, rle}}};
/// Reads a RGB8 `PixMap`.
pub fn read(mut im: Image8,

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT format run length encoded data.
use crate::durandal::{bin::*, err::*};
use crate::{bin::*, err::*};
/// Read run-length encoded data.
pub fn read<T>(b: &[u8], pitch: usize) -> ResultS<(Vec<T>, usize)>

View File

@ -1,6 +1,6 @@
//! Portable Pixel Map format images.
use crate::durandal::{err::*, fixed::FixedLong, image::*};
use crate::{err::*, fixed::FixedLong, image::*};
use std::io;
/// Writes a PPM file from an image.

View File

@ -1,6 +1,6 @@
//! TARGA format images.
use crate::durandal::{err::*, image::*};
use crate::{err::*, image::*};
use std::io;
/// Writes a TGA file from an image.

View File

@ -1,8 +1,8 @@
#![allow(clippy::unit_arg)]
use maraiah::{durandal::{err::*, file::*, image::*, sound::*},
marathon::{machdr, map, ppm, shp, snd, tga, wav}};
use std::{fs, io, slice::from_ref};
use maraiah::{err::*, file::*, image::*, sound::*,
machdr, map, ppm, shp, snd, tga, wav};
use std::{collections::HashSet, fs, io, slice::from_ref};
fn open(path: &str) -> ResultS<memmap::Mmap>
{
@ -27,9 +27,10 @@ fn exists(path: String) -> Result<(), String>
}
}
fn each_value<'a, F>(opt: &'a clap::ArgMatches<'a>, name: &str, mut f: F)
-> ResultS<()>
where F: FnMut(&'a str) -> ResultS<()>
fn each_value<F>(opt: &clap::ArgMatches<'_>,
name: &str,
mut f: F) -> ResultS<()>
where F: FnMut(&str) -> ResultS<()>
{
if let Some(values) = opt.values_of(name) {
for value in values {
@ -40,26 +41,53 @@ fn each_value<'a, F>(opt: &'a clap::ArgMatches<'a>, name: &str, mut f: F)
Ok(())
}
fn dump_info(data: impl std::fmt::Debug)
fn dbg_info(data: impl std::fmt::Debug)
{
println!("{:#?}", data);
}
fn sub_data_c<'a>(_opt: &clap::ArgMatches<'a>) -> ResultS<()>
fn dump_map(opt: &clap::ArgMatches<'_>, f: &str) -> ResultS<()>
{
let mut cnks = HashSet::new();
if let Some(opt_cnks) = opt.values_of("chunks") {
for typ in opt_cnks {
cnks.insert(typ);
}
}
Ok(())
}
fn dump_shp(opt: &clap::ArgMatches<'_>, f: &str) -> ResultS<()>
{
unimplemented!();
}
fn sub_dump_c<'a>(_opt: &clap::ArgMatches<'a>) -> ResultS<()>
fn dump_snd(opt: &clap::ArgMatches<'_>, f: &str) -> ResultS<()>
{
unimplemented!();
}
fn sub_info_c<'a>(opt: &clap::ArgMatches<'a>) -> ResultS<()>
fn sub_data_c(_opt: &clap::ArgMatches<'_>) -> ResultS<()>
{
each_value(opt, "map", |f| Ok(dump_info(file_read(f, map::read)?)))?;
each_value(opt, "shp", |f| Ok(dump_info(file_read(f, shp::read)?)))?;
each_value(opt, "snd", |f| Ok(dump_info(file_read(f, snd::read)?)))?;
unimplemented!();
}
fn sub_dump_c(opt: &clap::ArgMatches<'_>) -> ResultS<()>
{
each_value(opt, "map", |f| dump_map(opt, f))?;
each_value(opt, "shp", |f| dump_shp(opt, f))?;
each_value(opt, "snd", |f| dump_snd(opt, f))?;
Ok(())
}
fn sub_info_c(opt: &clap::ArgMatches<'_>) -> ResultS<()>
{
each_value(opt, "map", |f| Ok(dbg_info(file_read(f, map::read)?)))?;
each_value(opt, "shp", |f| Ok(dbg_info(file_read(f, shp::read)?)))?;
each_value(opt, "snd", |f| Ok(dbg_info(file_read(f, snd::read)?)))?;
Ok(())
}
@ -74,16 +102,22 @@ fn main() -> ResultS<()>
let sub_dump =
clap_app!(@subcommand dump =>
(about: "Dumps particular parts of data"));
(about: "Dumps particular parts of data")
(@arg chunks: -c --chunks [name]... "Dumps named chunks from an entry")
(@group files =>
(@attributes +required +multiple)
(@arg map: -m --map [file]... {exists} "Loads Map files")
(@arg shp: -s --shp [file]... {exists} "Loads Shapes files")
(@arg snd: -n --snd [file]... {exists} "Loads Sounds files")));
let sub_info =
clap_app!(@subcommand info =>
(about: "Outputs debug info")
(@group files =>
(@attributes +required +multiple)
(@arg map: -m --map [file]... {exists} "Loads a Map file")
(@arg shp: -s --shp [file]... {exists} "Loads a Shapes file")
(@arg snd: -n --snd [file]... {exists} "Loads a Sounds file")));
(@arg map: -m --map [file]... {exists} "Loads Map files")
(@arg shp: -s --shp [file]... {exists} "Loads Shapes files")
(@arg snd: -n --snd [file]... {exists} "Loads Sounds files")));
let opt =
clap_app!((env!("CARGO_PKG_NAME")) =>

View File

@ -48,7 +48,26 @@
#![deny(clippy::used_underscore_binding)]
#[macro_use]
pub mod durandal;
pub mod marathon;
pub mod ffi;
#[macro_use]
pub mod err;
#[macro_use]
pub mod cenum;
#[macro_use]
pub mod bin;
pub mod bit;
pub mod cksum;
pub mod defl;
pub mod file;
pub mod fixed;
pub mod image;
pub mod machdr;
pub mod map;
pub mod shp;
pub mod snd;
pub mod sound;
pub mod text;
pub mod xfer;
// EOF

View File

@ -1,6 +1,6 @@
//! Macintosh archived format header utilities.
use crate::durandal::bin::*;
use crate::bin::*;
/// Checks for an `AppleSingle` header. Returns offset to the resource fork.
pub fn check_apple_single(b: &[u8]) -> Option<usize>

View File

@ -32,7 +32,7 @@ pub mod trmf;
pub mod trmg;
pub mod wppx;
use crate::{durandal::err::*, marathon::text::mac_roman_cstr};
use crate::{err::*, text::mac_roman_cstr};
use std::convert::TryFrom;
/// Reads a Map file.
@ -66,9 +66,9 @@ pub fn read(b: &[u8]) -> ResultS<Wad>
bail!("invalid chunk size");
}
let entries = entr::read(b, old_wad, old_dat, siz_app, siz_ent, siz_cnk)?;
let entries = entr::read(b, old_wad, siz_app, siz_ent, siz_cnk)?;
Ok(Wad{name, siz_app, entries})
Ok(Wad{name, siz_app, old_dat, entries})
}
/// A Map file containing entries.
@ -82,6 +82,9 @@ pub struct Wad
/// The size of each `Entry`'s `appdata` field.
pub siz_app: usize,
/// If the data is in Marathon 1 format.
pub old_dat: bool,
/// All of the entries in this `Wad`.
pub entries: entr::EntryMap,
}

View File

@ -1,6 +1,6 @@
//! `SoundAmbi` type.
use crate::durandal::err::*;
use crate::err::*;
/// Reads an `ambi` chunk.
pub fn read(b: &[u8]) -> ResultS<(SoundAmbi, usize)>

View File

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

View File

@ -1,7 +1,6 @@
//! `SoundRand` type.
use crate::durandal::{err::*,
fixed::{Angle, Fixed}};
use crate::{err::*, fixed::{Angle, Fixed}};
use bitflags::bitflags;
/// Reads a `bonk` chunk.

View File

@ -1,18 +1,13 @@
//! Wad file chunk type.
use crate::{durandal::{bin::*, err::*, image}, marathon::{map, pict}};
use crate::{bin::*, err::*, image::{self, pict}, map};
/// Reads all chunks in an entry.
pub fn read(b: &[u8], old: bool, siz_cnk: usize) -> ResultS<Vec<Chunk>>
pub fn read(b: &[u8], siz_cnk: usize) -> ResultS<Vec<ChunkData>>
{
let mut chunks = Vec::new();
let mut p = 0;
let read_chunk_minf = if old {map::minf::read_old} else {map::minf::read};
let read_chunk_sids = if old {map::sids::read_old} else {map::sids::read};
let read_chunk_poly = if old {map::poly::read_old} else {map::poly::read};
let read_chunk_lite = if old {map::lite::read_old} else {map::lite::read};
while p < b.len() {
read_data! {
endian: BIG, buf: b, size: siz_cnk, start: p, data {
@ -23,34 +18,9 @@ pub fn read(b: &[u8], old: bool, siz_cnk: usize) -> ResultS<Vec<Chunk>>
let beg = p + siz_cnk;
let end = beg + size;
let data = ok!(b.get(beg..end), "not enough data")?;
let data = ok!(b.get(beg..end), "not enough data")?.to_vec();
chunks.push(match &iden.0 {
b"PICT" => Chunk::Pict(pict::load_pict(data)?),
b"Minf" => Chunk::Minf(read_chunk_minf(data)?),
b"iidx" => Chunk::Iidx(rd_array(data, map::iidx::read)?),
b"EPNT" => Chunk::Epnt(rd_array(data, map::epnt::read)?),
b"PNTS" => Chunk::Pnts(rd_array(data, map::pnts::read)?),
b"LINS" => Chunk::Lins(rd_array(data, map::lins::read)?),
b"SIDS" => Chunk::Sids(rd_array(data, read_chunk_sids)?),
b"POLY" => Chunk::Poly(rd_array(data, read_chunk_poly)?),
b"OBJS" => Chunk::Objs(rd_array(data, map::objs::read)?),
b"LITE" => Chunk::Lite(rd_array(data, read_chunk_lite)?),
b"plac" => Chunk::Plac(rd_array(data, map::plac::read)?),
b"ambi" => Chunk::Ambi(rd_array(data, map::ambi::read)?),
b"bonk" => Chunk::Bonk(rd_array(data, map::bonk::read)?),
b"medi" => Chunk::Medi(rd_array(data, map::medi::read)?),
b"plat" => Chunk::Plat(rd_array(data, map::plat::read)?),
b"NAME" => Chunk::Name(rd_array(data, map::name::read)?),
b"NOTE" => Chunk::Note(rd_array(data, map::note::read)?),
b"term" => Chunk::Term(rd_array(data, map::term::read)?),
b"FXpx" => Chunk::Fxpx(rd_array(data, map::fxpx::read)?),
b"MNpx" => Chunk::Mnpx(rd_array(data, map::mnpx::read)?),
b"PRpx" => Chunk::Prpx(rd_array(data, map::prpx::read)?),
b"PXpx" => Chunk::Pxpx(rd_array(data, map::pxpx::read)?),
b"WPpx" => Chunk::Wppx(rd_array(data, map::wppx::read)?),
_ => Chunk::Data{iden, data: data.to_vec()},
});
chunks.push(ChunkData{iden, data});
p = end;
}
@ -58,38 +28,93 @@ pub fn read(b: &[u8], old: bool, siz_cnk: usize) -> ResultS<Vec<Chunk>>
Ok(chunks)
}
/// Loads structured data from chunk data.
pub fn load(chunk_data: &[ChunkData], old: bool) -> ResultS<Vec<Chunk>>
{
let mut chunks = Vec::new();
let read_chunk_minf = if old {map::minf::read_old} else {map::minf::read};
let read_chunk_sids = if old {map::sids::read_old} else {map::sids::read};
let read_chunk_poly = if old {map::poly::read_old} else {map::poly::read};
let read_chunk_lite = if old {map::lite::read_old} else {map::lite::read};
for chunk in chunk_data.iter() {
let data = &chunk.data;
let chunk = match &chunk.iden.0 {
b"EPNT" => Chunk::Epnt(rd_array(data, map::epnt::read)?),
b"FXpx" => Chunk::Fxpx(rd_array(data, map::fxpx::read)?),
b"LINS" => Chunk::Lins(rd_array(data, map::lins::read)?),
b"LITE" => Chunk::Lite(rd_array(data, read_chunk_lite)?),
b"MNpx" => Chunk::Mnpx(rd_array(data, map::mnpx::read)?),
b"Minf" => Chunk::Minf(read_chunk_minf(data)?),
b"NAME" => Chunk::Name(rd_array(data, map::name::read)?),
b"NOTE" => Chunk::Note(rd_array(data, map::note::read)?),
b"OBJS" => Chunk::Objs(rd_array(data, map::objs::read)?),
b"PICT" => Chunk::Pict(pict::read(data)?),
b"PNTS" => Chunk::Pnts(rd_array(data, map::pnts::read)?),
b"POLY" => Chunk::Poly(rd_array(data, read_chunk_poly)?),
b"PRpx" => Chunk::Prpx(rd_array(data, map::prpx::read)?),
b"PXpx" => Chunk::Pxpx(rd_array(data, map::pxpx::read)?),
b"SIDS" => Chunk::Sids(rd_array(data, read_chunk_sids)?),
b"WPpx" => Chunk::Wppx(rd_array(data, map::wppx::read)?),
b"ambi" => Chunk::Ambi(rd_array(data, map::ambi::read)?),
b"bonk" => Chunk::Bonk(rd_array(data, map::bonk::read)?),
b"iidx" => Chunk::Iidx(rd_array(data, map::iidx::read)?),
b"medi" => Chunk::Medi(rd_array(data, map::medi::read)?),
b"plac" => Chunk::Plac(rd_array(data, map::plac::read)?),
b"plat" => Chunk::Plat(rd_array(data, map::plat::read)?),
b"term" => Chunk::Term(rd_array(data, map::term::read)?),
_ => Chunk::Data(chunk.clone()),
};
chunks.push(chunk);
}
Ok(chunks)
}
/// The data of a Chunk read from a file.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ChunkData
{
/// The name of the chunk.
pub iden: Ident,
/// The data.
pub data: Vec<u8>,
}
/// Any kind of chunk in an `Entry`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub enum Chunk
{
/** A `PICT` chunk. */ Pict(image::Image8),
/** A `Minf` chunk. */ Minf(map::minf::Minf),
/** An `iidx` chunk. */ Iidx(Vec<u16>),
/** An `EPNT` chunk. */ Epnt(Vec<map::epnt::Endpoint>),
/** A `PNTS` chunk. */ Pnts(Vec<map::pnts::Point>),
/** A `LINS` chunk. */ Lins(Vec<map::lins::Line>),
/** A `SIDS` chunk. */ Sids(Vec<map::sids::Side>),
/** A `POLY` chunk. */ Poly(Vec<map::poly::Polygon>),
/** A `LITE` chunk. */ Lite(Vec<map::lite::Light>),
/** An `OBJS` chunk. */ Objs(Vec<map::objs::Object>),
/** A `plac` chunk. */ Plac(Vec<map::plac::ObjectFreq>),
/** An `ambi` chunk. */ Ambi(Vec<map::ambi::SoundAmbi>),
/** A `bonk` chunk. */ Bonk(Vec<map::bonk::SoundRand>),
/** A `medi` chunk. */ Medi(Vec<map::medi::Media>),
/** A `plat` chunk. */ Plat(Vec<map::plat::Platform>),
/** A `NAME` chunk. */ Name(Vec<String>),
/** A `NOTE` chunk. */ Note(Vec<map::note::Note>),
/** A `term` chunk. */ Term(Vec<map::term::Terminal>),
/** A `FXpx` chunk. */ Fxpx(Vec<map::fxpx::Effect>),
/** A `MNpx` chunk. */ Mnpx(Vec<map::mnpx::Monster>),
/** A `PRpx` chunk. */ Prpx(Vec<map::prpx::Projectile>),
/** A `PXpx` chunk. */ Pxpx(Vec<map::pxpx::Physics>),
/** A `WPpx` chunk. */ Wppx(Vec<map::wppx::Weapon>),
/// Any other type of chunk, which may have arbitrary data in it.
Data{/** The name of the chunk. */ iden: Ident,
/** The data. */ data: Vec<u8>},
/** `EPNT` chunks. */ Epnt(Vec<map::epnt::Endpoint>),
/** `FXpx` chunks. */ Fxpx(Vec<map::fxpx::Effect>),
/** `LINS` chunks. */ Lins(Vec<map::lins::Line>),
/** `LITE` chunks. */ Lite(Vec<map::lite::Light>),
/** `MNpx` chunks. */ Mnpx(Vec<map::mnpx::Monster>),
/** `Minf` chunks. */ Minf(map::minf::Minf),
/** `NAME` chunks. */ Name(Vec<String>),
/** `NOTE` chunks. */ Note(Vec<map::note::Note>),
/** `OBJS` chunks. */ Objs(Vec<map::objs::Object>),
/** `PICT` chunks. */ Pict(image::Image8),
/** `PNTS` chunks. */ Pnts(Vec<map::pnts::Point>),
/** `POLY` chunks. */ Poly(Vec<map::poly::Polygon>),
/** `PRpx` chunks. */ Prpx(Vec<map::prpx::Projectile>),
/** `PXpx` chunks. */ Pxpx(Vec<map::pxpx::Physics>),
/** `SIDS` chunks. */ Sids(Vec<map::sids::Side>),
/** `WPpx` chunks. */ Wppx(Vec<map::wppx::Weapon>),
/** `ambi` chunks. */ Ambi(Vec<map::ambi::SoundAmbi>),
/** `bonk` chunks. */ Bonk(Vec<map::bonk::SoundRand>),
/** `iidx` chunks. */ Iidx(Vec<u16>),
/** `medi` chunks. */ Medi(Vec<map::medi::Media>),
/** `plac` chunks. */ Plac(Vec<map::plac::ObjectFreq>),
/** `plat` chunks. */ Plat(Vec<map::plat::Platform>),
/** `term` chunks. */ Term(Vec<map::term::Terminal>),
/** Unknown chunk. */ Data(ChunkData),
}
// EOF

View File

@ -1,6 +1,6 @@
//! `Damage` type.
use crate::durandal::{err::*, fixed::Fixed};
use crate::{err::*, fixed::Fixed};
use bitflags::bitflags;
use std::convert::TryFrom;

View File

@ -1,13 +1,12 @@
//! Wad file entry type.
use crate::durandal::{bin::usize_from_u32, err::*};
use crate::{bin::usize_from_u32, err::*};
use super::chnk;
use std::collections::BTreeMap;
/// Reads all entries in a `Wad`.
pub fn read(b: &[u8],
old_wad: bool,
old_dat: bool,
siz_app: usize,
siz_ent: usize,
siz_cnk: usize) -> ResultS<EntryMap>
@ -33,7 +32,7 @@ pub fn read(b: &[u8],
let index = if old_wad {i as u16} else {index};
let chunks = chnk::read(&b[offset..offset + size], old_dat, siz_cnk)?;
let chunks = chnk::read(&b[offset..offset + size], siz_cnk)?;
let appdata = b[p..p + siz_app].to_vec();
entries.insert(index, Entry{chunks, appdata});
@ -50,7 +49,7 @@ pub fn read(b: &[u8],
pub struct Entry
{
/// All of the chunks in this `Entry`.
pub chunks: Vec<chnk::Chunk>,
pub chunks: Vec<chnk::ChunkData>,
/// The application specific data for this Entry.
pub appdata: Vec<u8>,

View File

@ -1,7 +1,7 @@
//! `Endpoint` type.
use super::pnts;
use crate::durandal::{err::*, fixed::Unit};
use crate::{err::*, fixed::Unit};
use bitflags::bitflags;
/// Reads an `EPNT` chunk.

View File

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

View File

@ -1,6 +1,6 @@
//! `iidx` chunk.
use crate::durandal::{bin::u16b, err::*};
use crate::{bin::u16b, err::*};
/// Reads an `iidx` chunk.
pub fn read(b: &[u8]) -> ResultS<(u16, usize)>

View File

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

View File

@ -1,7 +1,7 @@
//! `Light` type.
use super::{ltfn, TICKS_PER_SECOND};
use crate::durandal::{err::*, fixed::Fixed};
use crate::{err::*, fixed::Fixed};
use bitflags::bitflags;
use std::convert::TryFrom;

View File

@ -1,6 +1,6 @@
//! `LightFunc` type.
use crate::durandal::{err::*, fixed::Fixed};
use crate::{err::*, fixed::Fixed};
use std::convert::TryFrom;
/// Reads a `LightFunc` object.

View File

@ -1,10 +1,10 @@
//! `Light` type.
use super::pnts;
use crate::{durandal::{bin::OptU16,
err::*,
fixed::{Angle, Fixed, Unit}},
marathon::xfer::TransferMode};
use crate::{bin::OptU16,
err::*,
fixed::{Angle, Fixed, Unit},
xfer::TransferMode};
use bitflags::bitflags;
use std::convert::TryFrom;

View File

@ -1,6 +1,6 @@
//! `Minf` type.
use crate::{durandal::err::*, marathon::text::*};
use crate::{err::*, text::*};
use bitflags::bitflags;
/// Reads a `Minf` chunk.

View File

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

View File

@ -1,6 +1,6 @@
//! `NAME` chunk.
use crate::{durandal::err::*, marathon::text::mac_roman_cstr};
use crate::{err::*, text::mac_roman_cstr};
/// Reads a `NAME` chunk.
pub fn read(b: &[u8]) -> ResultS<(String, usize)>

View File

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

View File

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

View File

@ -1,6 +1,6 @@
//! `ObjectFreq` type.
use crate::durandal::err::*;
use crate::err::*;
use bitflags::bitflags;
/// Reads a `plac` chunk.

View File

@ -1,6 +1,6 @@
//! `Platform` type.
use crate::durandal::{err::*, fixed::Unit};
use crate::{err::*, fixed::Unit};
use bitflags::bitflags;
/// Reads a `plat` chunk.

View File

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

View File

@ -1,8 +1,7 @@
//! `Polygon` type.
use super::pnts;
use crate::{durandal::{bin::OptU16, err::*, fixed::Unit},
marathon::xfer::TransferMode};
use crate::{bin::OptU16, err::*, fixed::Unit, xfer::TransferMode};
use bitflags::bitflags;
use std::convert::TryFrom;

View File

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

View File

@ -1,8 +1,7 @@
//! `Side` type.
use super::stex;
use crate::{durandal::{bin::OptU16, err::*, fixed::Fixed},
marathon::xfer::TransferMode};
use crate::{bin::OptU16, err::*, fixed::Fixed, xfer::TransferMode};
use bitflags::bitflags;
use std::convert::TryFrom;

View File

@ -1,6 +1,6 @@
//! `SideTex` type.
use crate::durandal::{bin::OptU16, err::*};
use crate::{bin::OptU16, err::*};
use super::pnts;
/// Reads a `SideTex` object.

View File

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

View File

@ -1,6 +1,6 @@
//! `Monster` type.
use crate::durandal::{bin::OptU16, err::*, fixed::Unit};
use crate::{bin::OptU16, err::*, fixed::Unit};
use std::convert::TryFrom;
/// Reads a `Trigger` object.

View File

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

View File

@ -1,6 +1,6 @@
//! `Group` type.
use crate::durandal::err::*;
use crate::err::*;
use bitflags::bitflags;
/// Reads an `InterGroup`.

View File

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

View File

@ -1,15 +0,0 @@
//! Library for file format data readers.
pub mod defl;
pub mod machdr;
pub mod map;
pub mod pict;
pub mod ppm;
pub mod shp;
pub mod snd;
pub mod text;
pub mod tga;
pub mod wav;
pub mod xfer;
// EOF

View File

@ -6,7 +6,7 @@ pub mod coll;
pub mod fram;
pub mod sequ;
use crate::durandal::{bin::usize_from_u32, err::*};
use crate::{bin::usize_from_u32, err::*};
/// Reads a collection at an offset provided by the Shapes header.
pub fn read_coll_at_offset(b: &[u8],

View File

@ -1,6 +1,6 @@
//! Shapes file bitmap type.
use crate::durandal::{err::*, image::Image};
use crate::{err::*, image::Image};
use super::clut;
use bitflags::bitflags;

View File

@ -1,6 +1,6 @@
//! Shapes file color lookup tables.
use crate::durandal::{err::*, image::Color};
use crate::{err::*, image::Color};
/// Reads a color from a color table into `clut`.
pub fn read_color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()>

View File

@ -1,6 +1,6 @@
//! Shapes file collection type.
use crate::durandal::{bin::{rd_ofstable, usize_from_u32}, err::*};
use crate::{bin::{rd_ofstable, usize_from_u32}, err::*};
use super::{bmap, clut, fram, sequ};
use std::convert::TryFrom;

View File

@ -1,6 +1,6 @@
//! Shapes file frame type.
use crate::durandal::{err::*, fixed::*};
use crate::{err::*, fixed::*};
use bitflags::bitflags;
/// Reads a `Frame`.

View File

@ -1,8 +1,8 @@
//! Shapes file sequence type.
use crate::{durandal::{bin::OptU16, err::*},
marathon::{text::{mac_roman_conv, pascal_str},
xfer::TransferMode}};
use crate::{bin::OptU16, err::*,
text::{mac_roman_conv, pascal_str},
xfer::TransferMode};
use std::convert::TryFrom;
/// Reads a `Sequence`.

View File

@ -3,7 +3,7 @@
pub mod defs;
pub mod snds;
use crate::durandal::{bin::Ident, err::*};
use crate::{bin::Ident, err::*};
use std::collections::BTreeMap;
/// Reads all sounds from a Sound file.

View File

@ -1,9 +1,6 @@
//! Sounds format definition type.
use crate::durandal::{bin::{u32b, usize_from_u32},
err::*,
fixed::*,
sound::Sound16};
use crate::{bin::{u32b, usize_from_u32}, err::*, fixed::*, sound::Sound16};
use std::convert::TryFrom;
use bitflags::bitflags;

View File

@ -1,6 +1,6 @@
//! Sounds file audio type.
use crate::durandal::{bin::usize_from_u32, err::*, sound::Sound16};
use crate::{bin::usize_from_u32, err::*, sound::Sound16};
/// Reads a sound.
pub fn read(b: &[u8]) -> ResultS<Sound16>

View File

@ -1,5 +1,7 @@
//! Sound representation.
pub mod wav;
/// Any PCM stream which may be represented as a 16-bit PCM stream.
pub trait Sound
{

View File

@ -1,6 +1,6 @@
//! RIFF WAVE format sounds.
use crate::durandal::{err::*, sound::*};
use crate::{err::*, sound::*};
use std::io;
/// Writes a WAVE file from a sound.

View File

@ -5,7 +5,7 @@
/// # Examples
///
/// ```
/// use maraiah::marathon::text::to_binsize;
/// use maraiah::text::to_binsize;
///
/// assert_eq!(to_binsize(5000), "5kB".to_string());
/// ```
@ -57,7 +57,7 @@ pub fn fuck_string(s: &[u8]) -> Vec<u8>
/// # Examples
///
/// ```
/// use maraiah::marathon::text::pascal_str;
/// use maraiah::text::pascal_str;
///
/// assert_eq!(pascal_str(b"\x0bhello world"), b"hello world"[..].into());
/// assert_eq!(pascal_str(b"\x0chello world"), None);
@ -74,7 +74,7 @@ pub fn pascal_str(b: &[u8]) -> Option<&[u8]>
/// # Examples
///
/// ```
/// use maraiah::marathon::text::mac_roman_conv;
/// use maraiah::text::mac_roman_conv;
///
/// assert_eq!(mac_roman_conv(b"p\x8cth"), "påth");
/// assert_eq!(mac_roman_conv(b"I\xd5ve"), "Ive");
@ -101,7 +101,7 @@ pub fn mac_roman_conv(s: &[u8]) -> String
/// # Examples
///
/// ```
/// use maraiah::marathon::text::mac_roman_cstr;
/// use maraiah::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");
@ -122,7 +122,7 @@ pub fn mac_roman_cstr(s: &[u8]) -> String
/// # Examples
///
/// ```
/// use maraiah::marathon::text::to_mac_roman;
/// use maraiah::text::to_mac_roman;
///
/// assert_eq!(to_mac_roman("påth"), b"p\x8cth".to_vec());
/// assert_eq!(to_mac_roman("Ive\n"), b"I\xd5ve\r".to_vec());
@ -155,7 +155,7 @@ pub fn to_mac_roman(s: &str) -> Vec<u8>
/// # Examples
///
/// ```
/// use maraiah::marathon::text::{pad_zero, to_mac_roman};
/// use maraiah::text::{pad_zero, to_mac_roman};
///
/// let s = to_mac_roman("påth");
///

View File

@ -1,4 +1,4 @@
use maraiah::marathon::defl;
use maraiah::defl;
include!("data/rand.rs");

View File

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

View File

@ -1,4 +1,4 @@
use maraiah::marathon::machdr;
use maraiah::machdr;
include!("data/rand.rs");

View File

@ -1,4 +1,4 @@
use maraiah::{durandal::image::Color8, marathon::pict};
use maraiah::{image::{Color8, pict}};
include!("data/rand.rs");

View File

@ -1,4 +1,4 @@
use maraiah::marathon::shp;
use maraiah::shp;
include!("data/rand.rs");

View File

@ -1,4 +1,4 @@
use maraiah::marathon::snd;
use maraiah::snd;
include!("data/rand.rs");