move trm to map module

gui-branch
an 2019-04-01 05:09:01 -04:00
parent c8ebe009e7
commit b3ff145f63
6 changed files with 112 additions and 99 deletions

View File

@ -10,7 +10,6 @@ pub mod shp;
pub mod snd;
pub mod text;
pub mod tga;
pub mod trm;
pub mod wad;
pub mod wav;
pub mod xfer;

View File

@ -17,6 +17,9 @@ pub mod pnts;
pub mod poly;
pub mod sids;
pub mod stex;
pub mod term;
pub mod trmf;
pub mod trmg;
/// The number of game ticks per second.
pub const TICKS_PER_SECOND: u16 = 30;

View File

@ -0,0 +1,54 @@
//! `Terminal` type.
use crate::{durandal::{bin, err::*}, marathon::text};
use super::{trmf, trmg};
/// Reads a `term` chunk.
pub fn read(b: &[u8]) -> ResultS<(Terminal, usize)>
{
read_data! {
endian: BIG, buf: b, size: 10, start: 0, data {
let end = u16[0] usize;
let encoded = u16[2];
let lines = u16[4];
let group_n = u16[6] usize;
let face_n = u16[8] 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 mut groups = Vec::with_capacity(group_n);
for grp in &i_grp {
let flags = grp.flags;
let ttype = grp.ttype;
let lines = grp.lines;
let beg = grp.beg;
let len = grp.len;
let text = ok!(text.get(beg..beg + len), "bad offset")?;
let text = text::mac_roman_cstr(text);
groups.push(trmg::Group{flags, ttype, lines, text});
}
Ok((Terminal{lines, groups, faces}, end))
}
/// A terminal definition, with collections of groups and faces.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub struct Terminal
{
pub lines: u16,
pub groups: Vec<trmg::Group>,
pub faces: Vec<trmf::Face>,
}
// EOF

View File

@ -0,0 +1,29 @@
//! `Face` type.
use crate::durandal::err::*;
/// Reads a `Face`.
pub fn read(b: &[u8]) -> ResultS<(Face, usize)>
{
read_data! {
endian: BIG, buf: b, size: 6, start: 0, data {
let start = u16[0] usize;
let face = u16[2];
let color = u16[4];
}
}
Ok((Face{start, face, color}, 6))
}
/// A text face.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub struct Face
{
pub start: usize,
pub face: u16,
pub color: u16,
}
// EOF

View File

@ -1,10 +1,10 @@
//! Structures used by Marathon's Map format's terminal definitions.
//! `Group` type.
use crate::{durandal::{bin::*, err::*}, marathon::text::*};
use crate::durandal::err::*;
use bitflags::bitflags;
/// Reads an `InterGroup`.
pub fn read_group(b: &[u8]) -> ResultS<(InterGroup, usize)>
pub fn read(b: &[u8]) -> ResultS<(InterGroup, usize)>
{
read_data! {
endian: BIG, buf: b, size: 12, start: 0, data {
@ -41,94 +41,11 @@ pub fn read_group(b: &[u8]) -> ResultS<(InterGroup, usize)>
Ok((InterGroup{flags, ttype, lines, beg, len}, 12))
}
/// Reads a `Face`.
pub fn read_face(b: &[u8]) -> ResultS<(Face, usize)>
{
read_data! {
endian: BIG, buf: b, size: 6, start: 0, data {
let start = u16[0] usize;
let face = u16[2];
let color = u16[4];
}
}
Ok((Face{start, face, color}, 6))
}
/// Reads a `term` chunk.
pub fn read_term(b: &[u8]) -> ResultS<(Terminal, usize)>
{
read_data! {
endian: BIG, buf: b, size: 10, start: 0, data {
let end = u16[0] usize;
let encoded = u16[2];
let lines = u16[4];
let group_n = u16[6] usize;
let face_n = u16[8] usize;
}
}
let encoded = encoded != 0;
let (i_grp, x) = rd_array_num(&b[10..], group_n, read_group)?;
let (faces, y) = rd_array_num(&b[10 + x..], face_n, read_face)?;
let text = ok!(b.get(10 + x + y..end), "not enough data")?;
let text = if encoded {fuck_string(text)} else {text.to_vec()};
let mut groups = Vec::with_capacity(group_n);
for grp in &i_grp {
let flags = grp.flags;
let ttype = grp.ttype;
let lines = grp.lines;
let beg = grp.beg;
let len = grp.len;
let text = ok!(text.get(beg..beg + len), "bad offset")?;
let text = mac_roman_cstr(text);
groups.push(Group{flags, ttype, lines, text});
}
Ok((Terminal{lines, groups, faces}, end))
}
impl Default for GroupType
{
fn default() -> Self {GroupType::Unfinished}
}
/// A terminal definition, with collections of groups and faces.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub struct Terminal
{
pub lines: u16,
pub groups: Vec<Group>,
pub faces: Vec<Face>,
}
/// A text face.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub struct Face
{
pub start: usize,
pub face: u16,
pub color: u16,
}
/// A terminal command grouping.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub struct Group
{
pub flags: GroupFlags,
pub ttype: GroupType,
pub lines: u16,
pub text: String,
}
/// Interim structure.
#[derive(Debug, Eq, PartialEq)]
pub struct InterGroup
@ -140,6 +57,17 @@ pub struct InterGroup
pub len: usize,
}
/// A terminal command grouping.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub struct Group
{
pub flags: GroupFlags,
pub ttype: GroupType,
pub lines: u16,
pub text: String,
}
/// The command of a `Group`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

View File

@ -1,20 +1,20 @@
//! Marathon Wad format handling.
use crate::{durandal::{bin::*, err::*, image},
marathon::{map, phy, pict, text::mac_roman_cstr, trm}};
marathon::{map, phy, pict, text::mac_roman_cstr}};
use std::collections::BTreeMap;
/// Reads all chunks in an entry.
pub fn read_chunks(b: &[u8], old_dat: bool, siz_cnk: usize)
pub fn read_chunks(b: &[u8], old: bool, siz_cnk: usize)
-> ResultS<Vec<Chunk>>
{
let mut chunks = Vec::new();
let mut p = 0;
let rd_minf = if old_dat {map::minf::read_old} else {map::minf::read};
let rd_sids = if old_dat {map::sids::read_old} else {map::sids::read};
let rd_poly = if old_dat {map::poly::read_old} else {map::poly::read};
let rd_lite = if old_dat {map::lite::read_old} else {map::lite::read};
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! {
@ -30,22 +30,22 @@ pub fn read_chunks(b: &[u8], old_dat: bool, siz_cnk: usize)
chunks.push(match &iden.0 {
b"PICT" => Chunk::Pict(pict::load_pict(data)?),
b"Minf" => Chunk::Minf(rd_minf(data)?),
b"Minf" => Chunk::Minf(read_chunk_minf(data)?),
b"iidx" => Chunk::Iidx(rd_array(data, map::iidx::read)?),
b"EPNT" => Chunk::Pnts(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, rd_sids)?),
b"POLY" => Chunk::Poly(rd_array(data, rd_poly)?),
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, rd_lite)?),
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"NOTE" => Chunk::Note(rd_array(data, map::note::read)?),
b"term" => Chunk::Term(rd_array(data, trm::read_term)?),
b"term" => Chunk::Term(rd_array(data, map::term::read)?),
b"FXpx" => Chunk::Fxpx(rd_array(data, phy::fxpx::read)?),
b"MNpx" => Chunk::Mnpx(rd_array(data, phy::mnpx::read)?),
b"PRpx" => Chunk::Prpx(rd_array(data, phy::prpx::read)?),
@ -157,7 +157,7 @@ pub enum Chunk
/** A `medi` chunk. */ Medi(Vec<map::medi::Media>),
/** A `plat` chunk. */ Plat(Vec<map::plat::Platform>),
/** A `NOTE` chunk. */ Note(Vec<map::note::Note>),
/** A `term` chunk. */ Term(Vec<trm::Terminal>),
/** A `term` chunk. */ Term(Vec<map::term::Terminal>),
/** A `FXpx` chunk. */ Fxpx(Vec<phy::fxpx::Effect>),
/** A `MNpx` chunk. */ Mnpx(Vec<phy::mnpx::Monster>),
/** A `PRpx` chunk. */ Prpx(Vec<phy::prpx::Projectile>),