Linedef Reader

Added ability to read linedef lumps. Also added all the test
functionality to make sure we are reading the linedefs correctly.
This commit is contained in:
2025-03-30 19:21:52 -04:00
parent 4b3822423f
commit c3b3081e74
8 changed files with 125 additions and 3 deletions

View File

@@ -1,8 +1,8 @@
use std::{fs::File, io::Read, path::Path};
use super::header::Header;
use crate::lumps::{Lump, LumpType, VertexLump};
use crate::types::Vertex;
use crate::lumps::{LinedefLump, Lump, LumpType, VertexLump};
use crate::types::{Linedef, Vertex};
use crate::utils::{read_ascii, read_i16_le, read_u32_le, validate_wad};
pub struct WADFile {
@@ -39,6 +39,7 @@ impl WADFile {
let name = read_ascii(&file_buffer[startpos + 8..startpos + 16]);
let lump_type = match name.as_str() {
"VERTEXES" => LumpType::Vertex,
"LINEDEFS" => LumpType::Linedef,
_ => LumpType::Unknown,
};
lump_dir.push(Lump {
@@ -79,4 +80,35 @@ impl WADFile {
VertexLump { vertexes }
}
pub fn get_linedef_lump(&self, lump: &Lump) -> LinedefLump {
let lump_offset = lump.offset as usize;
let lump_size = lump.size as usize;
let lump_data = &self.data[lump_offset..lump_offset + lump_size];
let lump_entries = lump_size / 14;
let mut linedefs: Vec<Linedef> = Vec::with_capacity(lump_entries);
for entry in 0..lump_entries {
let startpos = entry * 14;
let vertex1 = read_i16_le(&lump_data[startpos..startpos + 2]);
let vertex2 = read_i16_le(&lump_data[startpos + 2..startpos + 4]);
let flags = read_i16_le(&lump_data[startpos + 4..startpos + 6]);
let special = read_i16_le(&lump_data[startpos + 6..startpos + 8]);
let tag = read_i16_le(&lump_data[startpos + 8..startpos + 10]);
let front_sidedef = read_i16_le(&lump_data[startpos + 10..startpos + 12]);
let back_sidedef = read_i16_le(&lump_data[startpos + 12..startpos + 14]);
linedefs.push(Linedef {
vertex1,
vertex2,
flags,
special,
tag,
front_sidedef,
back_sidedef,
});
}
LinedefLump { linedefs }
}
}