aboutsummaryrefslogtreecommitdiff
path: root/stockton-levels/src/q3
diff options
context:
space:
mode:
Diffstat (limited to 'stockton-levels/src/q3')
-rw-r--r--stockton-levels/src/q3/brushes.rs4
-rw-r--r--stockton-levels/src/q3/effects.rs4
-rw-r--r--stockton-levels/src/q3/entities.rs4
-rw-r--r--stockton-levels/src/q3/faces.rs4
-rw-r--r--stockton-levels/src/q3/file.rs18
-rw-r--r--stockton-levels/src/q3/light_maps.rs10
-rw-r--r--stockton-levels/src/q3/light_vols.rs10
-rw-r--r--stockton-levels/src/q3/mod.rs2
-rw-r--r--stockton-levels/src/q3/models.rs4
-rw-r--r--stockton-levels/src/q3/planes.rs4
-rw-r--r--stockton-levels/src/q3/textures.rs12
-rw-r--r--stockton-levels/src/q3/tree.rs24
-rw-r--r--stockton-levels/src/q3/vertices.rs10
-rw-r--r--stockton-levels/src/q3/visdata.rs4
14 files changed, 59 insertions, 55 deletions
diff --git a/stockton-levels/src/q3/brushes.rs b/stockton-levels/src/q3/brushes.rs
index 098967b..585d643 100644
--- a/stockton-levels/src/q3/brushes.rs
+++ b/stockton-levels/src/q3/brushes.rs
@@ -23,7 +23,7 @@ const BRUSH_SIZE: usize = 4 * 3;
/// The size of one brushsize record
const SIDE_SIZE: usize = 4 * 2;
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::helpers::slice_to_i32;
use crate::traits::brushes::*;
@@ -104,7 +104,7 @@ fn get_sides(
Ok(sides.into_boxed_slice())
}
-impl<T: CoordSystem> HasBrushes<T> for Q3BSPFile<T> {
+impl<T: CoordSystem> HasBrushes<T> for Q3BspFile<T> {
type BrushesIter<'a> = std::slice::Iter<'a, Brush>;
fn brushes_iter(&self) -> Self::BrushesIter<'_> {
diff --git a/stockton-levels/src/q3/effects.rs b/stockton-levels/src/q3/effects.rs
index c0aafac..f3786bd 100644
--- a/stockton-levels/src/q3/effects.rs
+++ b/stockton-levels/src/q3/effects.rs
@@ -17,7 +17,7 @@
use std::str;
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::helpers::slice_to_u32;
use crate::traits::effects::*;
@@ -52,7 +52,7 @@ pub fn from_data(data: &[u8], n_brushes: u32) -> Result<Box<[Effect]>> {
Ok(effects.into_boxed_slice())
}
-impl<T: CoordSystem> HasEffects<T> for Q3BSPFile<T> {
+impl<T: CoordSystem> HasEffects<T> for Q3BspFile<T> {
type EffectsIter<'a> = std::slice::Iter<'a, Effect>;
fn effects_iter(&self) -> Self::EffectsIter<'_> {
diff --git a/stockton-levels/src/q3/entities.rs b/stockton-levels/src/q3/entities.rs
index cb2a326..9eb0a61 100644
--- a/stockton-levels/src/q3/entities.rs
+++ b/stockton-levels/src/q3/entities.rs
@@ -18,7 +18,7 @@
use std::collections::HashMap;
use std::str;
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::traits::entities::*;
use crate::types::{ParseError, Result};
@@ -103,7 +103,7 @@ pub fn from_data(data: &[u8]) -> Result<Box<[Entity]>> {
Ok(entities.into_boxed_slice())
}
-impl<T: CoordSystem> HasEntities for Q3BSPFile<T> {
+impl<T: CoordSystem> HasEntities for Q3BspFile<T> {
type EntitiesIter<'a> = std::slice::Iter<'a, Entity>;
fn entities_iter(&self) -> Self::EntitiesIter<'_> {
diff --git a/stockton-levels/src/q3/faces.rs b/stockton-levels/src/q3/faces.rs
index e28c189..94420a0 100644
--- a/stockton-levels/src/q3/faces.rs
+++ b/stockton-levels/src/q3/faces.rs
@@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use super::Q3BSPFile;
+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::*;
@@ -148,7 +148,7 @@ fn face_from_slice(
})
}
-impl<T: CoordSystem> HasFaces<T> for Q3BSPFile<T> {
+impl<T: CoordSystem> HasFaces<T> for Q3BspFile<T> {
type FacesIter<'a> = std::slice::Iter<'a, Face>;
fn faces_iter(&self) -> Self::FacesIter<'_> {
diff --git a/stockton-levels/src/q3/file.rs b/stockton-levels/src/q3/file.rs
index 1440e21..48066f1 100644
--- a/stockton-levels/src/q3/file.rs
+++ b/stockton-levels/src/q3/file.rs
@@ -36,11 +36,11 @@ 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::tree::BspNode;
use crate::traits::vertices::{MeshVert, Vertex};
/// A parsed Quake 3 BSP File.
-pub struct Q3BSPFile<T: CoordSystem> {
+pub struct Q3BspFile<T: CoordSystem> {
pub(crate) visdata: Box<[BitBox<Local, u8>]>,
pub(crate) textures: Box<[Texture]>,
pub(crate) entities: Box<[Entity]>,
@@ -53,13 +53,13 @@ pub struct Q3BSPFile<T: CoordSystem> {
pub(crate) effects: Box<[Effect]>,
pub(crate) faces: Box<[Face]>,
pub(crate) models: Box<[Model]>,
- pub(crate) tree_root: BSPNode,
+ pub(crate) tree_root: BspNode,
_phantom: PhantomData<T>,
}
-impl Q3BSPFile<Q3System> {
+impl Q3BspFile<Q3System> {
/// Parse `data` as a quake 3 bsp file.
- pub fn parse_file(data: &[u8]) -> Result<Q3BSPFile<Q3System>> {
+ pub fn parse_file(data: &[u8]) -> Result<Q3BspFile<Q3System>> {
let header = Header::from(data)?;
let entities = entities::from_data(header.get_lump(&data, 0))?;
@@ -101,7 +101,7 @@ impl Q3BSPFile<Q3System> {
brushes.len() as u32,
)?;
- Ok(Q3BSPFile {
+ Ok(Q3BspFile {
visdata,
textures,
entities,
@@ -120,8 +120,8 @@ impl Q3BSPFile<Q3System> {
}
}
-impl<T: CoordSystem> Q3BSPFile<T> {
- pub fn swizzle_to<D: CoordSystem>(mut self) -> Q3BSPFile<D>
+impl<T: CoordSystem> Q3BspFile<T> {
+ pub fn swizzle_to<D: CoordSystem>(mut self) -> Q3BspFile<D>
where
Swizzler: SwizzleFromTo<T, D>,
{
@@ -144,7 +144,7 @@ impl<T: CoordSystem> Q3BSPFile<T> {
}
// TODO: Possibly don't need to move?
- Q3BSPFile {
+ Q3BspFile {
visdata: self.visdata,
textures: self.textures,
entities: self.entities,
diff --git a/stockton-levels/src/q3/light_maps.rs b/stockton-levels/src/q3/light_maps.rs
index 605b7c2..6e07d33 100644
--- a/stockton-levels/src/q3/light_maps.rs
+++ b/stockton-levels/src/q3/light_maps.rs
@@ -15,10 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::traits::light_maps::*;
-use crate::types::{ParseError, Result, RGB};
+use crate::types::{ParseError, Result, Rgb};
/// The size of one LightMap
const LIGHTMAP_SIZE: usize = 128 * 128 * 3;
@@ -33,12 +33,12 @@ pub fn from_data(data: &[u8]) -> Result<Box<[LightMap]>> {
let mut maps = Vec::with_capacity(length as usize);
for n in 0..length {
let raw = &data[n * LIGHTMAP_SIZE..(n + 1) * LIGHTMAP_SIZE];
- let mut map: [[RGB; 128]; 128] = [[RGB::white(); 128]; 128];
+ let mut map: [[Rgb; 128]; 128] = [[Rgb::white(); 128]; 128];
for (x, outer) in map.iter_mut().enumerate() {
for (y, inner) in outer.iter_mut().enumerate() {
let offset = (x * 128 * 3) + (y * 3);
- *inner = RGB::from_slice(&raw[offset..offset + 3]);
+ *inner = Rgb::from_slice(&raw[offset..offset + 3]);
}
}
maps.push(LightMap { map })
@@ -47,7 +47,7 @@ pub fn from_data(data: &[u8]) -> Result<Box<[LightMap]>> {
Ok(maps.into_boxed_slice())
}
-impl<T: CoordSystem> HasLightMaps for Q3BSPFile<T> {
+impl<T: CoordSystem> HasLightMaps for Q3BspFile<T> {
type LightMapsIter<'a> = std::slice::Iter<'a, LightMap>;
fn lightmaps_iter(&self) -> Self::LightMapsIter<'_> {
diff --git a/stockton-levels/src/q3/light_vols.rs b/stockton-levels/src/q3/light_vols.rs
index 1741569..932219e 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 super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::traits::light_vols::*;
-use crate::types::{ParseError, Result, RGB};
+use crate::types::{ParseError, Result, Rgb};
const VOL_LENGTH: usize = (3 * 2) + 2;
@@ -34,8 +34,8 @@ pub fn from_data(data: &[u8]) -> Result<Box<[LightVol]>> {
for n in 0..length {
let data = &data[n * VOL_LENGTH..(n + 1) * VOL_LENGTH];
vols.push(LightVol {
- ambient: RGB::from_slice(&data[0..3]),
- directional: RGB::from_slice(&data[3..6]),
+ ambient: Rgb::from_slice(&data[0..3]),
+ directional: Rgb::from_slice(&data[3..6]),
dir: data[6..8].try_into().unwrap(),
});
}
@@ -43,7 +43,7 @@ pub fn from_data(data: &[u8]) -> Result<Box<[LightVol]>> {
Ok(vols.into_boxed_slice())
}
-impl<T: CoordSystem> HasLightVols for Q3BSPFile<T> {
+impl<T: CoordSystem> HasLightVols for Q3BspFile<T> {
type LightVolsIter<'a> = std::slice::Iter<'a, LightVol>;
fn lightvols_iter(&self) -> Self::LightVolsIter<'_> {
diff --git a/stockton-levels/src/q3/mod.rs b/stockton-levels/src/q3/mod.rs
index 810ae29..16d1a39 100644
--- a/stockton-levels/src/q3/mod.rs
+++ b/stockton-levels/src/q3/mod.rs
@@ -32,4 +32,4 @@ mod tree;
mod vertices;
mod visdata;
-pub use self::file::Q3BSPFile;
+pub use self::file::Q3BspFile;
diff --git a/stockton-levels/src/q3/models.rs b/stockton-levels/src/q3/models.rs
index e43a987..a1cc8b4 100644
--- a/stockton-levels/src/q3/models.rs
+++ b/stockton-levels/src/q3/models.rs
@@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::helpers::{slice_to_u32, slice_to_vec3};
use crate::traits::models::*;
@@ -69,7 +69,7 @@ pub fn from_data(data: &[u8], n_faces: u32, n_brushes: u32) -> Result<Box<[Model
Ok(models.into_boxed_slice())
}
-impl<T: CoordSystem> HasModels<T> for Q3BSPFile<T> {
+impl<T: CoordSystem> HasModels<T> for Q3BspFile<T> {
type ModelsIter<'a> = std::slice::Iter<'a, Model>;
fn models_iter(&self) -> Self::ModelsIter<'_> {
diff --git a/stockton-levels/src/q3/planes.rs b/stockton-levels/src/q3/planes.rs
index 2ded1bf..4bd319f 100644
--- a/stockton-levels/src/q3/planes.rs
+++ b/stockton-levels/src/q3/planes.rs
@@ -17,7 +17,7 @@
const PLANE_SIZE: usize = (4 * 3) + 4;
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::helpers::{slice_to_f32, slice_to_vec3};
use crate::traits::planes::*;
@@ -44,7 +44,7 @@ pub fn from_data(data: &[u8]) -> Result<Box<[Plane]>> {
Ok(planes.into_boxed_slice())
}
-impl<T: CoordSystem> HasPlanes<T> for Q3BSPFile<T> {
+impl<T: CoordSystem> HasPlanes<T> for Q3BspFile<T> {
type PlanesIter<'a> = std::slice::Iter<'a, Plane>;
fn planes_iter(&self) -> Self::PlanesIter<'_> {
diff --git a/stockton-levels/src/q3/textures.rs b/stockton-levels/src/q3/textures.rs
index eaf4bb7..6b845eb 100644
--- a/stockton-levels/src/q3/textures.rs
+++ b/stockton-levels/src/q3/textures.rs
@@ -17,7 +17,7 @@
use std::str;
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::helpers::slice_to_u32;
use crate::traits::textures::*;
@@ -58,15 +58,19 @@ pub fn from_data(lump: &[u8]) -> Result<Box<[Texture]>> {
Ok(textures.into_boxed_slice())
}
-impl<T: CoordSystem> HasTextures for Q3BSPFile<T> {
+impl<T: CoordSystem> HasTextures for Q3BspFile<T> {
type TexturesIter<'a> = std::slice::Iter<'a, Texture>;
fn textures_iter(&self) -> Self::TexturesIter<'_> {
self.textures.iter()
}
- fn get_texture(&self, idx: u32) -> &Texture {
- &self.textures[idx as usize]
+ fn get_texture(&self, idx: u32) -> Option<&Texture> {
+ if idx >= self.textures.len() as u32 {
+ None
+ } else {
+ Some(&self.textures[idx as usize])
+ }
}
}
diff --git a/stockton-levels/src/q3/tree.rs b/stockton-levels/src/q3/tree.rs
index 598f71a..d399c7d 100644
--- a/stockton-levels/src/q3/tree.rs
+++ b/stockton-levels/src/q3/tree.rs
@@ -17,7 +17,7 @@
//! Parses the BSP tree into a usable format
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::helpers::{slice_to_i32, slice_to_u32, slice_to_vec3i};
use crate::traits::tree::*;
@@ -33,12 +33,12 @@ pub fn from_data(
leaf_brushes: &[u8],
n_faces: u32,
n_brushes: u32,
-) -> Result<BSPNode> {
+) -> Result<BspNode> {
if nodes.len() % NODE_SIZE != 0 || leaves.len() % LEAF_SIZE != 0 {
return Err(ParseError::Invalid);
}
- Ok(compile_node(
+ compile_node(
0,
nodes,
leaves,
@@ -46,7 +46,7 @@ pub fn from_data(
leaf_brushes,
n_faces,
n_brushes,
- )?)
+ )
}
/// Internal function. Visits given node and all its children. Used to recursively build tree.
@@ -58,7 +58,7 @@ fn compile_node(
leaf_brushes: &[u8],
n_faces: u32,
n_brushes: u32,
-) -> Result<BSPNode> {
+) -> Result<BspNode> {
if i < 0 {
// Leaf.
let i = i.abs() - 1;
@@ -111,7 +111,7 @@ fn compile_node(
brushes.into_boxed_slice()
};
- let leaf = BSPLeaf {
+ let leaf = BspLeaf {
cluster_id: slice_to_u32(&raw[0..4]),
area: slice_to_i32(&raw[4..8]),
// 8..20 = min
@@ -120,11 +120,11 @@ fn compile_node(
brushes_idx,
};
- Ok(BSPNode {
+ Ok(BspNode {
plane_idx: 0,
min: slice_to_vec3i(&raw[8..20]),
max: slice_to_vec3i(&raw[20..32]),
- value: BSPNodeValue::Leaf(leaf),
+ value: BspNodeValue::Leaf(leaf),
})
} else {
// Node.
@@ -152,17 +152,17 @@ fn compile_node(
let min = slice_to_vec3i(&raw[12..24]);
let max = slice_to_vec3i(&raw[24..36]);
- Ok(BSPNode {
+ Ok(BspNode {
plane_idx,
- value: BSPNodeValue::Children(Box::new(child_one), Box::new(child_two)),
+ value: BspNodeValue::Children(Box::new(child_one), Box::new(child_two)),
min,
max,
})
}
}
-impl<T: CoordSystem> HasBSPTree<T> for Q3BSPFile<T> {
- fn get_bsp_root(&self) -> &BSPNode {
+impl<T: CoordSystem> HasBspTree<T> for Q3BspFile<T> {
+ fn get_bsp_root(&self) -> &BspNode {
&self.tree_root
}
}
diff --git a/stockton-levels/src/q3/vertices.rs b/stockton-levels/src/q3/vertices.rs
index 107c34e..97cb28f 100644
--- a/stockton-levels/src/q3/vertices.rs
+++ b/stockton-levels/src/q3/vertices.rs
@@ -17,11 +17,11 @@
use std::convert::TryInto;
-use super::Q3BSPFile;
+use super::Q3BspFile;
use crate::coords::CoordSystem;
use crate::helpers::{slice_to_u32, slice_to_vec3};
use crate::traits::vertices::*;
-use crate::types::{ParseError, Result, RGBA};
+use crate::types::{ParseError, Result, Rgba};
/// The size of one vertex
const VERTEX_SIZE: usize = (4 * 3) + (2 * 2 * 4) + (4 * 3) + 4;
@@ -42,7 +42,7 @@ pub fn verts_from_data(data: &[u8]) -> Result<Box<[Vertex]>> {
position: slice_to_vec3(&vertex[0..12]),
tex: TexCoord::from_bytes(&vertex[12..28].try_into().unwrap()),
normal: slice_to_vec3(&vertex[28..40]),
- color: RGBA::from_slice(&vertex[40..44]),
+ color: Rgba::from_slice(&vertex[40..44]),
})
}
@@ -64,7 +64,7 @@ pub fn meshverts_from_data(data: &[u8]) -> Result<Box<[MeshVert]>> {
Ok(meshverts.into_boxed_slice())
}
-impl<T: CoordSystem> HasVertices<T> for Q3BSPFile<T> {
+impl<T: CoordSystem> HasVertices<T> for Q3BspFile<T> {
type VerticesIter<'a> = std::slice::Iter<'a, Vertex>;
fn vertices_iter(&self) -> Self::VerticesIter<'_> {
@@ -76,7 +76,7 @@ impl<T: CoordSystem> HasVertices<T> for Q3BSPFile<T> {
}
}
-impl<T: CoordSystem> HasMeshVerts<T> for Q3BSPFile<T> {
+impl<T: CoordSystem> HasMeshVerts<T> for Q3BspFile<T> {
type MeshVertsIter<'a> = std::slice::Iter<'a, MeshVert>;
fn meshverts_iter(&self) -> Self::MeshVertsIter<'_> {
diff --git a/stockton-levels/src/q3/visdata.rs b/stockton-levels/src/q3/visdata.rs
index d4cb645..992a25b 100644
--- a/stockton-levels/src/q3/visdata.rs
+++ b/stockton-levels/src/q3/visdata.rs
@@ -20,7 +20,7 @@
use bitvec::prelude::*;
use std::vec::IntoIter;
-use super::file::Q3BSPFile;
+use super::file::Q3BspFile;
use crate::coords::CoordSystem;
use crate::helpers::slice_to_i32;
use crate::traits::visdata::*;
@@ -49,7 +49,7 @@ pub fn from_data(data: &[u8]) -> Result<Box<[BitBox<Local, u8>]>> {
Ok(vecs.into_boxed_slice())
}
-impl<T: CoordSystem> HasVisData for Q3BSPFile<T> {
+impl<T: CoordSystem> HasVisData for Q3BspFile<T> {
type VisibleIterator = IntoIter<ClusterId>;
fn all_visible_from(&self, from: ClusterId) -> Self::VisibleIterator {