Compare commits

...

2 Commits

Author SHA1 Message Date
an 49253773a6 add NOTE loader 2019-03-01 06:22:27 -05:00
an 144a4ae24a get rid of generic-array 2019-03-01 04:58:02 -05:00
14 changed files with 198 additions and 173 deletions

View File

@ -15,10 +15,9 @@ publish = false
members = ["src/leela", "src/tycho"]
[dependencies]
bitflags = "1.0"
failure = "0.1"
generic-array = "0.12"
serde = {version = "1.0", features = ["derive"]}
bitflags = "1.0"
failure = "0.1"
serde = {version = "1.0", features = ["derive"]}
[profile.dev]
opt-level = 1

View File

@ -378,7 +378,7 @@ Map tags:
| `SIDS` | Array of Side |
| `POLY` | Array of Polygon |
| `LITE` | Array of Light |
| `NOTE` | Not analyzed (annotations) |
| `NOTE` | Array of Annotation |
| `OBJS` | Array of Object |
| `påth` | Not analyzed (guardpaths) (å is $8C) |
| `plac` | Array of Object Frequency |
@ -782,6 +782,20 @@ Light is 100 bytes.
- `ActivPri`, `ActivSec` and `ActivMid` are Light Function structures.
- `InactPri`, `InactSec` and `InactMid` are Light Function structures.
### Map Annotation ###
Map Annotation is 72 bytes.
| Name | Type | Offset |
| ---- | ---- | ------ |
| `Type` | `u16` | `0` |
| `Location` | `struct` | `2` |
| `Polygon` | `u16` | `6` |
| `Text` | `u8[64]` | `8` |
- `Type` is an index into the annotation type definition, but there's only one,
so this will always be `0` anyway.
### Object ###
Object is 16 bytes.

View File

@ -1,7 +1,6 @@
//! Binary data conversion utilities.
use crate::durandal::err::*;
use serde::Serialize;
use std::{fmt, num::NonZeroU16};
#[doc(hidden)]
@ -267,7 +266,7 @@ impl fmt::Debug for OptU16
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
match self.get() {
None => write!(f, "None"),
None => write!(f, "None"),
Some(n) => write!(f, "Some({})", n),
}
}
@ -278,7 +277,7 @@ pub type Ident = [u8; 4];
/// An object identified by a `u16` which may be `u16::max_value()` to
/// represent a nulled value.
#[derive(Serialize)]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct OptU16(Option<NonZeroU16>);
// EOF

View File

