Found bug and fixed it
size is not num elements, but rather size in bytes
This commit is contained in:
20
src/wad.rs
20
src/wad.rs
@@ -23,10 +23,11 @@ pub struct WadHeader {
|
|||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct WadLumpDirectoryEntry {
|
pub struct WadLumpDirectoryEntry {
|
||||||
pub offset: i32,
|
pub offset: i32,
|
||||||
pub size: i32,
|
pub size: i32, // IN BYTES
|
||||||
pub name: [u8; 8],
|
pub name: [u8; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct NiceWadLumpEntry {
|
pub struct NiceWadLumpEntry {
|
||||||
pub offset: i32,
|
pub offset: i32,
|
||||||
pub size: i32,
|
pub size: i32,
|
||||||
@@ -63,12 +64,12 @@ pub fn open_wad(path: &PathBuf) -> WadHeader {
|
|||||||
size: lump.size,
|
size: lump.size,
|
||||||
name: std::str::from_utf8(&lump.name).unwrap().to_string(),
|
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
|
// 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
|
// 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
|
// 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
|
// for their maps - I don't know how you wouldn't
|
||||||
// whether the map reference is _always_ before the THINGS. Might have to try
|
// https://doomwiki.org/wiki/WAD says THINGS always comes after map name
|
||||||
// with some WADs to check
|
|
||||||
if &lump.name == b"THINGS\0\0" {
|
if &lump.name == b"THINGS\0\0" {
|
||||||
assert!(lump_num > 0);
|
assert!(lump_num > 0);
|
||||||
levels_indicies.push((lump_num - 1) as usize);
|
levels_indicies.push((lump_num - 1) as usize);
|
||||||
@@ -77,15 +78,14 @@ pub fn open_wad(path: &PathBuf) -> WadHeader {
|
|||||||
nice_lumps.push(nice_lump);
|
nice_lumps.push(nice_lump);
|
||||||
}
|
}
|
||||||
let mut _level_summaries: Vec<LevelSummary> = Vec::new();
|
let mut _level_summaries: Vec<LevelSummary> = Vec::new();
|
||||||
let mut enemy_maps: Vec<HashMap<Enemy, u16>> = Vec::new();
|
let mut enemy_maps: HashMap<String, HashMap<Enemy, u16>> = HashMap::new();
|
||||||
for level_i in levels_indicies {
|
for level_i in levels_indicies {
|
||||||
let name = nice_lumps.get(level_i).unwrap().name.clone();
|
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();
|
let level_things_wad_lump = nice_lumps.get(level_i + 1).unwrap();
|
||||||
file.seek(SeekFrom::Start(level_things_wad_lump.offset as u64))
|
file.seek(SeekFrom::Start(level_things_wad_lump.offset as u64))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut enemy_map: HashMap<Enemy, u16> = HashMap::new();
|
let mut enemy_map: HashMap<Enemy, u16> = HashMap::new();
|
||||||
for _ in 0..level_things_wad_lump.size {
|
for _ in 0..(level_things_wad_lump.size / std::mem::size_of::<WadThingLump>() as i32) {
|
||||||
let map_thing: WadThingLump = bincode::deserialize_from(&mut file).unwrap();
|
let map_thing: WadThingLump = bincode::deserialize_from(&mut file).unwrap();
|
||||||
// Just checking UV
|
// Just checking UV
|
||||||
if map_thing.options & (1 << 2) > 0 {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
println!("{:#?}", enemy_maps);
|
println!("{:#?}", enemy_maps);
|
||||||
@@ -176,12 +176,12 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_failed() {
|
fn test_failed() {
|
||||||
let freedoom_iwad = PathBuf::from("freedoom1.wad");
|
let freedoom_iwad = PathBuf::from("DOOM2.WAD");
|
||||||
assert!(
|
assert!(
|
||||||
freedoom_iwad.exists(),
|
freedoom_iwad.exists(),
|
||||||
"WAD test need freedoom1.wad - get it from here https://freedoom.github.io"
|
"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!();
|
panic!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user