Compare commits
4 Commits
76358caaff
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 728599e033 | |||
|
2e2c500155
|
|||
| 81fd194938 | |||
|
569265f414
|
@@ -12,4 +12,6 @@ pub enum LumpType {
|
||||
Vertex,
|
||||
Linedef,
|
||||
Sidedef,
|
||||
Thing,
|
||||
Seg,
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
mod linedef;
|
||||
mod lump;
|
||||
mod seg;
|
||||
mod sidedef;
|
||||
mod thing;
|
||||
mod vertex;
|
||||
|
||||
pub use linedef::LinedefLump;
|
||||
pub use lump::{Lump, LumpType};
|
||||
pub use seg::SegLump;
|
||||
pub use sidedef::SidedefLump;
|
||||
pub use thing::ThingLump;
|
||||
pub use vertex::VertexLump;
|
||||
|
||||
19
src/lumps/seg.rs
Normal file
19
src/lumps/seg.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use crate::types::Seg;
|
||||
|
||||
pub struct SegLump {
|
||||
pub segs: Vec<Seg>,
|
||||
}
|
||||
|
||||
impl SegLump {
|
||||
pub fn get_num_segs(&self) -> usize {
|
||||
self.segs.len()
|
||||
}
|
||||
|
||||
pub fn get_all_segs(&self) -> Vec<Seg> {
|
||||
self.segs.to_vec()
|
||||
}
|
||||
|
||||
pub fn get_seg(&self, pos: usize) -> Seg {
|
||||
self.segs[pos].to_owned()
|
||||
}
|
||||
}
|
||||
19
src/lumps/thing.rs
Normal file
19
src/lumps/thing.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use crate::types::Thing;
|
||||
|
||||
pub struct ThingLump {
|
||||
pub things: Vec<Thing>,
|
||||
}
|
||||
|
||||
impl ThingLump {
|
||||
pub fn get_num_things(&self) -> usize {
|
||||
self.things.len()
|
||||
}
|
||||
|
||||
pub fn get_all_things(&self) -> Vec<Thing> {
|
||||
self.things.to_vec()
|
||||
}
|
||||
|
||||
pub fn get_thing(&self, pos: usize) -> Thing {
|
||||
self.things[pos].to_owned()
|
||||
}
|
||||
}
|
||||
@@ -193,3 +193,94 @@ pub fn get_num_sidedefs() {
|
||||
|
||||
assert_eq!(sidedef_lump.get_num_sidedefs(), 648);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn read_first_thing() {
|
||||
use crate::types::Thing;
|
||||
|
||||
let wad_file = get_wad();
|
||||
|
||||
let thing_lump = wad_file.get_thing_lump(&wad_file.directory[7]);
|
||||
|
||||
let correct_thing = Thing {
|
||||
x_position: 1056,
|
||||
y_position: -3616,
|
||||
angle: 90,
|
||||
thing_type: 1,
|
||||
flags: 7,
|
||||
};
|
||||
|
||||
assert_eq!(thing_lump.get_thing(0), correct_thing);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn get_num_thing_lumps() {
|
||||
use crate::lumps::{Lump, LumpType};
|
||||
|
||||
let mut thing_lumps: Vec<Lump> = Vec::new();
|
||||
|
||||
let wad_file = get_wad();
|
||||
|
||||
for entry in 0..wad_file.num_lumps as usize {
|
||||
if let LumpType::Thing = wad_file.directory[entry].lump_type {
|
||||
thing_lumps.push(wad_file.directory[entry].to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(thing_lumps.len(), 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn get_num_things() {
|
||||
let wad_file = get_wad();
|
||||
|
||||
let thing_lump = wad_file.get_thing_lump(&wad_file.directory[7]);
|
||||
|
||||
assert_eq!(thing_lump.get_num_things(), 138);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn read_first_seg() {
|
||||
use crate::types::Seg;
|
||||
|
||||
let wad_file = get_wad();
|
||||
|
||||
let seg_lump = wad_file.get_seg_lump(&wad_file.directory[11]);
|
||||
|
||||
let correct_seg = Seg {
|
||||
start_vertex: 123,
|
||||
end_vertex: 124,
|
||||
angle: 16384,
|
||||
linedef: 152,
|
||||
direction: 0,
|
||||
offset: 0,
|
||||
};
|
||||
|
||||
assert_eq!(seg_lump.get_seg(0), correct_seg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn get_num_seg_lumps() {
|
||||
use crate::lumps::{Lump, LumpType};
|
||||
|
||||
let mut seg_lumps: Vec<Lump> = Vec::new();
|
||||
|
||||
let wad_file = get_wad();
|
||||
|
||||
for entry in 0..wad_file.num_lumps as usize {
|
||||
if let LumpType::Seg = wad_file.directory[entry].lump_type {
|
||||
seg_lumps.push(wad_file.directory[entry].to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(seg_lumps.len(), 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn get_num_segs() {
|
||||
let wad_file = get_wad();
|
||||
|
||||
let thing_lump = wad_file.get_seg_lump(&wad_file.directory[11]);
|
||||
|
||||
assert_eq!(thing_lump.get_num_segs(), 732);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
mod linedef;
|
||||
mod seg;
|
||||
mod sidedef;
|
||||
mod thing;
|
||||
mod vertex;
|
||||
|
||||
pub use linedef::Linedef;
|
||||
pub use seg::Seg;
|
||||
pub use sidedef::Sidedef;
|
||||
pub use thing::Thing;
|
||||
pub use vertex::Vertex;
|
||||
|
||||
9
src/types/seg.rs
Normal file
9
src/types/seg.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Seg {
|
||||
pub start_vertex: i16,
|
||||
pub end_vertex: i16,
|
||||
pub angle: i16,
|
||||
pub linedef: i16,
|
||||
pub direction: i16,
|
||||
pub offset: i16,
|
||||
}
|
||||
8
src/types/thing.rs
Normal file
8
src/types/thing.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Thing {
|
||||
pub x_position: i16,
|
||||
pub y_position: i16,
|
||||
pub angle: i16,
|
||||
pub thing_type: i16,
|
||||
pub flags: i16,
|
||||
}
|
||||
@@ -45,6 +45,8 @@ impl WADFile {
|
||||
"VERTEXES" => LumpType::Vertex,
|
||||
"LINEDEFS" => LumpType::Linedef,
|
||||
"SIDEDEFS" => LumpType::Sidedef,
|
||||
"THINGS" => LumpType::Thing,
|
||||
"SEGS" => LumpType::Seg,
|
||||
_ => LumpType::Unknown,
|
||||
};
|
||||
lump_dir.push(Lump {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::lumps::{LinedefLump, Lump, SidedefLump, VertexLump};
|
||||
use crate::types::{Linedef, Sidedef, Vertex};
|
||||
use crate::lumps::{LinedefLump, Lump, SegLump, SidedefLump, ThingLump, VertexLump};
|
||||
use crate::types::{Linedef, Seg, Sidedef, Thing, Vertex};
|
||||
use crate::utils::read_ascii;
|
||||
use crate::wad::WADFile;
|
||||
use crate::wad::wadfile::read_i16_le;
|
||||
@@ -85,4 +85,59 @@ impl WADFile {
|
||||
|
||||
SidedefLump { sidedefs }
|
||||
}
|
||||
|
||||
pub fn get_thing_lump(&self, lump: &Lump) -> ThingLump {
|
||||
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 / 10;
|
||||
let mut things: Vec<Thing> = Vec::with_capacity(lump_entries);
|
||||
|
||||
for entry in 0..lump_entries {
|
||||
let startpos = entry * 10;
|
||||
let x_position = read_i16_le(&lump_data[startpos..startpos + 2]);
|
||||
let y_position = read_i16_le(&lump_data[startpos + 2..startpos + 4]);
|
||||
let angle = read_i16_le(&lump_data[startpos + 4..startpos + 6]);
|
||||
let thing_type = read_i16_le(&lump_data[startpos + 6..startpos + 8]);
|
||||
let flags = read_i16_le(&lump_data[startpos + 8..startpos + 10]);
|
||||
|
||||
things.push(Thing {
|
||||
x_position,
|
||||
y_position,
|
||||
angle,
|
||||
thing_type,
|
||||
flags,
|
||||
});
|
||||
}
|
||||
|
||||
ThingLump { things }
|
||||
}
|
||||
|
||||
pub fn get_seg_lump(&self, lump: &Lump) -> SegLump {
|
||||
let lump_offset = lump.offset as usize;
|
||||
let lump_size = lump.size as usize;
|
||||
let lump_entries = lump_size / 12;
|
||||
let mut segs: Vec<Seg> = Vec::with_capacity(lump_entries);
|
||||
|
||||
for entry in 0..lump_entries {
|
||||
let startpos = (entry * 12) + lump_offset;
|
||||
let start_vertex = read_i16_le(&self.data[startpos..startpos + 2]);
|
||||
let end_vertex = read_i16_le(&self.data[startpos + 2..startpos + 4]);
|
||||
let angle = read_i16_le(&self.data[startpos + 4..startpos + 6]);
|
||||
let linedef = read_i16_le(&self.data[startpos + 6..startpos + 8]);
|
||||
let direction = read_i16_le(&self.data[startpos + 8..startpos + 10]);
|
||||
let offset = read_i16_le(&self.data[startpos + 10..startpos + 12]);
|
||||
|
||||
segs.push(Seg {
|
||||
start_vertex,
|
||||
end_vertex,
|
||||
angle,
|
||||
linedef,
|
||||
direction,
|
||||
offset,
|
||||
});
|
||||
}
|
||||
|
||||
SegLump { segs }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user