Vertex Loading
Added the ability to load vertex data from the WAD. Still needs some processing to make more robust, but for now is loading data.
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
use std::{fs::File, io::Read, path::Path};
|
||||
|
||||
use super::{directory::Directory, header::Header};
|
||||
use crate::utils::{read_ascii, read_u32_le, validate_wad};
|
||||
use super::header::Header;
|
||||
use crate::lumps::{Lump, LumpType, VertexLump};
|
||||
use crate::types::Vertex;
|
||||
use crate::utils::{read_ascii, read_i16_le, read_u32_le, validate_wad};
|
||||
|
||||
pub struct WADFile {
|
||||
pub path: String,
|
||||
pub wad_id: String,
|
||||
pub num_lumps: u32,
|
||||
pub dir_offset: u32,
|
||||
pub directory: Vec<Directory>,
|
||||
pub wad_data: Vec<u8>,
|
||||
pub directory: Vec<Lump>,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl WADFile {
|
||||
@@ -27,17 +29,19 @@ impl WADFile {
|
||||
|
||||
let wad_header = Header::read_data(&file_buffer[0..12]);
|
||||
|
||||
let mut wad_dir: Vec<Directory> = Vec::with_capacity(wad_header.num_lumps as usize);
|
||||
let mut lump_dir: Vec<Lump> = Vec::with_capacity(wad_header.num_lumps as usize);
|
||||
let offset = wad_header.dir_offset;
|
||||
|
||||
for entry in 0..wad_header.num_lumps {
|
||||
let startpos = (offset + 16 * entry) as usize;
|
||||
let filepos = read_u32_le(&file_buffer[startpos..startpos + 4]);
|
||||
let lump_offset = read_u32_le(&file_buffer[startpos..startpos + 4]);
|
||||
let size = read_u32_le(&file_buffer[startpos + 4..startpos + 8]);
|
||||
let name = read_ascii(&file_buffer[startpos + 8..startpos + 16]);
|
||||
wad_dir.push(Directory {
|
||||
filepos,
|
||||
let lump_type = LumpType::Unknown;
|
||||
lump_dir.push(Lump {
|
||||
name,
|
||||
offset: lump_offset,
|
||||
lump_type,
|
||||
size,
|
||||
});
|
||||
}
|
||||
@@ -47,8 +51,29 @@ impl WADFile {
|
||||
wad_id: wad_header.wad_id,
|
||||
num_lumps: wad_header.num_lumps,
|
||||
dir_offset: wad_header.dir_offset,
|
||||
directory: wad_dir,
|
||||
wad_data: file_buffer,
|
||||
directory: lump_dir,
|
||||
data: file_buffer,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_vertex_lump(&self, lump: Lump) -> VertexLump {
|
||||
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: usize = lump_size / 4;
|
||||
let mut vertexes: Vec<Vertex> = Vec::with_capacity(lump_size / 4);
|
||||
|
||||
for entry in 0..lump_entries {
|
||||
let startpos = entry * 4;
|
||||
let vertex_x = read_i16_le(&lump_data[startpos..startpos + 2]);
|
||||
let vertex_y = read_i16_le(&lump_data[startpos + 2..startpos + 4]);
|
||||
|
||||
vertexes.push(Vertex {
|
||||
x: vertex_x,
|
||||
y: vertex_y,
|
||||
});
|
||||
}
|
||||
|
||||
VertexLump { vertexes }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user