Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Rust
name: Rust CI

on:
push:
branches: [ master ]
branches: [ master, main ]
pull_request:
branches: [ master ]
branches: [ master, main ]

env:
CARGO_TERM_COLOR: always
Expand All @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
feature-set: ['', '--no-default-features --features alloc_fills']
feature-set: ['', '--no-default-features']

steps:
- uses: actions/checkout@v3
Expand Down
98 changes: 1 addition & 97 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ repository = "https://github.com/4LT/quake-util"

[features]
default = ["std"]
alloc_fills = ["hashbrown"]
std = []

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

[dev-dependencies]
benchmarking = "^0.4"
png = "^0.17"
21 changes: 19 additions & 2 deletions examples/bspstats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,28 @@ fn main() {
let mut map_name = String::from("<None>");

for edict in qmap.entities.into_iter().map(|e| e.edict) {
let map_name_cstr = if edict.get(&CString::new("classname").unwrap())
let map_name_cstr = if edict
.iter()
.flat_map(|(key, value)| {
if key == &CString::new("classname").unwrap() {
Some(value)
} else {
None
}
})
.next()
== Some(&CString::new("worldspawn").unwrap())
{
edict
.get(&CString::new("message").unwrap())
.iter()
.flat_map(|(key, value)| {
if key == &CString::new("message").unwrap() {
Some(value)
} else {
None
}
})
.next()
.map(Clone::clone)
} else {
None
Expand Down
26 changes: 15 additions & 11 deletions src/bsp/parser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ fn parse_good_bsp() {

let qmap = parser.parse_entities().unwrap();

assert_eq!(
qmap.entities[0]
.edict
.get(&CString::new("classname").unwrap()),
Some(&CString::new("func_door").unwrap())
);

assert_eq!(
qmap.entities[0].edict.get(&CString::new("model").unwrap()),
Some(&CString::new("*37").unwrap())
);
let (_, classname) = qmap.entities[0]
.edict
.iter()
.find(|(key, _)| key == &CString::new("classname").unwrap())
.unwrap();

assert_eq!(classname, &CString::new("func_door").unwrap());

let (_, model) = qmap.entities[0]
.edict
.iter()
.find(|(key, _)| key == &CString::new("model").unwrap())
.unwrap();

assert_eq!(model, &CString::new("*37").unwrap());
}

#[test]
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#![no_std]

#[cfg(all(not(feature = "std"), not(feature = "alloc_fills")))]
compile_error!("Must use feature 'std' or 'alloc_fills'");

#[cfg(all(feature = "std", feature = "alloc_fills"))]
compile_error!("Features 'std' and 'alloc_fills' are mutually exclusive");

#[cfg(feature = "std")]
#[macro_use]
extern crate std;
Expand Down
4 changes: 3 additions & 1 deletion src/lump/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ pub fn parse_mip_texture(
pub fn parse_palette(reader: &mut impl Read) -> BinParseResult<Box<Palette>> {
let mut bytes = [0u8; size_of::<Palette>()];
reader.read_exact(&mut bytes[..])?;
Ok(Box::from(unsafe { transmute::<_, Palette>(bytes) }))
Ok(Box::from(unsafe {
transmute::<[u8; size_of::<Palette>()], Palette>(bytes)
}))
}

/// Attempt to parse a 2D image
Expand Down
2 changes: 1 addition & 1 deletion src/lump/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Image {
pub fn from_pixels(width: u32, pixels: Box<[u8]>) -> Self {
let pixel_ct: u32 = pixels.len().try_into().expect("Too many pixels");

if pixels.len() == 0 {
if pixels.is_empty() {
return Image {
width: 0,
height: 0,
Expand Down
8 changes: 4 additions & 4 deletions src/qmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
//!
//! let mut soldier = Entity::new();
//!
//! soldier.edict.insert(
//! soldier.edict.push((
//! CString::new("classname").unwrap(),
//! CString::new("monster_army").unwrap(),
//! );
//! ));
//!
//! soldier.edict.insert(
//! soldier.edict.push((
//! CString::new("origin").unwrap(),
//! CString::new("128 -256 24").unwrap(),
//! );
//! ));
//!
//! map.entities.push(soldier);
//!
Expand Down
4 changes: 2 additions & 2 deletions src/qmap/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn parse_edict<R: Read>(
expect_quoted(&maybe_value)?;
let value =
strip_quoted(&maybe_value.unwrap().text).to_vec().into();
edict.insert(key, value);
edict.push((key, value));
} else {
break;
}
Expand Down Expand Up @@ -112,7 +112,7 @@ fn parse_brush<R: Read>(
}
}

expect_byte_or(&tokens.extract()?, b'}', &[b'('])?;
expect_byte_or(&tokens.extract()?, b'}', b"(")?;
Ok(surfaces)
}

Expand Down
6 changes: 3 additions & 3 deletions src/qmap/parser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ fn parse_point_entity_with_key_value() {
assert_eq!(edict.len(), 1);
assert_eq!(
edict.iter().next().unwrap(),
(
&CString::new("classname").unwrap(),
&CString::new("light").unwrap()
&(
CString::new("classname").unwrap(),
CString::new("light").unwrap()
)
);
}
Expand Down
20 changes: 9 additions & 11 deletions src/qmap/repr.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "alloc_fills")]
extern crate alloc;

#[cfg(feature = "std")]
use std::{
collections::HashMap,
ffi::{CStr, CString},
io,
string::String,
vec::Vec,
};
use std::io;

#[cfg(feature = "alloc_fills")]
use {
alloc::ffi::CString, alloc::format, alloc::string::String, alloc::vec::Vec,
core::ffi::CStr, hashbrown::HashMap,
core::ffi::CStr,
};

#[cfg(feature = "std")]
Expand Down Expand Up @@ -69,6 +61,12 @@ impl QuakeMap {
}
}

impl Default for QuakeMap {
fn default() -> Self {
Self::new()
}
}

impl CheckWritable for QuakeMap {
fn check_writable(&self) -> ValidationResult {
for ent in &self.entities {
Expand Down Expand Up @@ -149,7 +147,7 @@ impl CheckWritable for Entity {
}

/// Entity dictionary
pub type Edict = HashMap<CString, CString>;
pub type Edict = Vec<(CString, CString)>;

impl CheckWritable for Edict {
fn check_writable(&self) -> ValidationResult {
Expand Down
Loading
Loading