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.rs41
-rw-r--r--stockton-levels/src/traits/effects.rs35
-rw-r--r--stockton-levels/src/traits/entities.rs29
-rw-r--r--stockton-levels/src/traits/faces.rs54
-rw-r--r--stockton-levels/src/traits/light_maps.rs62
-rw-r--r--stockton-levels/src/traits/light_vols.rs34
-rw-r--r--stockton-levels/src/traits/mod.rs41
-rw-r--r--stockton-levels/src/traits/models.rs34
-rw-r--r--stockton-levels/src/traits/planes.rs42
-rw-r--r--stockton-levels/src/traits/textures.rs149
-rw-r--r--stockton-levels/src/traits/tree.rs50
-rw-r--r--stockton-levels/src/traits/vertices.rs70
-rw-r--r--stockton-levels/src/traits/visdata.rs29
13 files changed, 670 insertions, 0 deletions
diff --git a/stockton-levels/src/traits/brushes.rs b/stockton-levels/src/traits/brushes.rs
new file mode 100644
index 0000000..0b07653
--- /dev/null
+++ b/stockton-levels/src/traits/brushes.rs
@@ -0,0 +1,41 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of stockton-bsp.
+//
+// stockton-bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// stockton-bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with stockton-bsp. If not, see <http://www.gnu.org/licenses/>.
+
+//! Parses the brushes & brushsides lumps from a bsp file
+
+/// One brush record. Used for collision detection.
+/// "Each brush describes a convex volume as defined by its surrounding surfaces."
+#[derive(Debug, Clone, PartialEq)]
+pub struct Brush {
+ pub sides: Box<[BrushSide]>,
+ pub texture_idx: usize,
+}
+
+/// Bounding surface for brush.
+#[derive(Debug, Clone, PartialEq)]
+pub struct BrushSide {
+ pub plane_idx: usize,
+ pub texture_idx: usize,
+ pub is_opposing: bool,
+}
+
+pub trait HasBrushes<'a> {
+ type BrushesIter: Iterator<Item = &'a Brush>;
+
+ fn brushes_iter(&'a self) -> Self::BrushesIter;
+ fn get_brush(&'a self, index: u32) -> &'a Brush;
+}
diff --git a/stockton-levels/src/traits/effects.rs b/stockton-levels/src/traits/effects.rs
new file mode 100644
index 0000000..c889ea7
--- /dev/null
+++ b/stockton-levels/src/traits/effects.rs
@@ -0,0 +1,35 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of stockton-bsp.
+//
+// stockton-bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// stockton-bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with stockton-bsp. If not, see <http://www.gnu.org/licenses/>.
+
+/// One effect definition
+#[derive(Debug, Clone, PartialEq)]
+pub struct Effect {
+ /// The name of the effect - always 64 characters long
+ pub name: String,
+
+ /// The brush used for this effect
+ pub brush_idx: u32
+
+ // todo: unknown: i32
+}
+
+pub trait HasEffects<'a> {
+ type EffectsIter: Iterator<Item = &'a Effect>;
+
+ fn effects_iter(&'a self) -> Self::EffectsIter;
+ fn get_effect(&'a self, index: u32) -> &'a Effect;
+}
diff --git a/stockton-levels/src/traits/entities.rs b/stockton-levels/src/traits/entities.rs
new file mode 100644
index 0000000..6a762e0
--- /dev/null
+++ b/stockton-levels/src/traits/entities.rs
@@ -0,0 +1,29 @@
+// 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
+// Software Foundation, either version 3 of the License, or (at your option)
+// any later version.
+
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+
+// 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;
+
+#[derive(Debug, Clone, PartialEq)]
+/// A game entity
+pub struct Entity {
+ pub attributes: HashMap<String, String>,
+}
+
+pub trait HasEntities<'a> {
+ type EntitiesIter: Iterator<Item = &'a Entity>;
+
+ fn entities_iter(&'a self) -> Self::EntitiesIter;
+} \ No newline at end of file
diff --git a/stockton-levels/src/traits/faces.rs b/stockton-levels/src/traits/faces.rs
new file mode 100644
index 0000000..ff73c73
--- /dev/null
+++ b/stockton-levels/src/traits/faces.rs
@@ -0,0 +1,54 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of stockton-bsp.
+//
+// stockton-bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// stockton-bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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 na::{Vector2, Vector3};
+
+use std::ops::Range;
+
+#[derive(Debug, Clone, Copy, PartialEq)]
+#[repr(i32)]
+pub enum FaceType {
+ Polygon = 1,
+ Patch = 2,
+ Mesh = 3,
+ Billboard = 4,
+}
+
+#[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 map_start: Vector2<i32>,
+ pub map_size: Vector2<i32>,
+ pub map_origin: Vector3<f32>,
+ pub map_vecs: [Vector3<f32>; 2],
+
+ pub normal: Vector3<f32>,
+ pub size: Vector2<i32>,
+}
+
+pub trait HasFaces<'a> {
+ type FacesIter: Iterator<Item = &'a Face>;
+
+ fn faces_iter(&'a self) -> Self::FacesIter;
+ fn get_face(&'a self, index: u32) -> &'a Face;
+}
diff --git a/stockton-levels/src/traits/light_maps.rs b/stockton-levels/src/traits/light_maps.rs
new file mode 100644
index 0000000..406746d
--- /dev/null
+++ b/stockton-levels/src/traits/light_maps.rs
@@ -0,0 +1,62 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of stockton-bsp.
+//
+// stockton-bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// stockton-bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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::fmt;
+
+use crate::types::RGB;
+
+/// Stores light map textures that help make surface lighting more realistic
+#[derive(Clone)]
+pub struct LightMap {
+ pub map: [[RGB; 128]; 128],
+}
+
+impl PartialEq for LightMap {
+ fn eq(&self, other: &LightMap) -> bool {
+ for x in 0..128 {
+ for y in 0..128 {
+ if self.map[x][y] != other.map[x][y] {
+ return false;
+ }
+ }
+ }
+ true
+ }
+}
+
+impl fmt::Debug for LightMap {
+ // rust can't derive debug for 3d arrays so done manually
+ // \_( )_/
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "LightMap {{ map: [")?;
+ for c in self.map.iter() {
+ write!(f, "[")?;
+ for x in c.iter() {
+ write!(f, "{:?}, ", x)?;
+ }
+ write!(f, "], ")?;
+ }
+ write!(f, "}}")
+ }
+}
+
+pub trait HasLightMaps<'a> {
+ type LightMapsIter: Iterator<Item = &'a LightMap>;
+
+ fn lightmaps_iter(&'a self) -> Self::LightMapsIter;
+ fn get_lightmap(&'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
new file mode 100644
index 0000000..027709a
--- /dev/null
+++ b/stockton-levels/src/traits/light_vols.rs
@@ -0,0 +1,34 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of stockton-bsp.
+//
+// stockton-bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// stockton-bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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)]
+pub struct LightVol {
+ pub ambient: RGB,
+ pub directional: RGB,
+ pub dir: [u8; 2],
+}
+
+pub trait HasLightVols<'a> {
+ type LightVolsIter: Iterator<Item = &'a LightVol>;
+
+ fn lightvols_iter(&'a self) -> Self::LightVolsIter;
+ fn get_lightvol(&'a self, index: u32) -> &'a LightVol;
+}
diff --git a/stockton-levels/src/traits/mod.rs b/stockton-levels/src/traits/mod.rs
new file mode 100644
index 0000000..15bac30
--- /dev/null
+++ b/stockton-levels/src/traits/mod.rs
@@ -0,0 +1,41 @@
+// 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
+// Software Foundation, either version 3 of the License, or (at your option)
+// any later version.
+
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+
+// You should have received a copy of the GNU General Public License along
+// 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 faces;
+pub mod tree;
+pub mod models;
+
+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::faces::HasFaces;
+pub use self::tree::HasBSPTree;
+pub use self::models::HasModels; \ No newline at end of file
diff --git a/stockton-levels/src/traits/models.rs b/stockton-levels/src/traits/models.rs
new file mode 100644
index 0000000..ede7f78
--- /dev/null
+++ b/stockton-levels/src/traits/models.rs
@@ -0,0 +1,34 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of stockton-bsp.
+//
+// stockton-bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// stockton-bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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 na::Vector3;
+use std::ops::Range;
+
+#[derive(Debug, Clone)]
+pub struct Model {
+ pub mins: Vector3<f32>,
+ pub maxs: Vector3<f32>,
+ pub faces_idx: Range<u32>,
+ pub brushes_idx: Range<u32>,
+}
+
+pub trait HasModels<'a> {
+ type ModelsIter: Iterator<Item = &'a Model>;
+
+ fn models_iter(&'a self) -> Self::ModelsIter;
+ fn get_model(&'a self, index: u32) -> &'a Model;
+}
diff --git a/stockton-levels/src/traits/planes.rs b/stockton-levels/src/traits/planes.rs
new file mode 100644
index 0000000..6962c71
--- /dev/null
+++ b/stockton-levels/src/traits/planes.rs
@@ -0,0 +1,42 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of stockton-bsp.
+//
+// rust-bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// rust-bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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;
+
+/// The planes lump from a BSP file.
+/// Found at lump index 2 in a q3 bsp.
+#[derive(Debug, Clone)]
+pub struct PlanesLump {
+ pub planes: Box<[Plane]>,
+}
+
+/// Generic plane, referenced by nodes & brushsizes
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct Plane {
+ /// Plane normal
+ pub normal: Vector3<f32>,
+
+ /// Distance from origin to plane along normal
+ pub dist: f32,
+}
+
+pub trait HasPlanes<'a> {
+ type PlanesIter: Iterator<Item = &'a Plane>;
+
+ fn planes_iter(&'a self) -> Self::PlanesIter;
+} \ No newline at end of file
diff --git a/stockton-levels/src/traits/textures.rs b/stockton-levels/src/traits/textures.rs
new file mode 100644
index 0000000..d1a2a83
--- /dev/null
+++ b/stockton-levels/src/traits/textures.rs
@@ -0,0 +1,149 @@
+// 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
+// Software Foundation, either version 3 of the License, or (at your option)
+// any later version.
+
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+
+// 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;
+
+#[derive(Debug, Clone, PartialEq)]
+/// A texture from a BSP File.
+pub struct Texture {
+ pub name: String,
+ pub surface: SurfaceFlags,
+ 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
+ const NO_IMPACT = 0x10;
+
+ /// function as a ladder
+ const LADDER = 0x8;
+
+ /// 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;
+ }
+);
+
+bitflags!(
+ /// Extracted from the Q3 arena engine code. Less documented than `SurfaceFlags`.
+ /// https://github.com/id-Software/Quake-III-Arena/blob/master/code/game/surfaceflags.h
+ pub struct ContentsFlags: u32 {
+ // an eye is never valid in a solid
+ const SOLID = 0x1;
+ const LAVA = 0x8;
+ const SLIME = 0x10;
+ const WATER = 0x20;
+ const FOG = 0x40;
+
+ const NOT_TEAM1 = 0x00_80;
+ const NOT_TEAM2 = 0x01_00;
+ const NOT_BOT_CLIP = 0x02_00;
+
+ const AREA_PORTAL = 0x80_00;
+
+ /// bot specific contents type
+ const PLAYER_CLIP = 0x01_00_00;
+
+ /// bot specific contents type
+ const MONSTER_CLIP = 0x02_00_00;
+
+ const TELEPORTER = 0x04_00_00;
+ const JUMP_PAD = 0x08_00_00;
+ const CLUSTER_PORTAL = 0x10_00_00;
+ 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;
+
+ // should never be on a brush, only in game
+ const BODY = 0x02_00_00_00;
+
+ /// 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;
+ }
+);
+
+pub trait HasTextures<'a> {
+ type TexturesIter: Iterator<Item = &'a Texture>;
+
+ fn textures_iter(&'a self) -> Self::TexturesIter;
+}
diff --git a/stockton-levels/src/traits/tree.rs b/stockton-levels/src/traits/tree.rs
new file mode 100644
index 0000000..06cfd80
--- /dev/null
+++ b/stockton-levels/src/traits/tree.rs
@@ -0,0 +1,50 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of rust_bsp.
+//
+// rust_bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// rust_bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with rust_bsp. If not, see <http://www.gnu.org/licenses/>.
+
+//! Parses the BSP tree into a usable format
+
+use na::Vector3;
+
+/// A node in a BSP tree.
+/// Either has two children *or* a leaf entry.
+#[derive(Debug, Clone)]
+pub struct BSPNode {
+ pub plane_idx: u32,
+ pub min: Vector3<i32>,
+ pub max: Vector3<i32>,
+ pub value: BSPNodeValue
+}
+
+#[derive(Debug, Clone)]
+pub enum BSPNodeValue {
+ Leaf (BSPLeaf),
+ Children (Box<BSPNode>, Box<BSPNode>)
+}
+
+/// A leaf in a BSP tree.
+/// Will be under a `BSPNode`, min and max values are stored there.
+#[derive(Debug, Clone)]
+pub struct BSPLeaf {
+ pub cluster_id: u32,
+ pub area: i32,
+ pub faces_idx: Box<[u32]>,
+ pub brushes_idx: Box<[u32]>,
+}
+
+pub trait HasBSPTree<'a> {
+ fn get_bsp_root(&'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
new file mode 100644
index 0000000..cb06b3a
--- /dev/null
+++ b/stockton-levels/src/traits/vertices.rs
@@ -0,0 +1,70 @@
+// Copyright (C) 2019 Oscar Shrimpton
+//
+// This file is part of stockton-bsp.
+//
+// stockton-bsp 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 Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// stockton-bsp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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::types::RGBA;
+use na::Vector3;
+use std::convert::TryInto;
+
+
+/// A vertex, used to describe a face.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct Vertex {
+ pub position: Vector3<f32>,
+ pub tex: TexCoord,
+ pub normal: Vector3<f32>,
+ pub color: RGBA,
+}
+
+/// Represents a TexCoord. 0 = surface, 1= lightmap.
+/// This could also be written as [[f32; 2]; 2]
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct TexCoord {
+ pub u: [f32; 2],
+ pub v: [f32; 2],
+}
+
+impl TexCoord {
+ /// Internal function. Converts a slice to a TexCoord.
+ pub fn from_bytes(bytes: &[u8; 16]) -> TexCoord {
+ TexCoord {
+ u: [slice_to_f32(&bytes[0..4]), slice_to_f32(&bytes[4..8])],
+ v: [slice_to_f32(&bytes[8..12]), slice_to_f32(&bytes[12..16])],
+ }
+ }
+}
+
+/// A vertex offset, used to describe generalised triangle meshes
+pub type MeshVert = i32;
+
+pub trait HasVertices<'a> {
+ type VerticesIter: Iterator<Item = &'a Vertex>;
+
+ fn vertices_iter(&'a self) -> Self::VerticesIter;
+ fn get_vertex(&'a self, index: u32) -> &'a Vertex;
+}
+
+pub trait HasMeshVerts<'a>: HasVertices<'a> {
+ type MeshVertsIter: Iterator<Item = &'a MeshVert>;
+
+ fn meshverts_iter(&'a self) -> Self::MeshVertsIter;
+ 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())
+ }
+} \ No newline at end of file
diff --git a/stockton-levels/src/traits/visdata.rs b/stockton-levels/src/traits/visdata.rs
new file mode 100644
index 0000000..27849d3
--- /dev/null
+++ b/stockton-levels/src/traits/visdata.rs
@@ -0,0 +1,29 @@
+// 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
+// Software Foundation, either version 3 of the License, or (at your option)
+// any later version.
+
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+
+// 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;
+
+pub type ClusterId = u32;
+
+pub trait HasVisData {
+ /// 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<'a>(&'a 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