Skip to content

Commit

Permalink
Merge pull request #23 from 4LT/wad
Browse files Browse the repository at this point in the history
Wad parsing + qmap fixes + refactoring
  • Loading branch information
4LT authored Feb 13, 2024
2 parents 013ef62 + bd5f54c commit cc8b7a0
Show file tree
Hide file tree
Showing 29 changed files with 2,347 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
Cargo.lock
/dump

/test-res/lg-file
188 changes: 188 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quake-util"
version = "0.2.0"
version = "0.3.0"
authors = ["Seth <[email protected]>"]
edition = "2021"
description = "A utility library for using Quake file formats"
Expand All @@ -13,7 +13,8 @@ alloc_fills = ["hashbrown"]
std = []

[dependencies]
hashbrown = { version = "^0.12", optional = true }
hashbrown = { version = "^0.14", optional = true }

[dev-dependencies]
benchmarking = "^0.4"
png = "^0.17"
6 changes: 3 additions & 3 deletions examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ mod main {

fn parse_file(file_path: &str) {
let f = File::open(file_path).unwrap();
let reader = BufReader::new(f);
let _ = parse(reader).unwrap();
let mut reader = BufReader::new(f);
let _ = parse(&mut reader).unwrap();
}

fn measure_parse(path: &str) -> Duration {
Expand All @@ -33,7 +33,7 @@ mod main {
}

pub fn run_benches() {
let map_names = vec!["ad_heresp2.map", "standard.map"];
let map_names = ["ad_heresp2.map", "standard.map"];
let maps = map_names
.iter()
.map(|&m| (m, prepare_file(m).unwrap()))
Expand Down
2 changes: 1 addition & 1 deletion examples/bench_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn download_file(filename: &str, out_path: &str) -> Result<(), String> {
pub fn prepare_file(filename: &str) -> Result<String, String> {
let hash_path = format!("{LARGE_FILE_HASH_PATH}/{filename}.{HASH_SUFFIX}");
let file_path = format!("{LARGE_FILE_PATH}/{filename}");
let expected_hash = strip_hash(read_to_string(&hash_path).as_deref())?;
let expected_hash = strip_hash(read_to_string(hash_path).as_deref())?;
let file_res = File::open(&file_path);
let _ = create_dir_all(LARGE_FILE_PATH);

Expand Down
67 changes: 67 additions & 0 deletions examples/print_wad_entries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#[cfg(feature = "std")]
use quake_util::{lump, wad};

#[cfg(feature = "std")]
use std::{env::args, fs::File, io::BufReader};

#[cfg(feature = "std")]
fn main() {
let mut arguments = args();

let arg1 = if let Some(arg1) = arguments.nth(1) {
arg1
} else {
panic!("No arguments");
};

let file = File::open(arg1).expect("Could not open file");
let mut cursor = BufReader::new(file);

let (mut parser, warnings) = wad::Parser::new(&mut cursor).unwrap();

for warning in warnings {
eprintln!("Warning: {warning}");
}

for (name, entry) in parser.directory() {
print!("Entry `{}`: ", name);

match &parser
.parse_inferred(&entry)
.map_err(|e| format!("{}: {}", name, e))
.unwrap()
{
lump::Lump::MipTexture(tex) => {
println!("Texture");
for image in tex.mips() {
println!(
"\t{}x{}: {} bytes",
image.width(),
image.height(),
image.pixels().len()
);
}
}
lump::Lump::Palette(_) => {
println!("Palette");
println!("\t768 bytes");
}
lump::Lump::StatusBar(img) => {
println!("Status bar image");
println!(
"\t{}x{}: {} bytes",
img.width(),
img.height(),
img.pixels().len(),
);
}
lump::Lump::Flat(bytes) => {
println!("Flat");
println!("\t{} bytes", bytes.len());
}
}
}
}

#[cfg(not(feature = "std"))]
fn main() {}
Loading

0 comments on commit cc8b7a0

Please sign in to comment.