aboutsummaryrefslogtreecommitdiff
path: root/stockton-levels/src/traits
diff options
context:
space:
mode:
Diffstat (limited to 'stockton-levels/src/traits')
-rw-r--r--stockton-levels/src/traits/brushes.rs10
-rw-r--r--stockton-levels/src/traits/effects.rs10
-rw-r--r--stockton-levels/src/traits/entities.rs6
-rw-r--r--stockton-levels/src/traits/faces.rs28
-rw-r--r--stockton-levels/src/traits/light_maps.rs8
-rw-r--r--stockton-levels/src/traits/light_vols.rs10
-rw-r--r--stockton-levels/src/traits/models.rs10
-rw-r--r--stockton-levels/src/traits/planes.rs7
-rw-r--r--stockton-levels/src/traits/textures.rs6
-rw-r--r--stockton-levels/src/traits/tree.rs5
-rw-r--r--stockton-levels/src/traits/vertices.rs21
-rw-r--r--stockton-levels/src/traits/visdata.rs2
12 files changed, 65 insertions, 58 deletions
diff --git a/stockton-levels/src/traits/brushes.rs b/stockton-levels/src/traits/brushes.rs
index 0b07653..6131824 100644
--- a/stockton-levels/src/traits/brushes.rs
+++ b/stockton-levels/src/traits/brushes.rs
@@ -17,6 +17,8 @@
//! Parses the brushes & brushsides lumps from a bsp file
+use super::HasPlanes;
+
/// One brush record. Used for collision detection.
/// "Each brush describes a convex volume as defined by its surrounding surfaces."
#[derive(Debug, Clone, PartialEq)]
@@ -33,9 +35,9 @@ pub struct BrushSide {
pub is_opposing: bool,
}
-pub trait HasBrushes<'a> {
- type BrushesIter: Iterator<Item = &'a Brush>;
+pub trait HasBrushes: HasPlanes {
+ type BrushesIter<'a>: Iterator<Item = &'a Brush>;
- fn brushes_iter(&'a self) -> Self::BrushesIter;
- fn get_brush(&'a self, index: u32) -> &'a Brush;
+ fn brushes_iter<'a>(&'a self) -> Self::BrushesIter<'a>;
+ fn get_brush<'a>(&'a self, index: u32) -> &'a Brush;
}
diff --git a/stockton-levels/src/traits/effects.rs b/stockton-levels/src/traits/effects.rs
index c889ea7..d969dd1 100644
--- a/stockton-levels/src/traits/effects.rs
+++ b/stockton-levels/src/traits/effects.rs
@@ -15,6 +15,8 @@
// 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 super::HasBrushes;
+
/// One effect definition
#[derive(Debug, Clone, PartialEq)]
pub struct Effect {
@@ -27,9 +29,9 @@ pub struct Effect {
// todo: unknown: i32
}
-pub trait HasEffects<'a> {
- type EffectsIter: Iterator<Item = &'a Effect>;
+pub trait HasEffects: HasBrushes {
+ type EffectsIter<'a>: Iterator<Item = &'a Effect>;
- fn effects_iter(&'a self) -> Self::EffectsIter;
- fn get_effect(&'a self, index: u32) -> &'a Effect;
+ fn effects_iter<'a>(&'a self) -> Self::EffectsIter<'a>;
+ fn get_effect<'a>(&'a self, index: u32) -> &'a Effect;
}
diff --git a/stockton-levels/src/traits/entities.rs b/stockton-levels/src/traits/entities.rs
index 6a762e0..706f25a 100644
--- a/stockton-levels/src/traits/entities.rs
+++ b/stockton-levels/src/traits/entities.rs
@@ -22,8 +22,8 @@ pub struct Entity {
pub attributes: HashMap<String, String>,
}
-pub trait HasEntities<'a> {
- type EntitiesIter: Iterator<Item = &'a Entity>;
+pub trait HasEntities {
+ type EntitiesIter<'a>: Iterator<Item = &'a Entity>;
- fn entities_iter(&'a self) -> Self::EntitiesIter;
+ fn entities_iter<'a>(&'a self) -> Self::EntitiesIter<'a>;
} \ No newline at end of file
diff --git a/stockton-levels/src/traits/faces.rs b/stockton-levels/src/traits/faces.rs
index ff73c73..cb97877 100644
--- a/stockton-levels/src/traits/faces.rs
+++ b/stockton-levels/src/traits/faces.rs
@@ -15,9 +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};
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(i32)]
@@ -31,24 +32,25 @@ pub enum FaceType {
#[derive(Debug, Clone, PartialEq)]
pub struct Face {
pub face_type: FaceType,
- pub texture_idx: usize,
- pub effect_idx: Option<usize>,
- pub lightmap_idx: Option<usize>,
- pub vertices_idx: Range<usize>,
- pub meshverts_idx: Range<usize>,
+ pub texture_idx: u32,
+ pub effect_idx: Option<u32>,
+ pub lightmap_idx: Option<u32>,
+ pub vertices_idx: Range<u32>,
+ pub meshverts_idx: Range<u32>,
- pub map_start: Vector2<i32>,
- pub map_size: Vector2<i32>,
+ pub map_start: Vector2<u32>,
+ pub map_size: Vector2<u32>,
pub map_origin: Vector3<f32>,
pub map_vecs: [Vector3<f32>; 2],
pub normal: Vector3<f32>,
- pub size: Vector2<i32>,
+ pub size: Vector2<u32>,
}
-pub trait HasFaces<'a> {
- type FacesIter: Iterator<Item = &'a Face>;
+pub trait HasFaces: HasTextures + HasEffects + HasLightMaps + HasMeshVerts {
+ type FacesIter<'a>: Iterator<Item = &'a Face>;
- fn faces_iter(&'a self) -> Self::FacesIter;
- fn get_face(&'a self, index: u32) -> &'a Face;
+ fn faces_iter<'a>(&'a self) -> Self::FacesIter<'a>;
+ fn faces_len(&self) -> u32;
+ fn get_face<'a>(&'a self, index: u32) -> &'a Face;
}
diff --git a/stockton-levels/src/traits/light_maps.rs b/stockton-levels/src/traits/light_maps.rs
index 406746d..9b30d91 100644
--- a/stockton-levels/src/traits/light_maps.rs
+++ b/stockton-levels/src/traits/light_maps.rs
@@ -54,9 +54,9 @@ impl fmt::Debug for LightMap {
}
}
-pub trait HasLightMaps<'a> {
- type LightMapsIter: Iterator<Item = &'a LightMap>;
+pub trait HasLightMaps {
+ type LightMapsIter<'a>: Iterator<Item = &'a LightMap>;
- fn lightmaps_iter(&'a self) -> Self::LightMapsIter;
- fn get_lightmap(&'a self, index: u32) -> &'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
diff --git a/stockton-levels/src/traits/light_vols.rs b/stockton-levels/src/traits/light_vols.rs
index 027709a..8e75401 100644
--- a/stockton-levels/src/traits/light_vols.rs
+++ b/stockton-levels/src/traits/light_vols.rs
@@ -15,8 +15,6 @@
// 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::convert::TryInto;
-
use crate::types::RGB;
#[derive(Debug, Clone, Copy)]
@@ -26,9 +24,9 @@ pub struct LightVol {
pub dir: [u8; 2],
}
-pub trait HasLightVols<'a> {
- type LightVolsIter: Iterator<Item = &'a LightVol>;
+pub trait HasLightVols {
+ type LightVolsIter<'a>: Iterator<Item = &'a LightVol>;
- fn lightvols_iter(&'a self) -> Self::LightVolsIter;
- fn get_lightvol(&'a self, index: u32) -> &'a LightVol;
+ fn lightvols_iter<'a>(&'a self) -> Self::LightVolsIter<'a>;
+ fn get_lightvol<'a>(&'a self, index: u32) -> &'a LightVol;
}
diff --git a/stockton-levels/src/traits/models.rs b/stockton-levels/src/traits/models.rs
index ede7f78..7d1b896 100644
--- a/stockton-levels/src/traits/models.rs
+++ b/stockton-levels/src/traits/models.rs
@@ -18,6 +18,8 @@
use na::Vector3;
use std::ops::Range;
+use super::{HasFaces, HasBrushes};
+
#[derive(Debug, Clone)]
pub struct Model {
pub mins: Vector3<f32>,
@@ -26,9 +28,9 @@ pub struct Model {
pub brushes_idx: Range<u32>,
}
-pub trait HasModels<'a> {
- type ModelsIter: Iterator<Item = &'a Model>;
+pub trait HasModels: HasFaces + HasBrushes {
+ type ModelsIter<'a>: Iterator<Item = &'a Model>;
- fn models_iter(&'a self) -> Self::ModelsIter;
- fn get_model(&'a self, index: u32) -> &'a Model;
+ fn models_iter<'a>(&'a self) -> Self::ModelsIter<'a>;
+ fn get_model<'a>(&'a self, index: u32) -> &'a Model;
}
diff --git a/stockton-levels/src/traits/planes.rs b/stockton-levels/src/traits/planes.rs
index 6962c71..6a4e95a 100644
--- a/stockton-levels/src/traits/planes.rs
+++ b/stockton-levels/src/traits/planes.rs
@@ -35,8 +35,9 @@ pub struct Plane {
pub dist: f32,
}
-pub trait HasPlanes<'a> {
- type PlanesIter: Iterator<Item = &'a Plane>;
+pub trait HasPlanes {
+ type PlanesIter<'a>: Iterator<Item = &'a Plane>;
- fn planes_iter(&'a self) -> Self::PlanesIter;
+ 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
diff --git a/stockton-levels/src/traits/textures.rs b/stockton-levels/src/traits/textures.rs
index d1a2a83..ffd2a2f 100644
--- a/stockton-levels/src/traits/textures.rs
+++ b/stockton-levels/src/traits/textures.rs
@@ -142,8 +142,8 @@ bitflags!(
}
);
-pub trait HasTextures<'a> {
- type TexturesIter: Iterator<Item = &'a Texture>;
+pub trait HasTextures {
+ type TexturesIter<'a>: Iterator<Item = &'a Texture>;
- fn textures_iter(&'a self) -> Self::TexturesIter;
+ fn textures_iter<'a>(&'a self) -> Self::TexturesIter<'a>;
}
diff --git a/stockton-levels/src/traits/tree.rs b/stockton-levels/src/traits/tree.rs
index 06cfd80..bdbe705 100644
--- a/stockton-levels/src/traits/tree.rs
+++ b/stockton-levels/src/traits/tree.rs
@@ -18,6 +18,7 @@
//! Parses the BSP tree into a usable format
use na::Vector3;
+use super::{HasFaces, HasBrushes, HasVisData};
/// A node in a BSP tree.
/// Either has two children *or* a leaf entry.
@@ -45,6 +46,6 @@ pub struct BSPLeaf {
pub brushes_idx: Box<[u32]>,
}
-pub trait HasBSPTree<'a> {
- fn get_bsp_root(&'a self) -> &'a BSPNode;
+pub trait HasBSPTree: HasFaces + HasBrushes + HasVisData {
+ fn get_bsp_root<'a>(&'a self) -> &'a BSPNode;
} \ No newline at end of file
diff --git a/stockton-levels/src/traits/vertices.rs b/stockton-levels/src/traits/vertices.rs
index cb06b3a..2afa802 100644
--- a/stockton-levels/src/traits/vertices.rs
+++ b/stockton-levels/src/traits/vertices.rs
@@ -18,7 +18,6 @@
use crate::helpers::{slice_to_f32};
use crate::types::RGBA;
use na::Vector3;
-use std::convert::TryInto;
/// A vertex, used to describe a face.
@@ -49,22 +48,22 @@ impl TexCoord {
}
/// A vertex offset, used to describe generalised triangle meshes
-pub type MeshVert = i32;
+pub type MeshVert = u32;
-pub trait HasVertices<'a> {
- type VerticesIter: Iterator<Item = &'a Vertex>;
+pub trait HasVertices {
+ type VerticesIter<'a>: Iterator<Item = &'a Vertex>;
- fn vertices_iter(&'a self) -> Self::VerticesIter;
- fn get_vertex(&'a self, index: u32) -> &'a Vertex;
+ fn vertices_iter<'a>(&'a self) -> Self::VerticesIter<'a>;
+ fn get_vertex<'a>(&'a self, index: u32) -> &'a Vertex;
}
-pub trait HasMeshVerts<'a>: HasVertices<'a> {
- type MeshVertsIter: Iterator<Item = &'a MeshVert>;
+pub trait HasMeshVerts: HasVertices {
+ type MeshVertsIter<'a>: Iterator<Item = &'a MeshVert>;
- fn meshverts_iter(&'a self) -> Self::MeshVertsIter;
+ fn meshverts_iter<'a>(&'a self) -> Self::MeshVertsIter<'a>;
fn get_meshvert(&self, index: u32) -> MeshVert;
- fn resolve_meshvert(&'a self, index: u32) -> &'a Vertex {
- self.get_vertex(self.get_meshvert(index).try_into().unwrap())
+ fn resolve_meshvert<'a>(&'a self, index: u32, base: u32) -> &'a 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 27849d3..92ba9b8 100644
--- a/stockton-levels/src/traits/visdata.rs
+++ b/stockton-levels/src/traits/visdata.rs
@@ -22,7 +22,7 @@ pub trait HasVisData {
type VisibleIterator: Iterator<Item = ClusterId>;
/// Returns an iterator of all clusters visible from the given Cluster ID
- fn all_visible_from<'a>(&'a self, from: ClusterId) -> Self::VisibleIterator;
+ 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;