@ -1,6 +1,5 @@
//! Fixed point numbers.
use serde::Serialize;
use std::{fmt::{self, Write},
ops};
@ -10,7 +9,7 @@ macro_rules! define_fixed_type {
struct $Type:ident ($IT:ident) : $UT:ident, $LT:ident, $FracBits:expr;
) => {
$(#[$outer])*
#[derive(Clone, PartialEq, Serialize)]
#[derive(Clone, PartialEq, serde::Serialize)]
pub struct $Type($IT);
impl $Type

View File

@ -1,7 +1,6 @@
//! Image and color representations.
use crate::durandal::err::*;
use serde::Serialize;
use std::io;
/// Creates a RGB8 color from a R5G5B5 format color.
@ -187,15 +186,15 @@ impl Color for Color8
}
/// An RGB16 color.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct Color16(u16, u16, u16);
/// An RGB8 color.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct Color8(u8, u8, u8);
/// An RGB16 image.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Image16
{
w: usize,
@ -204,7 +203,7 @@ pub struct Image16
}
/// An RGB8 image.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Image8
{
w: usize,

View File

@ -1,7 +1,6 @@
use maraiah::{durandal::{err::*, file::*, image::*, sound::*, text::*},
use maraiah::{durandal::{err::*, file::*, image::*, sound::*},
marathon::{machdr, shp, snd, wad}};
use std::{fs,
io::{self, Write}};
use std::{fs, io};
fn make_tga(_opt: &Options, fname: &str, im: &impl Image) -> ResultS<()>
{
@ -9,13 +8,6 @@ fn make_tga(_opt: &Options, fname: &str, im: &impl Image) -> ResultS<()>
write_tga(&mut out, im)
}
fn make_data(_opt: &Options, fname: &str, data: &[u8]) -> ResultS<()>
{
let mut out = io::BufWriter::new(fs::File::create(fname)?);
out.write_all(data)?;
Ok(())
}
fn make_yaml<T>(opt: &Options, data: &T) -> ResultS<()>
where T: serde::Serialize + std::fmt::Debug
{
@ -34,29 +26,6 @@ fn make_wav(fname: &str, snd: &impl Sound) -> ResultS<()>
write_wav(&mut out, snd)
}
fn dump_chunk(opt: &Options, cnk: &wad::Chunk, eid: u16) -> ResultS<()>
{
if opt.wad_wrt_all {
match cnk {
wad::Chunk::Pict(im) => {
let fname = format!("{}/pict_{}.tga", opt.out_dir, eid);
make_tga(opt, &fname, im)?;
}
wad::Chunk::Data{iden, data} => {
if opt.wad_unknown {
let iden = mac_roman_conv(iden);
let fname = format!("{}/{:04}{}.bin", opt.out_dir, eid, iden);
make_data(opt, &fname, data)?;
}
make_yaml(opt, cnk)?;
}
_ => make_yaml(opt, cnk)?,
}
}
Ok(())
}
fn process_wad(opt: &Options, b: &[u8]) -> ResultS<()>
{
let wad = wad::read_wad(b)?;
@ -65,10 +34,8 @@ fn process_wad(opt: &Options, b: &[u8]) -> ResultS<()>
make_yaml(opt, &wad.head)?;
}
for (eid, ent) in wad.entries {
for cnk in ent.chunks {
dump_chunk(opt, &cnk, eid)?;
}
if opt.wad_wrt_all {
make_yaml(opt, &wad.entries)?;
}
Ok(())

View File

@ -3,7 +3,6 @@
use crate::{durandal::{bin::*, err::*, fixed::*, text::mac_roman_conv},
marathon::xfer::TransferMode};
use bitflags::bitflags;
use serde::Serialize;
/// Reads a `Minf` chunk.
pub fn read_minf(b: &[u8]) -> ResultS<Minf>
@ -311,8 +310,21 @@ pub fn read_plat(b: &[u8]) -> ResultS<(Platform, usize)>
Ok((Platform{ptype, speed, delay, hei_min, hei_max, flags, index, tag}, 32))
}
/// Reads a `NOTE` chunk.
pub fn read_note(b: &[u8]) -> ResultS<(Note, usize)>
{
read_data! {
72, BE in b =>
pos = read_point[2..6];
poly = u16[6];
text = mac_roman_conv[8..72] nt;
}
Ok((Note{pos, poly, text}, 72))
}
/// A point in world-space.
#[derive(Clone, PartialEq, Serialize)]
#[derive(Clone, PartialEq, serde::Serialize)]
pub struct Point
{
pub x: Unit,
@ -320,7 +332,7 @@ pub struct Point
}
/// A line segment.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Line
{
pub flags: LineFlags,
@ -333,7 +345,7 @@ pub struct Line
}
/// The texture of a side segment.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct SideTex
{
pub offs: Point,
@ -341,7 +353,7 @@ pub struct SideTex
}
/// One side of a line segment.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Side
{
pub stype: SideType,
@ -358,7 +370,7 @@ pub struct Side
}
/// A polygon segment.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Polygon
{
pub ptype: PolyType,
@ -381,7 +393,7 @@ pub struct Polygon
}
/// A light function.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct LightFunc
{
pub ftype: LightFuncType,
@ -392,7 +404,7 @@ pub struct LightFunc
}
/// A dynamic polygon light.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Light
{
pub ltype: LightType,
@ -408,7 +420,7 @@ pub struct Light
}
/// An object in the world.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Object
{
pub group: u16,
@ -423,7 +435,7 @@ pub struct Object
}
/// The difficulty definition for various object types.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct ObjectFreq
{
pub rnd_loc: bool,
@ -435,7 +447,7 @@ pub struct ObjectFreq
}
/// An ambient sound definition.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct SoundAmbi
{
pub index: u16,
@ -443,7 +455,7 @@ pub struct SoundAmbi
}
/// A randomly played sound definition.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct SoundRand
{
pub no_dir: bool,
@ -459,7 +471,7 @@ pub struct SoundRand
}
/// A media, as in a part of a polygon which goes up the middle of the wall.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Media
{
pub mtype: MediaType,
@ -477,7 +489,7 @@ pub struct Media
}
/// Extra information for polygons with platforms.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Platform
{
pub ptype: u16,
@ -490,8 +502,17 @@ pub struct Platform
pub tag: u16,
}
/// Overhead map annotations.
#[derive(Debug, serde::Serialize)]
pub struct Note
{
pub pos: Point,
pub poly: u16,
pub text: String,
}
/// Static map information.
#[derive(Debug, PartialEq, Serialize)]
#[derive(Debug, PartialEq, serde::Serialize)]
pub struct Minf
{
pub env_code: u16,
@ -505,7 +526,7 @@ pub struct Minf
bitflags! {
/// Flags for `Line`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct LineFlags: u16
{
const TransSide = 1 << 9;
@ -519,7 +540,7 @@ bitflags! {
bitflags! {
/// Flags for `Side`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct SideFlags: u16
{
const Status = 1;
@ -535,7 +556,7 @@ bitflags! {
bitflags! {
/// Static environment flags.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct EnvFlags: u16
{
const Vacuum = 1;
@ -556,7 +577,7 @@ bitflags! {
bitflags! {
/// Static entry point flags.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct EntFlags: u32
{
const Solo = 1;
@ -572,7 +593,7 @@ bitflags! {
bitflags! {
/// Static mission flags.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct MsnFlags: u16
{
const Extermination = 1;
@ -585,7 +606,7 @@ bitflags! {
bitflags! {
/// Flags for `Polygon`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct PolyFlags: u16
{
const Detached = 1 << 14;
@ -594,7 +615,7 @@ bitflags! {
bitflags! {
/// Flags for `Light`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct LightFlags: u16
{
const InitActive = 1;
@ -605,7 +626,7 @@ bitflags! {
bitflags! {
/// Flags for `Object`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct ObjectFlags: u16
{
const Invisible = 1;
@ -619,7 +640,7 @@ bitflags! {
bitflags! {
/// Flags for `Platform`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct PlatformFlags: u32
{
const InitActive = 1;
@ -654,7 +675,7 @@ bitflags! {
c_enum! {
/// The texture type of a `Side`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum SideType: u16
{
0 => Full,
@ -667,7 +688,7 @@ c_enum! {
c_enum! {
/// The action type of a `Polygon`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum PolyType: u16
{
0 => Normal,
@ -694,7 +715,7 @@ c_enum! {
c_enum! {
/// The type of function for a `LightFunc`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum LightFuncType: u16
{
0 => Constant,
@ -706,7 +727,7 @@ c_enum! {
c_enum! {
/// The type of a `Light`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum LightType: u16
{
0 => Normal,
@ -717,7 +738,7 @@ c_enum! {
c_enum! {
/// The liquid type of a `Media`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum MediaType: u16
{
0 => Water,

View File

@ -2,7 +2,6 @@
use crate::{durandal::{bin::*, err::*, fixed::*}};
use bitflags::bitflags;
use serde::Serialize;
/// Reads a `PXpx` chunk.
pub fn read_pxpx(b: &[u8]) -> ResultS<(Physics, usize)>
@ -284,7 +283,7 @@ fn read_attack(b: &[u8]) -> ResultS<Attack>
}
/// Static physics information.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Physics
{
pub acc_ang: Fixed,
@ -316,7 +315,7 @@ pub struct Physics
}
/// An effect definition.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Effect
{
pub collection: u16,
@ -328,7 +327,7 @@ pub struct Effect
}
/// A weapon definition.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Weapon
{
pub amp_bob: Fixed,
@ -359,7 +358,7 @@ pub struct Weapon
}
/// The definition of one of two triggers for a weapon.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Trigger
{
pub burst: u16,
@ -383,7 +382,7 @@ pub struct Trigger
}
/// A projectile definition.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Projectile
{
pub collection: OptU16,
@ -406,7 +405,7 @@ pub struct Projectile
}
/// A monster definition.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Monster
{
pub collection: u16,
@ -463,7 +462,7 @@ pub struct Monster
}
/// A damage definition.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Damage
{
pub dtype: DamageType,
@ -474,7 +473,7 @@ pub struct Damage
}
/// The definition of a monster's attack.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Attack
{
pub ptype: OptU16,
@ -489,7 +488,7 @@ pub struct Attack
bitflags! {
/// Flags for an effect.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct EffectFlags: u16
{
const EndOnLoop = 1;
@ -502,7 +501,7 @@ bitflags! {
bitflags! {
/// Flags for a weapon.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct WeaponFlags: u16
{
const Automatic = 1;
@ -521,7 +520,7 @@ bitflags! {
bitflags! {
/// Flags for a projectile.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct ProjectileFlags: u32
{
const Guided = 1;
@ -550,7 +549,7 @@ bitflags! {
bitflags! {
/// Flags for a monster.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct MonsterFlags: u32
{
const IgnoreLOS = 1;
@ -586,7 +585,7 @@ bitflags! {
bitflags! {
/// The composite type of a monster.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct MonsterClass: u32
{
const Player = 1;
@ -610,7 +609,7 @@ bitflags! {
bitflags! {
/// The composite type of damage taken by something.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct DamageTypeFlags: u32
{
const Explosion = 1;
@ -642,7 +641,7 @@ bitflags! {
c_enum! {
/// A bullet shell casing emitted by a weapon.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum CasingType: u16
{
0 => Rifle,
@ -656,7 +655,7 @@ c_enum! {
c_enum! {
/// The type of functionality a weapon provides.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum WeaponType: u16
{
0 => Melee,
@ -669,7 +668,7 @@ c_enum! {
c_enum! {
/// A named type of damage taken by something.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum DamageType: u16
{
0 => Explosion,

View File

@ -1,7 +1,6 @@
//! QuickDraw PICT format loader.
use crate::durandal::{bin::*, err::*, image::*};
use generic_array::*;
/// Reads a `PixMap` header.
fn read_pm_header<'a>(b: &'a [u8],
@ -77,7 +76,7 @@ fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
} else if hdr.rle {
// RLE compressed 1, 2, 4 or 8 bit colormap indices
for _ in 0..im.h() {
let (d, pp) = read_rle(&b[p..], hdr.pitch, false)?;
let (d, pp) = read_rle::<u8>(&b[p..], hdr.pitch)?;
let d = if hdr.depth < 8 {
expand_data(d, hdr.depth)?
} else {
@ -117,12 +116,11 @@ fn read_pm_16(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
} else if hdr.rle {
// RLE compressed R5G5B5
for _ in 0..im.h() {
let (d, pp) = read_rle(&b[p..], hdr.pitch, true)?;
let (d, pp) = read_rle::<u16>(&b[p..], hdr.pitch)?;
p += pp;
for x in 0..im.w() {
let cr = u16b(&d[x * 2..]);
for &cr in &d {
im.cr.push(r5g5b5_to_rgb8(cr));
}
}
@ -167,7 +165,7 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
// RLE compressed RGB8
let pitch = hdr.pitch - im.w(); // remove padding byte from pitch
for _ in 0..im.h() {
let (d, pp) = read_rle(&b[p..], pitch, false)?;
let (d, pp) = read_rle::<u8>(&b[p..], pitch)?;
p += pp;
@ -230,11 +228,11 @@ pub fn load_pict(b: &[u8]) -> ResultS<Image8>
// PackBitsRgn
return read_pm_area(im, &b[p..], true, true);
}
0x009a => {
0x009A => {
// DirectBitsRect
return read_pm_area(im, &b[p..], false, false);
}
0x009b => {
0x009B => {
// DirectBitsRgn
return read_pm_area(im, &b[p..], false, true);
}
@ -242,57 +240,57 @@ pub fn load_pict(b: &[u8]) -> ResultS<Image8>
// CompressedQuickTime
unimplemented!();
}
0x00ff => {
0x00FF => {
// OpEndPic
break;
}
// help i'm trapped in an awful metafile format from the 80s
0x0000 | // NoOp
0x001c | // HiliteMode
0x001e | // DefHilite
0x001C | // HiliteMode
0x001E | // DefHilite
0x0038 | // FrameSameRect
0x0039 | // PaintSameRect
0x003a | // EraseSameRect
0x003b | // InvertSameRect
0x003c | // FillSameRect
0x003A | // EraseSameRect
0x003B | // InvertSameRect
0x003C | // FillSameRect
0x8000 | // Reserved
0x8100 => (), // Reserved
0x0003 | // TxFont
0x0004 | // TxFace
0x0005 | // TxMode
0x0008 | // PnMode
0x000d | // TxSize
0x000D | // TxSize
0x0011 | // VersionOp
0x0015 | // PnLocHFrac
0x0016 | // ChExtra
0x0023 | // ShortLineFrom
0x00a0 => p += 2, // ShortComment
0x00A0 => p += 2, // ShortComment
0x0006 | // SpExtra
0x0007 | // PnSize
0x000b | // OvSize
0x000c | // Origin
0x000e | // FgCol
0x000f | // BkCol
0x000B | // OvSize
0x000C | // Origin
0x000E | // FgCol
0x000F | // BkCol
0x0021 => p += 4, // LineFrom
0x001a | // RGBFgCol
0x001b | // RGBBkCol
0x001d | // TxRatio
0x001A | // RGBFgCol
0x001B | // RGBBkCol
0x001D | // TxRatio
0x0022 => p += 6, // ShortLine
0x0002 | // BkPat
0x0009 | // PnPat
0x0010 | // TxRatio
0x0020 | // Line
0x002e | // GlyphState
0x002E | // GlyphState
0x0030 | // FrameRect
0x0031 | // PaintRect
0x0032 | // EraseRect
0x0033 | // InvertRect
0x0034 => p += 8, // FillRect
0x002d => p += 10, // LineJustify
0x002D => p += 10, // LineJustify
0x0001 => p += (u16b(&b[p.. ]) & !1) as usize, // Clip
0x00a1 => p += (u16b(&b[p+2..]) & !1) as usize + 2, // LongComment
0x00A1 => p += (u16b(&b[p+2..]) & !1) as usize + 2, // LongComment
0x100..=
0x7fff => p += (op >> 8) as usize * 2, // Reserved
0x7FFF => p += (op >> 8) as usize * 2, // Reserved
_ => {
bail!("invalid op in PICT");
}
@ -338,7 +336,8 @@ pub fn get_clut(b: &[u8]) -> ResultS<(Vec<Color8>, usize)>
}
/// Read run-length encoded data.
pub fn read_rle(b: &[u8], pitch: usize, ln: bool) -> ResultS<(Vec<u8>, usize)>
fn read_rle<T>(b: &[u8], pitch: usize) -> ResultS<(Vec<T>, usize)>
where T: ReadRleData
{
let mut p = 0;
let mut o = Vec::with_capacity(pitch);
@ -357,11 +356,7 @@ pub fn read_rle(b: &[u8], pitch: usize, ln: bool) -> ResultS<(Vec<u8>, usize)>
p += 1;
o.reserve(len);
if ln {
read_rle_data(cmp, len, &mut o, || (arr![u8; b[p], b[p+1]], p += 2).0);
} else {
read_rle_data(cmp, len, &mut o, || (arr![u8; b[p] ], p += 1).0);
}
T::read_rle_data(b, &mut p, cmp, len, &mut o);
}
if o.len() == pitch {
@ -371,23 +366,59 @@ pub fn read_rle(b: &[u8], pitch: usize, ln: bool) -> ResultS<(Vec<u8>, usize)>
}
}
/// Read a sequence of packed RLE data.
fn read_rle_data<F, N>(cmp: bool, len: usize, out: &mut Vec<u8>, mut read: F)
where F: FnMut() -> GenericArray<u8, N>,
N: ArrayLength<u8>
trait ReadRleData: Sized
{
if cmp {
let d = read();
for _ in 0..len {
for v in d.iter() {
out.push(*v);
/// Read a sequence of packed RLE data.
fn read_rle_data(b: &[u8],
p: &mut usize,
cmp: bool,
len: usize,
out: &mut Vec<Self>);
}
impl ReadRleData for u16
{
fn read_rle_data(b: &[u8],
p: &mut usize,
cmp: bool,
len: usize,
out: &mut Vec<u16>)
{
if cmp {
let d = u16b(&b[*p..*p + 2]);
*p += 2;
for _ in 0..len {
out.push(d);
}
} else {
for _ in 0..len {
let d = u16b(&b[*p..*p + 2]);
*p += 2;
out.push(d);
}
}
} else {
for _ in 0..len {
let d = read();
for v in d.iter() {
out.push(*v);
}
}
impl ReadRleData for u8
{
fn read_rle_data(b: &[u8],
p: &mut usize,
cmp: bool,
len: usize,
out: &mut Vec<u8>)
{
if cmp {
let d = b[*p];
*p += 1;
for _ in 0..len {
out.push(d);
}
} else {
for _ in 0..len {
let d = b[*p];
*p += 1;
out.push(d);
}
}
}

View File

@ -3,7 +3,6 @@
use crate::{durandal::{bin::*, err::*, fixed::*, image::*, text::*},
marathon::xfer::TransferMode};
use bitflags::bitflags;
use serde::Serialize;
/// Reads a color from a color table into `clut`.
fn read_color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()>
@ -312,7 +311,7 @@ impl Color for ColorShp
}
/// A color in an `ImageShp`'s color table.
#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Debug, serde::Serialize)]
pub enum ColorShp
{
Translucent,
@ -345,7 +344,7 @@ pub struct ImageShp<'a, 'b>
}
/// A frame, also known as a low level shape.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Frame
{
flags: FrameFlags,
@ -360,7 +359,7 @@ pub struct Frame
}
/// A sequence, also known as a high level shape.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Sequence
{
name: String,
@ -400,7 +399,7 @@ bitflags! {
bitflags! {
/// Flags for `Frame`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct FrameFlags: u16
{
const Obscure = 1 << 13;
@ -411,7 +410,7 @@ bitflags! {
c_enum! {
/// The type of a collection.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum CollectionType: u16
{
0 => Unused,
@ -424,7 +423,7 @@ c_enum! {
c_enum! {
/// The type of or number of views for a sequence.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum ViewType: u16
{
1 => Anim,

View File

@ -2,7 +2,6 @@
use crate::durandal::{bin::*, err::*, fixed::*, sound::*};
use bitflags::bitflags;
use serde::Serialize;
use std::collections::BTreeMap;
/// Reads a sound.
@ -125,7 +124,7 @@ pub fn read_sounds(b: &[u8]) -> ResultS<Vec<SoundTable>>
}
/// The header of a sound definition.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct SoundHead
{
pub volume: Volume,
@ -147,7 +146,7 @@ pub type SoundTable = BTreeMap<u16, SoundDef>;
bitflags! {
/// Flags for `SoundHead`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct SoundFlags: u16
{
const NoRestart = 1;
@ -162,7 +161,7 @@ bitflags! {
c_enum! {
/// The type of volume this sound has.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum Volume: u16
{
0 => Quiet,

View File

@ -2,7 +2,6 @@
use crate::durandal::{err::*, text::*};
use bitflags::bitflags;
use serde::Serialize;
use std::fmt;
/// Reads a `Group`.
@ -82,7 +81,7 @@ pub fn read_term(b: &[u8]) -> ResultS<(Terminal, usize)>
}
/// A terminal definition, with collections of groups and faces.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Terminal
{
lines: u16,
@ -91,7 +90,7 @@ pub struct Terminal
}
/// A text face.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Face
{
start: usize,
@ -100,7 +99,7 @@ pub struct Face
}
/// A terminal command grouping.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct Group
{
flags: GroupFlags,
@ -112,7 +111,7 @@ pub struct Group
bitflags! {
/// Flags for `Group`.
#[derive(Serialize)]
#[derive(serde::Serialize)]
pub struct GroupFlags: u16
{
const DrawOnRight = 1;
@ -122,7 +121,7 @@ bitflags! {
c_enum! {
/// The command of a `Group`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum GroupType: u16
{
0 => Logon,

View File

@ -2,7 +2,6 @@
use crate::durandal::{bin::*, err::*, image, text::mac_roman_conv};
use crate::marathon::{map, phy, pict, trm};
use serde::Serialize;
use std::collections::BTreeMap;
/// Reads all chunks in an entry.
@ -37,6 +36,7 @@ pub fn read_chunks(b: &[u8], siz_cnk: usize) -> ResultS<Vec<Chunk>>
b"bonk" => Chunk::Bonk(rd_array(data, map::read_bonk)?),
b"medi" => Chunk::Medi(rd_array(data, map::read_medi)?),
b"plat" => Chunk::Plat(rd_array(data, map::read_plat)?),
b"NOTE" => Chunk::Note(rd_array(data, map::read_note)?),
b"term" => Chunk::Term(rd_array(data, trm::read_term)?),
b"FXpx" => Chunk::Fxpx(rd_array(data, phy::read_fxpx)?),
b"MNpx" => Chunk::Mnpx(rd_array(data, phy::read_mnpx)?),
@ -115,11 +115,11 @@ pub fn read_wad(b: &[u8]) -> ResultS<Wad>
let siz_ent = if is_old {8 } else {10};
let siz_cnk = if is_old {12} else {16};
if siz_ent != wentsize {
if siz_ent != siz_went {
bail!("invalid entry size");
}
if siz_cnk != wcnksize {
if siz_cnk != siz_wcnk {
bail!("invalid chunk size");
}
@ -129,7 +129,7 @@ pub fn read_wad(b: &[u8]) -> ResultS<Wad>
}
/// Any kind of chunk in an `Entry`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum Chunk
{
Pict(image::Image8),
@ -145,6 +145,7 @@ pub enum Chunk
Bonk(Vec<map::SoundRand>),
Medi(Vec<map::Media>),
Plat(Vec<map::Platform>),
Note(Vec<map::Note>),
Term(Vec<trm::Terminal>),
Fxpx(Vec<phy::Effect>),
Mnpx(Vec<phy::Monster>),
@ -155,7 +156,7 @@ pub enum Chunk
}
/// An entry containing chunks and application-specific data.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Entry
{
pub chunks: Vec<Chunk>,
@ -163,7 +164,7 @@ pub struct Entry
}
/// The header of a `Wad`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct WadHeader
{
pub ver_wad: Ver,
@ -173,7 +174,7 @@ pub struct WadHeader
}
/// A Map file containing entries.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub struct Wad
{
pub head: WadHeader,
@ -182,7 +183,7 @@ pub struct Wad
c_enum! {
/// The version of a `Wad`.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum Ver: u16
{
0 => Base,

View File

@ -1,11 +1,10 @@
//! Transfer Mode type.
use crate::durandal::err::*;
use serde::Serialize;
c_enum! {
/// A rendering style for many things.
#[derive(Debug, Serialize)]
#[derive(Debug, serde::Serialize)]
pub enum TransferMode: u16
{
0 => Normal,