Merge pull request 'WAD Rework' (#8) from wadfile-rework into master
Reviewed-on: https://git.batesirvintech.net/wesley/doom-oxidized/pulls/8
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -1,7 +1,9 @@
|
|||||||
mod wadutils;
|
mod wadfile;
|
||||||
|
|
||||||
|
use wadfile::WADFile;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let wad_file = wadutils::load_wad("WADs/doom1.wad");
|
let wad_file = WADFile::from_path("WADs/doom1.wad");
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"WAD Path: {}
|
"WAD Path: {}
|
||||||
@@ -11,11 +13,11 @@ Header:
|
|||||||
Lump Count: {}
|
Lump Count: {}
|
||||||
Initial Offset: {}
|
Initial Offset: {}
|
||||||
Number of Found Lumps: {}",
|
Number of Found Lumps: {}",
|
||||||
wadutils::get_wad_path(&wad_file),
|
wad_file.wad_path,
|
||||||
wadutils::get_wad_type(&wad_file),
|
wad_file.identifier,
|
||||||
wadutils::get_num_lumps(&wad_file),
|
wad_file.num_lumps,
|
||||||
wadutils::get_init_offset(&wad_file),
|
wad_file.init_offset,
|
||||||
wadutils::get_directory_len(&wad_file)
|
wad_file.get_directory_len()
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("First 15 Directory Entries:");
|
println!("First 15 Directory Entries:");
|
||||||
@@ -24,14 +26,14 @@ Header:
|
|||||||
println!(
|
println!(
|
||||||
"\t{}\tName {}\tPosition {}\tSize {}",
|
"\t{}\tName {}\tPosition {}\tSize {}",
|
||||||
i,
|
i,
|
||||||
wadutils::get_lump_name(&wad_file, i),
|
wad_file.get_lump_name(i),
|
||||||
wadutils::get_lump_offset(&wad_file, i),
|
wad_file.get_lump_offset(i),
|
||||||
wadutils::get_lump_size(&wad_file, i)
|
wad_file.get_lump_size(i)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Index of e1m1 is: {}",
|
"Index of e1m1 is: {}",
|
||||||
wadutils::get_index_from_name(&wad_file, "e1m1").unwrap()
|
wad_file.get_index_from_name("e1m1").unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
pub mod directory;
|
mod directory;
|
||||||
|
|
||||||
use directory::Directory;
|
use directory::Directory;
|
||||||
use std::{
|
use std::{
|
||||||
@@ -30,6 +30,38 @@ impl WADFile {
|
|||||||
lump_directory: lump_dir,
|
lump_directory: lump_dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_lump_name(&self, index: u32) -> String {
|
||||||
|
self.lump_directory[index as usize].lump_name.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_lump_offset(&self, index: u32) -> u32 {
|
||||||
|
self.lump_directory[index as usize].lump_pos.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_lump_size(&self, index: u32) -> u32 {
|
||||||
|
self.lump_directory[index as usize].lump_size.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_directory_len(&self) -> usize {
|
||||||
|
self.lump_directory.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_index_from_name(&self, lump_name: &str) -> Option<u32> {
|
||||||
|
let mut search_lump = lump_name.to_ascii_uppercase();
|
||||||
|
|
||||||
|
for _ in 0..8 - search_lump.len() {
|
||||||
|
search_lump.push(0 as char);
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..self.num_lumps {
|
||||||
|
if self.lump_directory[i as usize].lump_name == search_lump {
|
||||||
|
return Some(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_lump_dir(path: &str, dir_offset: &u32, num_lumps: &u32, lump_buffer: &mut Vec<Directory>) {
|
fn get_lump_dir(path: &str, dir_offset: &u32, num_lumps: &u32, lump_buffer: &mut Vec<Directory>) {
|
||||||
5
src/wadfile/directory.rs
Normal file
5
src/wadfile/directory.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub struct Directory {
|
||||||
|
pub lump_pos: u32,
|
||||||
|
pub lump_size: u32,
|
||||||
|
pub lump_name: String,
|
||||||
|
}
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
mod wadfile;
|
|
||||||
|
|
||||||
use wadfile::WADFile;
|
|
||||||
|
|
||||||
pub fn load_wad(path: &str) -> WADFile {
|
|
||||||
WADFile::from_path(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_wad_path(wad_file: &WADFile) -> String {
|
|
||||||
wad_file.wad_path.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_wad_type(wad_file: &WADFile) -> String {
|
|
||||||
wad_file.identifier.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_num_lumps(wad_file: &WADFile) -> u32 {
|
|
||||||
wad_file.num_lumps
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_init_offset(wad_file: &WADFile) -> u32 {
|
|
||||||
wad_file.init_offset
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_lump_name(wad_file: &WADFile, index: u32) -> String {
|
|
||||||
wad_file.lump_directory[index as usize].lump_name.to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_lump_offset(wad_file: &WADFile, index: u32) -> u32 {
|
|
||||||
wad_file.lump_directory[index as usize].lump_pos.to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_lump_size(wad_file: &WADFile, index: u32) -> u32 {
|
|
||||||
wad_file.lump_directory[index as usize].lump_size.to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_directory_len(wad_file: &WADFile) -> usize {
|
|
||||||
wad_file.lump_directory.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_index_from_name(wad_file: &WADFile, lump_name: &str) -> Option<u32> {
|
|
||||||
let mut search_lump = lump_name.to_ascii_uppercase();
|
|
||||||
|
|
||||||
for _ in 0..8 - search_lump.len() {
|
|
||||||
search_lump.push(0 as char);
|
|
||||||
}
|
|
||||||
|
|
||||||
for i in 0..wad_file.num_lumps {
|
|
||||||
if wad_file.lump_directory[i as usize].lump_name == search_lump {
|
|
||||||
return Some(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
pub(in crate::wadutils) struct Directory {
|
|
||||||
pub(in crate::wadutils) lump_pos: u32,
|
|
||||||
pub(in crate::wadutils) lump_size: u32,
|
|
||||||
pub(in crate::wadutils) lump_name: String,
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user