Maraiah/source/marathon/map.rs

104 lines
2.0 KiB
Rust
Raw Normal View History

2019-04-11 21:04:39 -07:00
//! Marathon Map format handling.
2019-03-01 01:27:14 -08:00
2019-04-01 00:39:47 -07:00
pub mod ambi;
2019-04-11 21:04:39 -07:00
pub mod attk;
2019-04-01 00:39:47 -07:00
pub mod bonk;
2019-04-11 21:04:39 -07:00
pub mod chnk;
pub mod damg;
pub mod entr;
2019-04-01 00:39:47 -07:00
pub mod epnt;
2019-04-11 21:04:39 -07:00
pub mod fxpx;
2019-04-01 00:39:47 -07:00
pub mod iidx;
pub mod lins;
pub mod lite;
pub mod ltfn;
pub mod medi;
pub mod minf;
2019-04-11 21:04:39 -07:00
pub mod mnpx;
2019-04-01 00:39:47 -07:00
pub mod note;
pub mod objs;
pub mod plac;
pub mod plat;
pub mod pnts;
pub mod poly;
2019-04-11 21:04:39 -07:00
pub mod prpx;
pub mod pxpx;
2019-04-01 00:39:47 -07:00
pub mod sids;
pub mod stex;
2019-04-01 02:09:01 -07:00
pub mod term;
2019-04-11 21:04:39 -07:00
pub mod trig;
2019-04-01 02:09:01 -07:00
pub mod trmf;
pub mod trmg;
2019-04-11 21:04:39 -07:00
pub mod wppx;
use crate::{durandal::err::*, marathon::text::mac_roman_cstr};
use std::convert::TryFrom;
/// Reads a Map file.
pub fn read(b: &[u8]) -> ResultS<Wad>
{
read_data! {
endian: BIG, buf: b, size: 128, start: 0, data {
let ver_wad = u16[0] enum Ver;
let ver_dat = u16[2];
let name = mac_roman_cstr[4; 64] no_try;
let siz_app = u16[78] usize;
let siz_wcnk = u16[80] usize;
let siz_went = u16[82] usize;
}
}
let old_dat = ver_dat == 0;
let old_wad = match ver_wad {
Ver::Base => true,
_ => false,
};
let siz_ent = if old_wad {8 } else {10};
let siz_cnk = if old_wad {12} else {16};
if !old_wad && siz_ent != siz_went {
bail!("invalid entry size");
}
if !old_wad && siz_cnk != siz_wcnk {
bail!("invalid chunk size");
}
let entries = entr::read(b, old_wad, old_dat, siz_app, siz_ent, siz_cnk)?;
Ok(Wad{name, siz_app, entries})
}
/// A Map file containing entries.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub struct Wad
{
/// The original name of this file.
pub name: String,
/// The size of each `Entry`'s `appdata` field.
pub siz_app: usize,
/// All of the entries in this `Wad`.
pub entries: entr::EntryMap,
}
c_enum! {
/// The version of a `Wad`.
#[derive(Debug)]
enum Ver: u16
{
Base = 0,
Dir = 1,
Over = 2,
Inf = 4,
}
}
2019-02-20 12:24:47 -08:00
2019-03-09 14:03:20 -08:00
/// The number of game ticks per second.
2019-03-01 20:04:20 -08:00
pub const TICKS_PER_SECOND: u16 = 30;
2018-12-11 19:59:15 -08:00
// EOF