diff --git a/src/wad.rs b/src/wad.rs index 29af2b6..2f98034 100644 --- a/src/wad.rs +++ b/src/wad.rs @@ -23,10 +23,11 @@ pub struct WadHeader { #[derive(Deserialize, Debug)] pub struct WadLumpDirectoryEntry { pub offset: i32, - pub size: i32, + pub size: i32, // IN BYTES pub name: [u8; 8], } +#[derive(Debug)] pub struct NiceWadLumpEntry { pub offset: i32, pub size: i32, @@ -63,12 +64,12 @@ pub fn open_wad(path: &PathBuf) -> WadHeader { size: lump.size, name: std::str::from_utf8(&lump.name).unwrap().to_string(), }; + println!("{:?}", nice_lump); // I stole this from rust-doom. I looked up idSoftware Linux Doom, but they searched // for the strings "mapXY" or ExMy - I'm not 100% sure, but I bet many PWADs don't // neccesarily use this... I do think that probably PWADs provide different THINGS - // for their maps - I don't know how you wouldn't - what I'm not 100% sure about is - // whether the map reference is _always_ before the THINGS. Might have to try - // with some WADs to check + // for their maps - I don't know how you wouldn't + // https://doomwiki.org/wiki/WAD says THINGS always comes after map name if &lump.name == b"THINGS\0\0" { assert!(lump_num > 0); levels_indicies.push((lump_num - 1) as usize); @@ -77,15 +78,14 @@ pub fn open_wad(path: &PathBuf) -> WadHeader { nice_lumps.push(nice_lump); } let mut _level_summaries: Vec = Vec::new(); - let mut enemy_maps: Vec> = Vec::new(); + let mut enemy_maps: HashMap> = HashMap::new(); for level_i in levels_indicies { let name = nice_lumps.get(level_i).unwrap().name.clone(); - // Presume the THINGS is offset by 1 for the minute let level_things_wad_lump = nice_lumps.get(level_i + 1).unwrap(); file.seek(SeekFrom::Start(level_things_wad_lump.offset as u64)) .unwrap(); let mut enemy_map: HashMap = HashMap::new(); - for _ in 0..level_things_wad_lump.size { + for _ in 0..(level_things_wad_lump.size / std::mem::size_of::() as i32) { let map_thing: WadThingLump = bincode::deserialize_from(&mut file).unwrap(); // Just checking UV if map_thing.options & (1 << 2) > 0 { @@ -97,7 +97,7 @@ pub fn open_wad(path: &PathBuf) -> WadHeader { } } - enemy_maps.push(enemy_map); + enemy_maps.insert(name, enemy_map); break; } println!("{:#?}", enemy_maps); @@ -176,12 +176,12 @@ mod tests { #[test] fn test_failed() { - let freedoom_iwad = PathBuf::from("freedoom1.wad"); + let freedoom_iwad = PathBuf::from("DOOM2.WAD"); assert!( freedoom_iwad.exists(), "WAD test need freedoom1.wad - get it from here https://freedoom.github.io" ); - let ow = open_wad(&freedoom_iwad); + let _ow = open_wad(&freedoom_iwad); panic!(); }