aboutsummaryrefslogtreecommitdiff
path: root/stockton-levels
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:21 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:21 +0100
commit2111c1248b08236a839dcf22036f92735bceb31c (patch)
tree9313da344b7134a913d1d917162e55b35fe1e74f /stockton-levels
parent102e166b040030b590df83888a1d1a47d0130f10 (diff)
chore(all): style formatting and clippy fixes
Diffstat (limited to 'stockton-levels')
-rw-r--r--stockton-levels/src/coords.rs19
-rw-r--r--stockton-levels/src/features.rs7
-rw-r--r--stockton-levels/src/helpers.rs2
-rw-r--r--stockton-levels/src/lib.rs11
-rw-r--r--stockton-levels/src/prelude.rs6
-rw-r--r--stockton-levels/src/q3/brushes.rs19
-rw-r--r--stockton-levels/src/q3/effects.rs17
-rw-r--r--stockton-levels/src/q3/entities.rs13
-rw-r--r--stockton-levels/src/q3/faces.rs22
-rw-r--r--stockton-levels/src/q3/file.rs232
-rw-r--r--stockton-levels/src/q3/header.rs6
-rw-r--r--stockton-levels/src/q3/light_maps.rs16
-rw-r--r--stockton-levels/src/q3/light_vols.rs9
-rw-r--r--stockton-levels/src/q3/mod.rs24
-rw-r--r--stockton-levels/src/q3/models.rs21
-rw-r--r--stockton-levels/src/q3/planes.rs14
-rw-r--r--stockton-levels/src/q3/textures.rs38
-rw-r--r--stockton-levels/src/q3/tree.rs31
-rw-r--r--stockton-levels/src/q3/vertices.rs13
-rw-r--r--stockton-levels/src/q3/visdata.rs16
-rw-r--r--stockton-levels/src/traits/brushes.rs4
-rw-r--r--stockton-levels/src/traits/effects.rs8
-rw-r--r--stockton-levels/src/traits/entities.rs10
-rw-r--r--stockton-levels/src/traits/faces.rs14
-rw-r--r--stockton-levels/src/traits/light_maps.rs6
-rw-r--r--stockton-levels/src/traits/light_vols.rs4
-rw-r--r--stockton-levels/src/traits/mod.rs34
-rw-r--r--stockton-levels/src/traits/models.rs6
-rw-r--r--stockton-levels/src/traits/planes.rs10
-rw-r--r--stockton-levels/src/traits/textures.rs47
-rw-r--r--stockton-levels/src/traits/tree.rs14
-rw-r--r--stockton-levels/src/traits/vertices.rs13
-rw-r--r--stockton-levels/src/traits/visdata.rs16
-rw-r--r--stockton-levels/src/types.rs4
34 files changed, 362 insertions, 364 deletions
diff --git a/stockton-levels/src/coords.rs b/stockton-levels/src/coords.rs
index 613c932..bddf1f2 100644
--- a/stockton-levels/src/coords.rs
+++ b/stockton-levels/src/coords.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -14,8 +14,8 @@
// with this program. If not, see <http://www.gnu.org/licenses/>.
//! Marker traits for different co-ordinate systems, and functions to swizzle between them
-use na::Vector3;
use na::base::Scalar;
+use na::Vector3;
use std::ops::Neg;
pub trait CoordSystem {}
@@ -28,17 +28,16 @@ impl CoordSystem for Q3System {}
pub struct VulkanSystem;
impl CoordSystem for VulkanSystem {}
-
pub struct Swizzler;
pub trait SwizzleFromTo<F: CoordSystem, T: CoordSystem> {
- fn swizzle<U: Scalar + Copy + Neg<Output = U>>(vec: &mut Vector3<U>) -> ();
+ fn swizzle<U: Scalar + Copy + Neg<Output = U>>(vec: &mut Vector3<U>);
}
impl SwizzleFromTo<Q3System, VulkanSystem> for Swizzler {
- fn swizzle<U: Scalar + Copy + Neg<Output = U>>(vec: &mut Vector3<U>) -> () {
- let temp = vec.y;
- vec.y = vec.z;
- vec.z = -temp;
- }
-} \ No newline at end of file
+ fn swizzle<U: Scalar + Copy + Neg<Output = U>>(vec: &mut Vector3<U>) {
+ let temp = vec.y;
+ vec.y = vec.z;
+ vec.z = -temp;
+ }
+}
diff --git a/stockton-levels/src/features.rs b/stockton-levels/src/features.rs
index 6cecbff..7b81cc8 100644
--- a/stockton-levels/src/features.rs
+++ b/stockton-levels/src/features.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -14,9 +14,8 @@
// with this program. If not, see <http://www.gnu.org/licenses/>.
//! Marker traits for different feature sets
-use crate::traits::*;
use crate::coords::CoordSystem;
+use crate::traits::*;
pub trait MinBSPFeatures<S: CoordSystem>: HasBSPTree<S> {}
-impl<T, S: CoordSystem> MinBSPFeatures<S> for T
- where T: HasBSPTree<S> {} \ No newline at end of file
+impl<T, S: CoordSystem> MinBSPFeatures<S> for T where T: HasBSPTree<S> {}
diff --git a/stockton-levels/src/helpers.rs b/stockton-levels/src/helpers.rs
index c3e6c80..91a672a 100644
--- a/stockton-levels/src/helpers.rs
+++ b/stockton-levels/src/helpers.rs
@@ -68,4 +68,4 @@ pub fn slice_to_vec3i(slice: &[u8]) -> Vector3<i32> {
/// If slice isn't 8 bytes long.
pub fn slice_to_vec2ui(slice: &[u8]) -> Vector2<u32> {
Vector2::new(slice_to_u32(&slice[0..4]), slice_to_u32(&slice[4..8]))
-} \ No newline at end of file
+}
diff --git a/stockton-levels/src/lib.rs b/stockton-levels/src/lib.rs
index 3026b9d..46484bd 100644
--- a/stockton-levels/src/lib.rs
+++ b/stockton-levels/src/lib.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -13,6 +13,7 @@
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//! Parses common features from many BSP file formats.
+#![allow(incomplete_features)]
#![feature(generic_associated_types)]
#[macro_use]
@@ -20,10 +21,10 @@ extern crate bitflags;
extern crate bitvec;
extern crate nalgebra as na;
+pub mod coords;
+pub mod features;
mod helpers;
+pub mod prelude;
pub mod q3;
-pub mod types;
pub mod traits;
-pub mod prelude;
-pub mod features;
-pub mod coords; \ No newline at end of file
+pub mod types;
diff --git a/stockton-levels/src/prelude.rs b/stockton-levels/src/prelude.rs
index 32485b3..ec6aa1f 100644
--- a/stockton-levels/src/prelude.rs
+++ b/stockton-levels/src/prelude.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -14,6 +14,6 @@
// with this program. If not, see <http://www.gnu.org/licenses/>.
//! Common traits, etc.
-pub use crate::traits::*;
+pub use crate::coords::*;
pub use crate::features::*;
-pub use crate::coords::*; \ No newline at end of file
+pub use crate::traits::*;
diff --git a/stockton-levels/src/q3/brushes.rs b/stockton-levels/src/q3/brushes.rs
index f82e57a..cd848a2 100644
--- a/stockton-levels/src/q3/brushes.rs
+++ b/stockton-levels/src/q3/brushes.rs
@@ -23,18 +23,18 @@ const BRUSH_SIZE: usize = 4 * 3;
/// The size of one brushsize record
const SIDE_SIZE: usize = 4 * 2;
+use super::Q3BSPFile;
+use crate::coords::CoordSystem;
use crate::helpers::slice_to_i32;
-use crate::types::{ParseError, Result};
use crate::traits::brushes::*;
-use crate::coords::CoordSystem;
-use super::Q3BSPFile;
+use crate::types::{ParseError, Result};
/// Parse the brushes & brushsides lump from a bsp file.
pub fn from_data(
brushes_data: &[u8],
sides_data: &[u8],
n_textures: u32,
- n_planes: u32
+ n_planes: u32,
) -> Result<Box<[Brush]>> {
if brushes_data.len() % BRUSH_SIZE != 0 || sides_data.len() % SIDE_SIZE != 0 {
return Err(ParseError::Invalid);
@@ -57,9 +57,9 @@ pub fn from_data(
slice_to_i32(&brush[0..4]),
slice_to_i32(&brush[4..8]),
n_textures as usize,
- n_planes as usize
+ n_planes as usize,
)?,
- texture_idx
+ texture_idx,
});
}
@@ -96,7 +96,7 @@ fn get_sides(
sides.push(BrushSide {
plane_idx,
texture_idx,
- is_opposing
+ is_opposing,
});
}
}
@@ -104,15 +104,14 @@ fn get_sides(
Ok(sides.into_boxed_slice())
}
-
impl<T: CoordSystem> HasBrushes<T> for Q3BSPFile<T> {
type BrushesIter<'a> = std::slice::Iter<'a, Brush>;
- fn brushes_iter<'a>(&'a self) -> Self::BrushesIter<'a> {
+ fn brushes_iter(&self) -> Self::BrushesIter<'_> {
self.brushes.iter()
}
- fn get_brush<'a>(&'a self, index: u32) -> &'a Brush {
+ fn get_brush(&self, index: u32) -> &Brush {
&self.brushes[index as usize]
}
}
diff --git a/stockton-levels/src/q3/effects.rs b/stockton-levels/src/q3/effects.rs
index 77ad1ed..a796570 100644
--- a/stockton-levels/src/q3/effects.rs
+++ b/stockton-levels/src/q3/effects.rs
@@ -17,11 +17,11 @@
use std::str;
-use crate::helpers::slice_to_u32;
-use crate::types::{Result, ParseError};
-use crate::traits::effects::*;
use super::Q3BSPFile;
use crate::coords::CoordSystem;
+use crate::helpers::slice_to_u32;
+use crate::traits::effects::*;
+use crate::types::{ParseError, Result};
/// The size of one effect definition
const EFFECT_SIZE: usize = 64 + 4 + 4;
@@ -42,23 +42,24 @@ pub fn from_data(data: &[u8], n_brushes: u32) -> Result<Box<[Effect]>> {
}
effects.push(Effect {
- name: str::from_utf8(&raw[..64]).map_err(|_| ParseError::Invalid)?.to_owned(),
- brush_idx
+ name: str::from_utf8(&raw[..64])
+ .map_err(|_| ParseError::Invalid)?
+ .to_owned(),
+ brush_idx,
});
}
Ok(effects.into_boxed_slice())
}
-
impl<T: CoordSystem> HasEffects<T> for Q3BSPFile<T> {
type EffectsIter<'a> = std::slice::Iter<'a, Effect>;
- fn effects_iter<'a>(&'a self) -> Self::EffectsIter<'a> {
+ fn effects_iter(&self) -> Self::EffectsIter<'_> {
self.effects.iter()
}
- fn get_effect<'a>(&'a self, index: u32) -> &'a Effect {
+ fn get_effect(&self, index: u32) -> &Effect {
&self.effects[index as usize]
}
}
diff --git a/stockton-levels/src/q3/entities.rs b/stockton-levels/src/q3/entities.rs
index 4382ef2..950d89a 100644
--- a/stockton-levels/src/q3/entities.rs
+++ b/stockton-levels/src/q3/entities.rs
@@ -15,13 +15,13 @@
// You should have received a copy of the GNU General Public License
// along with stockton-bsp. If not, see <http://www.gnu.org/licenses/>.
-use std::str;
use std::collections::HashMap;
+use std::str;
-use crate::types::{Result, ParseError};
-use crate::traits::entities::*;
use super::Q3BSPFile;
use crate::coords::CoordSystem;
+use crate::traits::entities::*;
+use crate::types::{ParseError, Result};
const QUOTE: u8 = b'"';
const END_BRACKET: u8 = b'}';
@@ -72,7 +72,10 @@ pub fn from_data(data: &[u8]) -> Result<Box<[Entity]>> {
state = ParseState::InsideEntity;
val_end = i;
- attrs.insert(string[key_start..key_end].to_owned(), string[val_start..val_end].to_owned());
+ attrs.insert(
+ string[key_start..key_end].to_owned(),
+ string[val_start..val_end].to_owned(),
+ );
}
_ => {
return Err(ParseError::Invalid);
@@ -103,7 +106,7 @@ pub fn from_data(data: &[u8]) -> Result<Box<[Entity]>> {
impl<T: CoordSystem> HasEntities for Q3BSPFile<T> {
type EntitiesIter<'a> = std::slice::Iter<'a, Entity>;
- fn entities_iter<'a>(&'a self) -> Self::EntitiesIter<'a> {
+ fn entities_iter(&self) -> Self::EntitiesIter<'_> {
self.entities.iter()
}
}
diff --git a/stockton-levels/src/q3/faces.rs b/stockton-levels/src/q3/faces.rs
index a53af6e..ab768ce 100644
--- a/stockton-levels/src/q3/faces.rs
+++ b/stockton-levels/src/q3/faces.rs
@@ -15,16 +15,15 @@
// You should have received a copy of the GNU General Public License
// along with stockton-bsp. If not, see <http://www.gnu.org/licenses/>.
-use crate::helpers::{slice_to_i32, slice_to_u32, slice_to_vec2ui, slice_to_vec3};
-use crate::types::{Result, ParseError};
-use na::Vector3;
-use crate::traits::faces::*;
use super::Q3BSPFile;
use crate::coords::CoordSystem;
+use crate::helpers::{slice_to_i32, slice_to_u32, slice_to_vec2ui, slice_to_vec3};
+use crate::traits::faces::*;
+use crate::types::{ParseError, Result};
+use na::Vector3;
const FACE_SIZE: usize = (4 * 8) + (4 * 2) + (4 * 2) + (4 * 3) + ((4 * 2) * 3) + (4 * 3) + (4 * 2);
-
pub fn from_data(
data: &[u8],
n_textures: u32,
@@ -53,7 +52,6 @@ pub fn from_data(
Ok(faces.into_boxed_slice())
}
-
fn face_from_slice(
data: &[u8],
n_textures: u32,
@@ -125,9 +123,9 @@ fn face_from_slice(
// map_vecs
let mut map_vecs = [Vector3::new(0.0, 0.0, 0.0); 2];
- for n in 0..2 {
+ for (n, map_vec) in map_vecs.iter_mut().enumerate() {
let offset = 60 + (n * 3 * 4);
- map_vecs[n] = slice_to_vec3(&data[offset..offset + 12]);
+ *map_vec = slice_to_vec3(&data[offset..offset + 12]);
}
// normal & size
@@ -150,11 +148,10 @@ fn face_from_slice(
})
}
-
impl<T: CoordSystem> HasFaces<T> for Q3BSPFile<T> {
type FacesIter<'a> = std::slice::Iter<'a, Face>;
-
- fn faces_iter<'a>(&'a self) -> Self::FacesIter<'a> {
+
+ fn faces_iter(&self) -> Self::FacesIter<'_> {
self.faces.iter()
}
@@ -162,8 +159,7 @@ impl<T: CoordSystem> HasFaces<T> for Q3BSPFile<T> {
self.faces.len() as u32
}
- fn get_face<'a>(&'a self, index: u32) -> &'a Face {
+ fn get_face(&self, index: u32) -> &Face {
&self.faces[index as usize]
}
-
}
diff --git a/stockton-levels/src/q3/file.rs b/stockton-levels/src/q3/file.rs
index ecce783..7906823 100644
--- a/stockton-levels/src/q3/file.rs
+++ b/stockton-levels/src/q3/file.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -21,126 +21,142 @@ use bitvec::prelude::*;
use std::marker::PhantomData;
use self::header::Header;
-use crate::types::Result;
use crate::coords::*;
+use crate::types::Result;
use super::*;
-use crate::traits::textures::Texture;
-use crate::traits::entities::Entity;
-use crate::traits::planes::Plane;
-use crate::traits::vertices::{Vertex, MeshVert};
-use crate::traits::light_maps::LightMap;
-use crate::traits::light_vols::LightVol;
use crate::traits::brushes::Brush;
use crate::traits::effects::Effect;
+use crate::traits::entities::Entity;
use crate::traits::faces::Face;
-use crate::traits::tree::BSPNode;
+use crate::traits::light_maps::LightMap;
+use crate::traits::light_vols::LightVol;
use crate::traits::models::Model;
+use crate::traits::planes::Plane;
+use crate::traits::textures::Texture;
+use crate::traits::tree::BSPNode;
+use crate::traits::vertices::{MeshVert, Vertex};
/// A parsed Quake 3 BSP File.
pub struct Q3BSPFile<T: CoordSystem> {
- pub(crate) visdata: Box<[BitBox<Local, u8>]>,
- pub(crate) textures: Box<[Texture]>,
- pub(crate) entities: Box<[Entity]>,
- pub(crate) planes: Box<[Plane]>,
- pub(crate) vertices: Box<[Vertex]>,
- pub(crate) meshverts: Box<[MeshVert]>,
- pub(crate) light_maps: Box<[LightMap]>,
- pub(crate) light_vols: Box<[LightVol]>,
- pub(crate) brushes: Box<[Brush]>,
- pub(crate) effects: Box<[Effect]>,
- pub(crate) faces: Box<[Face]>,
- pub(crate) models: Box<[Model]>,
- pub(crate) tree_root: BSPNode,
- _phantom: PhantomData<T>
+ pub(crate) visdata: Box<[BitBox<Local, u8>]>,
+ pub(crate) textures: Box<[Texture]>,
+ pub(crate) entities: Box<[Entity]>,
+ pub(crate) planes: Box<[Plane]>,
+ pub(crate) vertices: Box<[Vertex]>,
+ pub(crate) meshverts: Box<[MeshVert]>,
+ pub(crate) light_maps: Box<[LightMap]>,
+ pub(crate) light_vols: Box<[LightVol]>,
+ pub(crate) brushes: Box<[Brush]>,
+ pub(crate) effects: Box<[Effect]>,
+ pub(crate) faces: Box<[Face]>,
+ pub(crate) models: Box<[Model]>,
+ pub(crate) tree_root: BSPNode,
+ _phantom: PhantomData<T>,
}
impl Q3BSPFile<Q3System> {
- /// Parse `data` as a quake 3 bsp file.
- pub fn parse_file(data: &[u8]) -> Result<Q3BSPFile<Q3System>> {
- let header = Header::from(data)?;
-
- let entities = entities::from_data(header.get_lump(&data, 0))?;
- let textures = textures::from_data(header.get_lump(&data, 1))?;
- let planes = planes::from_data(header.get_lump(&data, 2))?;
- let vertices = vertices::verts_from_data(header.get_lump(&data, 10))?;
- let meshverts = vertices::meshverts_from_data(header.get_lump(&data, 11))?;
- let light_maps = light_maps::from_data(header.get_lump(&data, 14))?;
- let light_vols = light_vols::from_data(header.get_lump(&data, 15))?;
- let visdata = visdata::from_data(header.get_lump(&data, 16))?;
- let brushes = brushes::from_data(
- header.get_lump(&data, 8),
- header.get_lump(&data, 9),
- textures.len() as u32,
- planes.len() as u32
- )?;
- let effects = effects::from_data(header.get_lump(&data, 12), brushes.len() as u32)?;
- let faces = faces::from_data(
- header.get_lump(&data, 13),
- textures.len() as u32,
- effects.len() as u32,
- vertices.len() as u32,
- meshverts.len() as u32,
- light_maps.len() as u32
- )?;
-
- let tree_root = tree::from_data(
- header.get_lump(&data, 3),
- header.get_lump(&data, 4),
- header.get_lump(&data, 5),
- header.get_lump(&data, 6),
- faces.len() as u32,
- brushes.len() as u32
- )?;
-
- let models = models::from_data(header.get_lump(&data, 7), faces.len() as u32, brushes.len() as u32)?;
-
- Ok(Q3BSPFile {
- visdata, textures, entities, planes, vertices, meshverts, light_maps,
- light_vols, brushes, effects, faces, tree_root, models,
- _phantom: PhantomData
- })
- }
+ /// Parse `data` as a quake 3 bsp file.
+ pub fn parse_file(data: &[u8]) -> Result<Q3BSPFile<Q3System>> {
+ let header = Header::from(data)?;
+
+ let entities = entities::from_data(header.get_lump(&data, 0))?;
+ let textures = textures::from_data(header.get_lump(&data, 1))?;
+ let planes = planes::from_data(header.get_lump(&data, 2))?;
+ let vertices = vertices::verts_from_data(header.get_lump(&data, 10))?;
+ let meshverts = vertices::meshverts_from_data(header.get_lump(&data, 11))?;
+ let light_maps = light_maps::from_data(header.get_lump(&data, 14))?;
+ let light_vols = light_vols::from_data(header.get_lump(&data, 15))?;
+ let visdata = visdata::from_data(header.get_lump(&data, 16))?;
+ let brushes = brushes::from_data(
+ header.get_lump(&data, 8),
+ header.get_lump(&data, 9),
+ textures.len() as u32,
+ planes.len() as u32,
+ )?;
+ let effects = effects::from_data(header.get_lump(&data, 12), brushes.len() as u32)?;
+ let faces = faces::from_data(
+ header.get_lump(&data, 13),
+ textures.len() as u32,
+ effects.len() as u32,
+ vertices.len() as u32,
+ meshverts.len() as u32,
+ light_maps.len() as u32,
+ )?;
+
+ let tree_root = tree::from_data(
+ header.get_lump(&data, 3),
+ header.get_lump(&data, 4),
+ header.get_lump(&data, 5),
+ header.get_lump(&data, 6),
+ faces.len() as u32,
+ brushes.len() as u32,
+ )?;
+
+ let models = models::from_data(
+ header.get_lump(&data, 7),
+ faces.len() as u32,
+ brushes.len() as u32,
+ )?;
+
+ Ok(Q3BSPFile {
+ visdata,
+ textures,
+ entities,
+ planes,
+ vertices,
+ meshverts,
+ light_maps,
+ light_vols,
+ brushes,
+ effects,
+ faces,
+ tree_root,
+ models,
+ _phantom: PhantomData,
+ })
+ }
}
impl<T: CoordSystem> Q3BSPFile<T> {
- pub fn swizzle_to<D: CoordSystem>(mut self) -> Q3BSPFile<D>
- where Swizzler: SwizzleFromTo<T, D> {
-
- for vertex in self.vertices.iter_mut() {
- Swizzler::swizzle(&mut vertex.normal);
- Swizzler::swizzle(&mut vertex.position);
- }
-
- for model in self.models.iter_mut() {
- Swizzler::swizzle(&mut model.mins);
- Swizzler::swizzle(&mut model.maxs);
- }
-
- for face in self.faces.iter_mut() {
- Swizzler::swizzle(&mut face.normal);
- }
-
- for plane in self.planes.iter_mut() {
- Swizzler::swizzle(&mut plane.normal);
- }
-
- // TODO: Possibly don't need to move?
- Q3BSPFile {
- visdata: self.visdata,
- textures: self.textures,
- entities: self.entities,
- planes: self.planes,
- vertices: self.vertices,
- meshverts: self.meshverts,
- light_maps: self.light_maps,
- light_vols: self.light_vols,
- brushes: self.brushes,
- effects: self.effects,
- faces: self.faces,
- tree_root: self.tree_root,
- models: self.models,
- _phantom: PhantomData
- }
- }
-} \ No newline at end of file
+ pub fn swizzle_to<D: CoordSystem>(mut self) -> Q3BSPFile<D>
+ where
+ Swizzler: SwizzleFromTo<T, D>,
+ {
+ for vertex in self.vertices.iter_mut() {
+ Swizzler::swizzle(&mut vertex.normal);
+ Swizzler::swizzle(&mut vertex.position);
+ }
+
+ for model in self.models.iter_mut() {
+ Swizzler::swizzle(&mut model.mins);
+ Swizzler::swizzle(&mut model.maxs);
+ }
+
+ for face in self.faces.iter_mut() {
+ Swizzler::swizzle(&mut face.normal);
+ }
+
+ for plane in self.planes.iter_mut() {
+ Swizzler::swizzle(&mut plane.normal);
+ }
+
+ // TODO: Possibly don't need to move?
+ Q3BSPFile {
+ visdata: self.visdata,
+ textures: self.textures,
+ entities: self.entities,
+ planes: self.planes,
+ vertices: self.vertices,
+ meshverts: self.meshverts,
+ light_maps: self.light_maps,
+ light_vols: self.light_vols,
+ brushes: self.brushes,
+ effects: self.effects,
+ faces: self.faces,
+ tree_root: self.tree_root,
+ models: self.models,
+ _phantom: PhantomData,
+ }
+ }
+}
diff --git a/stockton-levels/src/q3/header.rs b/stockton-levels/src/q3/header.rs
index d4e4f2f..46cfdac 100644
--- a/stockton-levels/src/q3/header.rs
+++ b/stockton-levels/src/q3/header.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
-use std::convert::TryInto;
use crate::types::{ParseError, Result};
+use std::convert::TryInto;
const MAGIC_HEADER: &[u8] = &[0x49, 0x42, 0x53, 0x50];
const HEADER_LEN: usize = 4 + 4 + (17 * 4 * 2);
@@ -80,4 +80,4 @@ impl Header {
&buf[entry.offset as usize..entry.offset as usize + entry.length as usize]
}
-} \ No newline at end of file
+}
diff --git a/stockton-levels/src/q3/light_maps.rs b/stockton-levels/src/q3/light_maps.rs
index 8fc1c83..2d0fcc6 100644
--- a/stockton-levels/src/q3/light_maps.rs
+++ b/stockton-levels/src/q3/light_maps.rs
@@ -15,10 +15,10 @@
// You should have received a copy of the GNU General Public License
// along with stockton-bsp. If not, see <http://www.gnu.org/licenses/>.
-use crate::types::{Result, RGB, ParseError};
-use crate::traits::light_maps::*;
use super::Q3BSPFile;
use crate::coords::CoordSystem;
+use crate::traits::light_maps::*;
+use crate::types::{ParseError, Result, RGB};
/// The size of one LightMap
const LIGHTMAP_SIZE: usize = 128 * 128 * 3;
@@ -35,10 +35,10 @@ pub fn from_data(data: &[u8]) -> Result<Box<[LightMap]>> {
let raw = &data[n * LIGHTMAP_SIZE..(n + 1) * LIGHTMAP_SIZE];
let mut map: [[RGB; 128]; 128] = [[RGB::white(); 128]; 128];
- for x in 0..128 {
- for y in 0..128 {
+ for (x, outer) in map.iter_mut().enumerate() {
+ for (y, inner) in outer.iter_mut().enumerate() {
let offset = (x * 128 * 3) + (y * 3);
- map[x][y] = RGB::from_slice(&raw[offset..offset + 3]);
+ *inner = RGB::from_slice(&raw[offset..offset + 3]);
}
}
maps.push(LightMap { map })
@@ -50,11 +50,11 @@ pub fn from_data(data: &[u8]) -> Result<Box<[LightMap]>> {
impl<T: CoordSystem> HasLightMaps for Q3BSPFile<T> {
type LightMapsIter<'a> = std::slice::Iter<'a, LightMap>;
- fn lightmaps_iter<'a>(&'a self) -> Self::LightMapsIter<'a> {
+ fn lightmaps_iter(&self) -> Self::LightMapsIter<'_> {
self.light_maps.iter()
}
- fn get_lightmap<'a>(&'a self, index: u32) -> &'a LightMap {
+ fn get_lightmap(&self, index: u32) -> &LightMap {
&self.light_maps[index as usize]
}
-} \ No newline at end of file
+}
diff --git a/stockton-levels/src/q3/light_vols.rs b/stockton-levels/src/q3/light_vols.rs
index d5bbadf..bec3bea 100644
--- a/stockton-levels/src/q3/light_vols.rs
+++ b/stockton-levels/src/q3/light_vols.rs
@@ -17,10 +17,10 @@
use std::convert::TryInto;
-use crate::types::{Result, ParseError, RGB};
-use crate::traits::light_vols::*;
use super::Q3BSPFile;
use crate::coords::CoordSystem;
+use crate::traits::light_vols::*;
+use crate::types::{ParseError, Result, RGB};
const VOL_LENGTH: usize = (3 * 2) + 2;
@@ -43,15 +43,14 @@ pub fn from_data(data: &[u8]) -> Result<Box<[LightVol]>> {
Ok(vols.into_boxed_slice())
}
-
impl<T: CoordSystem> HasLightVols for Q3BSPFile<T> {
type LightVolsIter<'a> = std::slice::Iter<'a, LightVol>;
- fn lightvols_iter<'a>(&'a self) -> Self::LightVolsIter<'a> {
+ fn lightvols_iter(&self) -> Self::LightVolsIter<'_> {
self.light_vols.iter()
}
- fn get_lightvol<'a>(&'a self, index: u32) -> &'a LightVol {
+ fn get_lightvol(&self, index: u32) -> &LightVol {
&self.light_vols[index as usize]
}
}
diff --git a/stockton-levels/src/q3/mod.rs b/stockton-levels/src/q3/mod.rs
index 72634f8..f7d3c86 100644
--- a/stockton-levels/src/q3/mod.rs
+++ b/stockton-levels/src/q3/mod.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -15,19 +15,19 @@
//! Parsing data from Q3 and similar BSPs
-mod visdata;
-mod header;
-mod textures;
-mod entities;
-mod planes;
-mod vertices;
-mod light_maps;
-mod light_vols;
mod brushes;
mod effects;
+mod entities;
mod faces;
-mod tree;
-mod models;
pub mod file;
+mod header;
+mod light_maps;
+mod light_vols;
+mod models;
+mod planes;
+mod textures;
+mod tree;
+mod vertices;
+mod visdata;
-pub use self::file::Q3BSPFile; \ No newline at end of file
+pub use self::file::Q3BSPFile;
diff --git a/stockton-levels/src/q3/models.rs b/stockton-levels/src/q3/models.rs
index 75f42fa..b197521 100644
--- a/stockton-levels/src/q3/models.rs
+++ b/stockton-levels/src/q3/models.rs
@@ -15,19 +15,15 @@
// You should have received a copy of the GNU General Public License
// along with stockton-bsp. If not, see <http://www.gnu.org/licenses/>.
-use crate::helpers::{slice_to_u32, slice_to_vec3};
-use crate::types::{Result, ParseError};
+use super::Q3BSPFile;
use crate::coords::CoordSystem;
+use crate::helpers::{slice_to_u32, slice_to_vec3};
use crate::traits::models::*;
-use super::Q3BSPFile;
+use crate::types::{ParseError, Result};
const MODEL_SIZE: usize = (4 * 3 * 2) + (4 * 4);
-pub fn from_data(
- data: &[u8],
- n_faces: u32,
- n_brushes: u32,
-) -> Result<Box<[Model]>> {
+pub fn from_data(data: &[u8], n_faces: u32, n_brushes: u32) -> Result<Box<[Model]>> {
if data.len() % MODEL_SIZE != 0 {
return Err(ParseError::Invalid);
}
@@ -48,7 +44,7 @@ pub fn from_data(
return Err(ParseError::Invalid);
}
- start..start+n
+ start..start + n
};
let brushes_idx = {
@@ -59,7 +55,7 @@ pub fn from_data(
return Err(ParseError::Invalid);
}
- start..start+n
+ start..start + n
};
models.push(Model {
@@ -73,15 +69,14 @@ pub fn from_data(
Ok(models.into_boxed_slice())
}
-
impl<T: CoordSystem> HasModels<T> for Q3BSPFile<T> {
type ModelsIter<'a> = std::slice::Iter<'a, Model>;
- fn models_iter<'a>(&'a self) -> Self::ModelsIter<'a> {
+ fn models_iter(&self) -> Self::ModelsIter<'_> {
self.models.iter()
}
- fn get_model<'a>(&'a self, index: u32) -> &'a Model {
+ fn get_model(&self, index: u32) -> &Model {
&self.models[index as usize]
}
}
diff --git a/stockton-levels/src/q3/planes.rs b/stockton-levels/src/q3/planes.rs
index 618a441..7acc872 100644
--- a/stockton-levels/src/q3/planes.rs
+++ b/stockton-levels/src/q3/planes.rs
@@ -17,22 +17,20 @@
const PLANE_SIZE: usize = (4 * 3) + 4;
-use crate::helpers::{slice_to_f32, slice_to_vec3};
-use crate::types::{Result, ParseError};
-use crate::traits::planes::*;
use super::Q3BSPFile;
use crate::coords::CoordSystem;
+use crate::helpers::{slice_to_f32, slice_to_vec3};
+use crate::traits::planes::*;
+use crate::types::{ParseError, Result};
/// Parse a lump of planes.
/// A lump is (data length / plane size) planes long
pub fn from_data(data: &[u8]) -> Result<Box<[Plane]>> {
-
let length = data.len() / PLANE_SIZE;
if data.is_empty() || data.len() % PLANE_SIZE != 0 || length % 2 != 0 {
return Err(ParseError::Invalid);
}
-
let mut planes = Vec::with_capacity(length / 2);
for n in 0..length {
let offset = n * PLANE_SIZE;
@@ -49,11 +47,11 @@ pub fn from_data(data: &[u8]) -> Result<Box<[Plane]>> {
impl<T: CoordSystem> HasPlanes<T> for Q3BSPFile<T> {
type PlanesIter<'a> = std::slice::Iter<'a, Plane>;
- fn planes_iter<'a>(&'a self) -> Self::PlanesIter<'a> {
+ fn planes_iter(&self) -> Self::PlanesIter<'_> {
self.planes.iter()
}
- fn get_plane<'a>(&'a self, idx: u32) -> &'a Plane {
+ fn get_plane(&self, idx: u32) -> &Plane {
&self.planes[idx as usize]
}
-} \ No newline at end of file
+}
diff --git a/stockton-levels/src/q3/textures.rs b/stockton-levels/src/q3/textures.rs
index e317898..5f8a19f 100644
--- a/stockton-levels/src/q3/textures.rs
+++ b/stockton-levels/src/q3/textures.rs
@@ -18,10 +18,10 @@
use std::str;
use super::Q3BSPFile;
-use crate::traits::textures::*;
-use crate::helpers::slice_to_u32;
-use crate::types::{Result, ParseError};
use crate::coords::CoordSystem;
+use crate::helpers::slice_to_u32;
+use crate::traits::textures::*;
+use crate::types::{ParseError, Result};
const TEXTURE_LUMP_SIZE: usize = 64 + 4 + 4;
@@ -42,9 +42,16 @@ pub fn from_data(lump: &[u8]) -> Result<Box<[Texture]>> {
for n in 0..length {
let offset = n * TEXTURE_LUMP_SIZE;
textures.push(Texture {
- name: str::from_utf8(&lump[offset..offset + 64]).map_err(|_| ParseError::Invalid)?.trim_matches('\0').to_owned(),
- surface: SurfaceFlags::from_bits_truncate(slice_to_u32(&lump[offset + 64..offset + 68])),
- contents: ContentsFlags::from_bits_truncate(slice_to_u32(&lump[offset + 68..offset + 72])),
+ name: str::from_utf8(&lump[offset..offset + 64])
+ .map_err(|_| ParseError::Invalid)?
+ .trim_matches('\0')
+ .to_owned(),
+ surface: SurfaceFlags::from_bits_truncate(slice_to_u32(
+ &lump[offset + 64..offset + 68],
+ )),
+ contents: ContentsFlags::from_bits_truncate(slice_to_u32(
+ &lump[offset + 68..offset + 72],
+ )),
});
}
@@ -54,11 +61,11 @@ pub fn from_data(lump: &[u8]) -> Result<Box<[Texture]>> {
impl<T: CoordSystem> HasTextures for Q3BSPFile<T> {
type TexturesIter<'a> = std::slice::Iter<'a, Texture>;
- fn textures_iter<'a>(&'a self) -> Self::TexturesIter<'a> {
+ fn textures_iter(&self) -> Self::TexturesIter<'_> {
self.textures.iter()
}
- fn get_texture<'a>(&'a self, idx: u32) -> &'a Texture {
+ fn get_texture(&self, idx: u32) -> &Texture {
&self.textures[idx as usize]
}
}
@@ -84,10 +91,7 @@ fn textures_single_texture() {
lump[0].surface,
SurfaceFlags::NO_DAMAGE | SurfaceFlags::SLICK | SurfaceFlags::FLESH | SurfaceFlags::DUST
);
- assert_eq!(
- lump[0].contents,
- ContentsFlags::SOLID | ContentsFlags::LAVA
- );
+ assert_eq!(lump[0].contents, ContentsFlags::SOLID | ContentsFlags::LAVA);
}
#[test]
@@ -140,13 +144,7 @@ fn textures_multiple_textures() {
SurfaceFlags::POINT_LIGHT | SurfaceFlags::SKIP
);
- assert_eq!(
- lump[0].contents,
- ContentsFlags::SOLID | ContentsFlags::LAVA
- );
+ assert_eq!(lump[0].contents, ContentsFlags::SOLID | ContentsFlags::LAVA);
assert_eq!(lump[1].contents, ContentsFlags::SOLID);
- assert_eq!(
- lump[2].contents,
- ContentsFlags::SOLID | ContentsFlags::FOG
- );
+ assert_eq!(lump[2].contents, ContentsFlags::SOLID | ContentsFlags::FOG);
}
diff --git a/stockton-levels/src/q3/tree.rs b/stockton-levels/src/q3/tree.rs
index 4d49e76..bc22b22 100644
--- a/stockton-levels/src/q3/tree.rs
+++ b/stockton-levels/src/q3/tree.rs
@@ -17,11 +17,11 @@
//! Parses the BSP tree into a usable format
+use super::Q3BSPFile;
use crate::coords::CoordSystem;
-use crate::helpers::{slice_to_u32, slice_to_i32, slice_to_vec3i};
-use crate::types::{ParseError, Result};
+use crate::helpers::{slice_to_i32, slice_to_u32, slice_to_vec3i};
use crate::traits::tree::*;
-use super::Q3BSPFile;
+use crate::types::{ParseError, Result};
const NODE_SIZE: usize = 4 + (4 * 2) + (4 * 3) + (4 * 3);
const LEAF_SIZE: usize = 4 * 6 + (4 * 3 * 2);
@@ -39,18 +39,17 @@ pub fn from_data(
}
Ok(compile_node(
- 0,
- nodes,
- leaves,
- leaf_faces,
- leaf_brushes,
- n_faces,
- n_brushes,
- )?,
- )
+ 0,
+ nodes,
+ leaves,
+ leaf_faces,
+ leaf_brushes,
+ n_faces,
+ n_brushes,
+ )?)
}
- /// Internal function. Visits given node and all its children. Used to recursively build tree.
+/// Internal function. Visits given node and all its children. Used to recursively build tree.
fn compile_node(
i: i32,
nodes: &[u8],
@@ -93,7 +92,7 @@ fn compile_node(
let start = slice_to_u32(&raw[40..44]) as usize;
let n = slice_to_u32(&raw[44..48]) as usize;
let mut brushes = Vec::with_capacity(n);
-
+
if n > 0 {
if start + n > leaf_brushes.len() / 4 {
return Err(ParseError::Invalid);
@@ -163,7 +162,7 @@ fn compile_node(
}
impl<T: CoordSystem> HasBSPTree<T> for Q3BSPFile<T> {
- fn get_bsp_root<'a>(&'a self) -> &'a BSPNode {
+ fn get_bsp_root(&self) -> &BSPNode {
&self.tree_root
}
-} \ No newline at end of file
+}
diff --git a/stockton-levels/src/q3/vertices.rs b/stockton-levels/src/q3/vertices.rs
index d517ede..649d0d5 100644
--- a/stockton-levels/src/q3/vertices.rs
+++ b/stockton-levels/src/q3/vertices.rs
@@ -18,10 +18,10 @@
use std::convert::TryInto;
use super::Q3BSPFile;
+use crate::coords::CoordSystem;
use crate::helpers::{slice_to_u32, slice_to_vec3};
-use crate::types::{Result, ParseError, RGBA};
use crate::traits::vertices::*;
-use crate::coords::CoordSystem;
+use crate::types::{ParseError, Result, RGBA};
/// The size of one vertex
const VERTEX_SIZE: usize = (4 * 3) + (2 * 2 * 4) + (4 * 3) + 4;
@@ -56,7 +56,6 @@ pub fn meshverts_from_data(data: &[u8]) -> Result<Box<[MeshVert]>> {
}
let length = data.len() / 4;
-
let mut meshverts = Vec::with_capacity(length as usize);
for n in 0..length {
meshverts.push(slice_to_u32(&data[n * 4..(n + 1) * 4]))
@@ -68,11 +67,11 @@ pub fn meshverts_from_data(data: &[u8]) -> Result<Box<[MeshVert]>> {
impl<T: CoordSystem> HasVertices<T> for Q3BSPFile<T> {
type VerticesIter<'a> = std::slice::Iter<'a, Vertex>;
- fn vertices_iter<'a>(&'a self) -> Self::VerticesIter<'a> {
+ fn vertices_iter(&self) -> Self::VerticesIter<'_> {
self.vertices.iter()
}
- fn get_vertex<'a>(&'a self, index: u32) -> &'a Vertex {
+ fn get_vertex(&self, index: u32) -> &Vertex {
&self.vertices[index as usize]
}
}
@@ -80,11 +79,11 @@ impl<T: CoordSystem> HasVertices<T> for Q3BSPFile<T> {
impl<T: CoordSystem> HasMeshVerts<T> for Q3BSPFile<T> {
type MeshVertsIter<'a> = std::slice::Iter<'a, MeshVert>;
- fn meshverts_iter<'a>(&'a self) -> Self::MeshVertsIter<'a> {
+ fn meshverts_iter(&self) -> Self::MeshVertsIter<'_> {
self.meshverts.iter()
}
fn get_meshvert<'a>(&self, index: u32) -> MeshVert {
self.meshverts[index as usize]
}
-} \ No newline at end of file
+}
diff --git a/stockton-levels/src/q3/visdata.rs b/stockton-levels/src/q3/visdata.rs
index fd48415..92b61d5 100644
--- a/stockton-levels/src/q3/visdata.rs
+++ b/stockton-levels/src/q3/visdata.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -14,22 +14,21 @@
// with this program. If not, see <http://www.gnu.org/licenses/>.
//! Parses visdata from Q3 BSPs.
-
-use std::vec::IntoIter;
use bitvec::prelude::*;
+use std::vec::IntoIter;
-use crate::types::{Result, ParseError};
-use crate::traits::visdata::*;
-use crate::helpers::slice_to_i32;
use super::file::Q3BSPFile;
use crate::coords::CoordSystem;
+use crate::helpers::slice_to_i32;
+use crate::traits::visdata::*;
+use crate::types::{ParseError, Result};
/// Stores cluster-to-cluster visibility information.
pub fn from_data(data: &[u8]) -> Result<Box<[BitBox<Local, u8>]>> {
if data.len() < 8 {
return Err(ParseError::Invalid);
}
-
+
let n_vecs = slice_to_i32(&data[0..4]) as usize;
let size_vecs = slice_to_i32(&data[4..8]) as usize;
@@ -53,7 +52,7 @@ impl<T: CoordSystem> HasVisData for Q3BSPFile<T> {
fn all_visible_from(&self, from: ClusterId) -> Self::VisibleIterator {
let mut visible = vec![];
- for (idx,val) in self.visdata[from as usize].iter().enumerate() {
+ for (idx, val) in self.visdata[from as usize].iter().enumerate() {
if *val {
visible.push(idx as u32);
}
@@ -66,4 +65,3 @@ impl<T: CoordSystem> HasVisData for Q3BSPFile<T> {
self.visdata[from as usize][dest as usize]
}
}
-
diff --git a/stockton-levels/src/traits/brushes.rs b/stockton-levels/src/traits/brushes.rs
index 30ab420..a281394 100644
--- a/stockton-levels/src/traits/brushes.rs
+++ b/stockton-levels/src/traits/brushes.rs
@@ -39,6 +39,6 @@ pub struct BrushSide {
pub trait HasBrushes<S: CoordSystem>: HasPlanes<S> {
type BrushesIter<'a>: Iterator<Item = &'a Brush>;
- fn brushes_iter<'a>(&'a self) -> Self::BrushesIter<'a>;
- fn get_brush<'a>(&'a self, index: u32) -> &'a Brush;
+ fn brushes_iter(&self) -> Self::BrushesIter<'_>;
+ fn get_brush(&self, index: u32) -> &Brush;
}
diff --git a/stockton-levels/src/traits/effects.rs b/stockton-levels/src/traits/effects.rs
index dec2122..73f55bd 100644
--- a/stockton-levels/src/traits/effects.rs
+++ b/stockton-levels/src/traits/effects.rs
@@ -25,14 +25,12 @@ pub struct Effect {
pub name: String,
/// The brush used for this effect
- pub brush_idx: u32
-
- // todo: unknown: i32
+ pub brush_idx: u32, // todo: unknown: i32
}
pub trait HasEffects<S: CoordSystem>: HasBrushes<S> {
type EffectsIter<'a>: Iterator<Item = &'a Effect>;
- fn effects_iter<'a>(&'a self) -> Self::EffectsIter<'a>;
- fn get_effect<'a>(&'a self, index: u32) -> &'a Effect;
+ fn effects_iter(&self) -> Self::EffectsIter<'_>;
+ fn get_effect(&self, index: u32) -> &Effect;
}
diff --git a/stockton-levels/src/traits/entities.rs b/stockton-levels/src/traits/entities.rs
index 706f25a..e1370ed 100644
--- a/stockton-levels/src/traits/entities.rs
+++ b/stockton-levels/src/traits/entities.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
-use std::iter::Iterator;
use std::collections::HashMap;
+use std::iter::Iterator;
#[derive(Debug, Clone, PartialEq)]
/// A game entity
@@ -23,7 +23,7 @@ pub struct Entity {
}
pub trait HasEntities {
- type EntitiesIter<'a>: Iterator<Item = &'a Entity>;
+ type EntitiesIter<'a>: Iterator<Item = &'a Entity>;
- fn entities_iter<'a>(&'a self) -> Self::EntitiesIter<'a>;
-} \ No newline at end of file
+ fn entities_iter(&self) -> Self::EntitiesIter<'_>;
+}
diff --git a/stockton-levels/src/traits/faces.rs b/stockton-levels/src/traits/faces.rs
index 50d2b7d..3b9fbdf 100644
--- a/stockton-levels/src/traits/faces.rs
+++ b/stockton-levels/src/traits/faces.rs
@@ -15,10 +15,10 @@
// You should have received a copy of the GNU General Public License
// along with stockton-bsp. If not, see <http://www.gnu.org/licenses/>.
-use std::ops::Range;
use na::{Vector2, Vector3};
+use std::ops::Range;
-use super::{HasEffects, HasTextures, HasLightMaps, HasMeshVerts};
+use super::{HasEffects, HasLightMaps, HasMeshVerts, HasTextures};
use crate::coords::CoordSystem;
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -43,15 +43,17 @@ pub struct Face {
pub map_size: Vector2<u32>,
pub map_origin: Vector3<f32>,
pub map_vecs: [Vector3<f32>; 2],
-
+
pub normal: Vector3<f32>,
pub size: Vector2<u32>,
}
-pub trait HasFaces<S: CoordSystem>: HasTextures + HasEffects<S> + HasLightMaps + HasMeshVerts<S> {
+pub trait HasFaces<S: CoordSystem>:
+ HasTextures + HasEffects<S> + HasLightMaps + HasMeshVerts<S>
+{
type FacesIter<'a>: Iterator<Item = &'a Face>;
- fn faces_iter<'a>(&'a self) -> Self::FacesIter<'a>;
+ fn faces_iter(&self) -> Self::FacesIter<'_>;
fn faces_len(&self) -> u32;
- fn get_face<'a>(&'a self, index: u32) -> &'a Face;
+ fn get_face(&self, index: u32) -> &Face;
}
diff --git a/stockton-levels/src/traits/light_maps.rs b/stockton-levels/src/traits/light_maps.rs
index 9b30d91..59dc27f 100644
--- a/stockton-levels/src/traits/light_maps.rs
+++ b/stockton-levels/src/traits/light_maps.rs
@@ -57,6 +57,6 @@ impl fmt::Debug for LightMap {
pub trait HasLightMaps {
type LightMapsIter<'a>: Iterator<Item = &'a LightMap>;
- fn lightmaps_iter<'a>(&'a self) -> Self::LightMapsIter<'a>;
- fn get_lightmap<'a>(&'a self, index: u32) -> &'a LightMap;
-} \ No newline at end of file
+ fn lightmaps_iter(&self) -> Self::LightMapsIter<'_>;
+ fn get_lightmap(&self, index: u32) -> &LightMap;
+}
diff --git a/stockton-levels/src/traits/light_vols.rs b/stockton-levels/src/traits/light_vols.rs
index 8e75401..871f028 100644
--- a/stockton-levels/src/traits/light_vols.rs
+++ b/stockton-levels/src/traits/light_vols.rs
@@ -27,6 +27,6 @@ pub struct LightVol {
pub trait HasLightVols {
type LightVolsIter<'a>: Iterator<Item = &'a LightVol>;
- fn lightvols_iter<'a>(&'a self) -> Self::LightVolsIter<'a>;
- fn get_lightvol<'a>(&'a self, index: u32) -> &'a LightVol;
+ fn lightvols_iter(&self) -> Self::LightVolsIter<'_>;
+ fn get_lightvol(&self, index: u32) -> &LightVol;
}
diff --git a/stockton-levels/src/traits/mod.rs b/stockton-levels/src/traits/mod.rs
index 15bac30..3ee47b4 100644
--- a/stockton-levels/src/traits/mod.rs
+++ b/stockton-levels/src/traits/mod.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -14,28 +14,28 @@
// with this program. If not, see <http://www.gnu.org/licenses/>.
//! Traits for parts of files that can exist
-pub mod visdata;
-pub mod entities;
-pub mod textures;
-pub mod planes;
-pub mod vertices;
-pub mod light_maps;
-pub mod light_vols;
pub mod brushes;
pub mod effects;
+pub mod entities;
pub mod faces;
-pub mod tree;
+pub mod light_maps;
+pub mod light_vols;
pub mod models;
+pub mod planes;
+pub mod textures;
+pub mod tree;
+pub mod vertices;
+pub mod visdata;
-pub use self::visdata::HasVisData;
-pub use self::textures::HasTextures;
-pub use self::entities::HasEntities;
-pub use self::planes::HasPlanes;
-pub use self::vertices::{HasVertices, HasMeshVerts};
-pub use self::light_maps::HasLightMaps;
-pub use self::light_vols::HasLightVols;
pub use self::brushes::HasBrushes;
pub use self::effects::HasEffects;
+pub use self::entities::HasEntities;
pub use self::faces::HasFaces;
+pub use self::light_maps::HasLightMaps;
+pub use self::light_vols::HasLightVols;
+pub use self::models::HasModels;
+pub use self::planes::HasPlanes;
+pub use self::textures::HasTextures;
pub use self::tree::HasBSPTree;
-pub use self::models::HasModels; \ No newline at end of file
+pub use self::vertices::{HasMeshVerts, HasVertices};
+pub use self::visdata::HasVisData;
diff --git a/stockton-levels/src/traits/models.rs b/stockton-levels/src/traits/models.rs
index 4f755f3..1f868ad 100644
--- a/stockton-levels/src/traits/models.rs
+++ b/stockton-levels/src/traits/models.rs
@@ -18,7 +18,7 @@
use na::Vector3;
use std::ops::Range;
-use super::{HasFaces, HasBrushes};
+use super::{HasBrushes, HasFaces};
use crate::coords::CoordSystem;
#[derive(Debug, Clone)]
@@ -32,6 +32,6 @@ pub struct Model {
pub trait HasModels<S: CoordSystem>: HasFaces<S> + HasBrushes<S> {
type ModelsIter<'a>: Iterator<Item = &'a Model>;
- fn models_iter<'a>(&'a self) -> Self::ModelsIter<'a>;
- fn get_model<'a>(&'a self, index: u32) -> &'a Model;
+ fn models_iter(&self) -> Self::ModelsIter<'_>;
+ fn get_model(&self, index: u32) -> &Model;
}
diff --git a/stockton-levels/src/traits/planes.rs b/stockton-levels/src/traits/planes.rs
index c024815..e827a31 100644
--- a/stockton-levels/src/traits/planes.rs
+++ b/stockton-levels/src/traits/planes.rs
@@ -15,9 +15,9 @@
// You should have received a copy of the GNU General Public License
// along with rust-bsp. If not, see <http://www.gnu.org/licenses/>.
-use std::iter::Iterator;
-use na::Vector3;
use crate::coords::CoordSystem;
+use na::Vector3;
+use std::iter::Iterator;
/// The planes lump from a BSP file.
/// Found at lump index 2 in a q3 bsp.
@@ -39,6 +39,6 @@ pub struct Plane {
pub trait HasPlanes<S: CoordSystem> {
type PlanesIter<'a>: Iterator<Item = &'a Plane>;
- fn planes_iter<'a>(&'a self) -> Self::PlanesIter<'a>;
- fn get_plane<'a>(&'a self, idx: u32) -> &'a Plane;
-} \ No newline at end of file
+ fn planes_iter(&self) -> Self::PlanesIter<'_>;
+ fn get_plane(&self, idx: u32) -> &Plane;
+}
diff --git a/stockton-levels/src/traits/textures.rs b/stockton-levels/src/traits/textures.rs
index 16213ea..a9c9bc9 100644
--- a/stockton-levels/src/traits/textures.rs
+++ b/stockton-levels/src/traits/textures.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -23,21 +23,20 @@ pub struct Texture {
pub contents: ContentsFlags,
}
-
bitflags!(
/// Extracted from the Q3 arena engine code.
/// https://github.com/id-Software/Quake-III-Arena/blob/master/code/game/surfaceflags.h
pub struct SurfaceFlags: u32 {
/// never give falling damage
const NO_DAMAGE = 0x1;
-
+
/// affects game physics
const SLICK = 0x2;
-
+
/// lighting from environment map
const SKY = 0x4;
- /// don't make missile explosions
+ /// don't make missile explosions
const NO_IMPACT = 0x10;
/// function as a ladder
@@ -45,43 +44,43 @@ bitflags!(
/// don't leave missile marks
const NO_MARKS = 0x20;
-
+
/// make flesh sounds and effects
const FLESH = 0x40;
-
+
/// don't generate a drawsurface at all
const NODRAW = 0x80;
-
+
/// make a primary bsp splitter
const HINT = 0x01_00;
-
+
/// completely ignore, allowing non-closed brushes
const SKIP = 0x02_00;
-
+
/// surface doesn't need a lightmap
const NO_LIGHT_MAP = 0x04_00;
-
+
/// generate lighting info at vertexes
const POINT_LIGHT = 0x08_00;
-
+
/// clanking footsteps
const METAL_STEPS = 0x10_00;
-
+
/// no footstep sounds
const NO_STEPS = 0x20_00;
-
+
/// don't collide against curves with this set
const NON_SOLID = 0x40_00;
-
+
/// act as a light filter during q3map -light
const LIGHT_FILTER = 0x80_00;
-
+
/// do per-pixel light shadow casting in q3map
const ALPHA_SHADOW = 0x01_00_00;
-
+
/// don't dlight even if solid (solid lava, skies)
const NO_DLIGHT = 0x02_00_00;
-
+
/// leave a dust trail when walking on this surface
const DUST = 0x04_00_00;
}
@@ -116,7 +115,7 @@ bitflags!(
const DO_NOT_ENTER = 0x20_00_00;
const BOT_CLIP = 0x40_00_00;
const MOVER = 0x80_00_00;
-
+
// removed before bsping an entity
const ORIGIN = 0x01_00_00_00;
@@ -125,18 +124,18 @@ bitflags!(
/// brush not used for the bsp
const DETAIL = 0x08_00_00_00;
-
+
/// brush not used for the bsp
const CORPSE = 0x04_00_00_00;
/// brushes used for the bsp
const STRUCTURAL = 0x10_00_00_00;
-
+
/// don't consume surface fragments inside
const TRANSLUCENT = 0x20_00_00_00;
const TRIGGER = 0x40_00_00_00;
-
+
/// don't leave bodies or items (death fog, lava)
const NODROP = 0x80_00_00_00;
}
@@ -145,6 +144,6 @@ bitflags!(
pub trait HasTextures {
type TexturesIter<'a>: Iterator<Item = &'a Texture>;
- fn textures_iter<'a>(&'a self) -> Self::TexturesIter<'a>;
- fn get_texture<'a>(&'a self, idx: u32) -> &'a Texture;
+ fn textures_iter(&self) -> Self::TexturesIter<'_>;
+ fn get_texture(&self, idx: u32) -> &Texture;
}
diff --git a/stockton-levels/src/traits/tree.rs b/stockton-levels/src/traits/tree.rs
index c56576a..89be1c1 100644
--- a/stockton-levels/src/traits/tree.rs
+++ b/stockton-levels/src/traits/tree.rs
@@ -17,9 +17,9 @@
//! Parses the BSP tree into a usable format
-use na::Vector3;
-use super::{HasFaces, HasBrushes, HasVisData};
+use super::{HasBrushes, HasFaces, HasVisData};
use crate::coords::CoordSystem;
+use na::Vector3;
/// A node in a BSP tree.
/// Either has two children *or* a leaf entry.
@@ -28,13 +28,13 @@ pub struct BSPNode {
pub plane_idx: u32,
pub min: Vector3<i32>,
pub max: Vector3<i32>,
- pub value: BSPNodeValue
+ pub value: BSPNodeValue,
}
#[derive(Debug, Clone)]
pub enum BSPNodeValue {
- Leaf (BSPLeaf),
- Children (Box<BSPNode>, Box<BSPNode>)
+ Leaf(BSPLeaf),
+ Children(Box<BSPNode>, Box<BSPNode>),
}
/// A leaf in a BSP tree.
@@ -48,5 +48,5 @@ pub struct BSPLeaf {
}
pub trait HasBSPTree<S: CoordSystem>: HasFaces<S> + HasBrushes<S> + HasVisData {
- fn get_bsp_root<'a>(&'a self) -> &'a BSPNode;
-} \ No newline at end of file
+ fn get_bsp_root(&self) -> &BSPNode;
+}
diff --git a/stockton-levels/src/traits/vertices.rs b/stockton-levels/src/traits/vertices.rs
index 7b14c98..ddf315b 100644
--- a/stockton-levels/src/traits/vertices.rs
+++ b/stockton-levels/src/traits/vertices.rs
@@ -15,12 +15,11 @@
// You should have received a copy of the GNU General Public License
// along with stockton-bsp. If not, see <http://www.gnu.org/licenses/>.
-use crate::helpers::{slice_to_f32};
use crate::coords::CoordSystem;
+use crate::helpers::slice_to_f32;
use crate::types::RGBA;
use na::Vector3;
-
/// A vertex, used to describe a face.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vertex {
@@ -54,17 +53,17 @@ pub type MeshVert = u32;
pub trait HasVertices<S: CoordSystem> {
type VerticesIter<'a>: Iterator<Item = &'a Vertex>;
- fn vertices_iter<'a>(&'a self) -> Self::VerticesIter<'a>;
- fn get_vertex<'a>(&'a self, index: u32) -> &'a Vertex;
+ fn vertices_iter(&self) -> Self::VerticesIter<'_>;
+ fn get_vertex(&self, index: u32) -> &Vertex;
}
pub trait HasMeshVerts<S: CoordSystem>: HasVertices<S> {
type MeshVertsIter<'a>: Iterator<Item = &'a MeshVert>;
- fn meshverts_iter<'a>(&'a self) -> Self::MeshVertsIter<'a>;
+ fn meshverts_iter(&self) -> Self::MeshVertsIter<'_>;
fn get_meshvert(&self, index: u32) -> MeshVert;
- fn resolve_meshvert<'a>(&'a self, index: u32, base: u32) -> &'a Vertex {
+ fn resolve_meshvert(&self, index: u32, base: u32) -> &Vertex {
self.get_vertex(self.get_meshvert(index) + base)
}
-} \ No newline at end of file
+}
diff --git a/stockton-levels/src/traits/visdata.rs b/stockton-levels/src/traits/visdata.rs
index 92ba9b8..749000b 100644
--- a/stockton-levels/src/traits/visdata.rs
+++ b/stockton-levels/src/traits/visdata.rs
@@ -1,4 +1,4 @@
-// Copyright (C) Oscar Shrimpton 2019
+// Copyright (C) Oscar Shrimpton 2019
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -18,12 +18,12 @@ use std::iter::Iterator;
pub type ClusterId = u32;
pub trait HasVisData {
- /// The iterator returned from all_visible_from
- type VisibleIterator: Iterator<Item = ClusterId>;
+ /// The iterator returned from all_visible_from
+ type VisibleIterator: Iterator<Item = ClusterId>;
- /// Returns an iterator of all clusters visible from the given Cluster ID
- fn all_visible_from(&self, from: ClusterId) -> Self::VisibleIterator;
+ /// Returns an iterator of all clusters visible from the given Cluster ID
+ fn all_visible_from(&self, from: ClusterId) -> Self::VisibleIterator;
- /// Returns true if `dest` is visible from `from`.
- fn cluster_visible_from(&self, from: ClusterId, dest: ClusterId) -> bool;
-} \ No newline at end of file
+ /// Returns true if `dest` is visible from `from`.
+ fn cluster_visible_from(&self, from: ClusterId, dest: ClusterId) -> bool;
+}
diff --git a/stockton-levels/src/types.rs b/stockton-levels/src/types.rs
index 7bccd23..6f19b3d 100644
--- a/stockton-levels/src/types.rs
+++ b/stockton-levels/src/types.rs
@@ -86,8 +86,8 @@ impl RGB {
/// An error encountered while parsing.
pub enum ParseError {
Unsupported,
- Invalid
+ Invalid,
}
/// Standard result type.
-pub type Result<T> = std::result::Result<T, ParseError>; \ No newline at end of file
+pub type Result<T> = std::result::Result<T, ParseError>;