separate minf loading to its own file
parent
fd37b9a6b8
commit
f9235b086d
39
src/main.rs
39
src/main.rs
|
@ -2,43 +2,10 @@ pub mod durandal;
|
|||
pub mod marathon;
|
||||
|
||||
use crate::durandal::{err::*, image::Image, pict::load_pict};
|
||||
use crate::marathon::{wad, term};
|
||||
use crate::marathon::{map, wad, term};
|
||||
use memmap::Mmap;
|
||||
use std::{io, io::Write, fs, env};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Minf
|
||||
{
|
||||
env_code: u16,
|
||||
physi_id: u16,
|
||||
music_id: u16,
|
||||
msn_flag: u16,
|
||||
env_flag: u16,
|
||||
ent_flag: u32,
|
||||
levelnam: String,
|
||||
}
|
||||
|
||||
impl Minf
|
||||
{
|
||||
fn chunk(b: &[u8]) -> ResultS<Minf>
|
||||
{
|
||||
use crate::durandal::text::mac_roman_conv;
|
||||
use crate::durandal::bin::*;
|
||||
|
||||
if b.len() < 88 {return err_msg("not enough data for Minf")}
|
||||
|
||||
let env_code = b.c_u16b( 0)?;
|
||||
let physi_id = b.c_u16b( 2)?;
|
||||
let music_id = b.c_u16b( 4)?;
|
||||
let msn_flag = b.c_u16b( 6)?;
|
||||
let env_flag = b.c_u16b( 8)?;
|
||||
let levelnam = mac_roman_conv(&b[18..84]);
|
||||
let ent_flag = b.c_u32b(84)?;
|
||||
|
||||
Ok(Minf{env_code, physi_id, music_id, msn_flag, env_flag, ent_flag, levelnam})
|
||||
}
|
||||
}
|
||||
|
||||
fn write_ppm(fname: &str, im: &Image) -> io::Result<()>
|
||||
{
|
||||
let out = fs::File::create(fname)?;
|
||||
|
@ -73,8 +40,8 @@ fn main() -> ResultS<()>
|
|||
}
|
||||
|
||||
if let Some(b) = ent.chunks.get(b"Minf") {
|
||||
let minf = Minf::chunk(b)?;
|
||||
println!("entry {} has Minf {:#?}", id, minf);
|
||||
let minf = map::Minf::chunk(b)?;
|
||||
println!("entry {} has {:#?}", id, minf);
|
||||
}
|
||||
|
||||
if let Some(b) = ent.chunks.get(b"term") {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
use crate::durandal::{bin::*, err::*, text::mac_roman_conv};
|
||||
|
||||
impl Minf
|
||||
{
|
||||
pub fn chunk(b: &[u8]) -> ResultS<Minf>
|
||||
{
|
||||
if b.len() < 88 {return err_msg("not enough data for Minf")}
|
||||
|
||||
let env_code = b.c_u16b( 0)?;
|
||||
let physi_id = b.c_u16b( 2)?;
|
||||
let music_id = b.c_u16b( 4)?;
|
||||
let msn_flag = b.c_u16b( 6)?;
|
||||
let env_flag = b.c_u16b( 8)?;
|
||||
let levelnam = mac_roman_conv(&b[18..84]);
|
||||
let ent_flag = b.c_u32b(84)?;
|
||||
|
||||
Ok(Minf{env_code, physi_id, music_id, msn_flag, env_flag, ent_flag, levelnam})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Minf
|
||||
{
|
||||
env_code: u16,
|
||||
physi_id: u16,
|
||||
music_id: u16,
|
||||
msn_flag: u16,
|
||||
env_flag: u16,
|
||||
ent_flag: u32,
|
||||
levelnam: String,
|
||||
}
|
||||
|
||||
// EOF
|
|
@ -1,5 +1,6 @@
|
|||
//! Library for Marathon data formats.
|
||||
|
||||
pub mod map;
|
||||
pub mod term;
|
||||
pub mod wad;
|
||||
|
||||
|
|
Loading…
Reference in New Issue