diff options
Diffstat (limited to 'stockton-levels')
22 files changed, 92 insertions, 88 deletions
diff --git a/stockton-levels/src/features.rs b/stockton-levels/src/features.rs index f9e6455..0034831 100644 --- a/stockton-levels/src/features.rs +++ b/stockton-levels/src/features.rs @@ -32,5 +32,5 @@ use crate::coords::CoordSystem; use crate::traits::*; -pub trait MinBSPFeatures<S: CoordSystem>: HasBSPTree<S> + Send + Sync {} -impl<T, S: CoordSystem> MinBSPFeatures<S> for T where T: HasBSPTree<S> + Send + Sync {} +pub trait MinBspFeatures<S: CoordSystem>: HasBspTree<S> + Send + Sync {} +impl<T, S: CoordSystem> MinBspFeatures<S> for T where T: HasBspTree<S> + Send + Sync {} 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 { diff --git a/stockton-levels/src/traits/light_maps.rs b/stockton-levels/src/traits/light_maps.rs index 50ec84d..cc7fa70 100644 --- a/stockton-levels/src/traits/light_maps.rs +++ b/stockton-levels/src/traits/light_maps.rs @@ -17,12 +17,12 @@ use std::fmt; -use crate::types::RGB; +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], + pub map: [[Rgb; 128]; 128], } impl PartialEq for LightMap { diff --git a/stockton-levels/src/traits/light_vols.rs b/stockton-levels/src/traits/light_vols.rs index 48972ef..016ddab 100644 --- a/stockton-levels/src/traits/light_vols.rs +++ b/stockton-levels/src/traits/light_vols.rs @@ -15,12 +15,12 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -use crate::types::RGB; +use crate::types::Rgb; #[derive(Debug, Clone, Copy)] pub struct LightVol { - pub ambient: RGB, - pub directional: RGB, + pub ambient: Rgb, + pub directional: Rgb, pub dir: [u8; 2], } diff --git a/stockton-levels/src/traits/mod.rs b/stockton-levels/src/traits/mod.rs index c65cde8..00d129f 100644 --- a/stockton-levels/src/traits/mod.rs +++ b/stockton-levels/src/traits/mod.rs @@ -39,6 +39,6 @@ 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::tree::HasBspTree; pub use self::vertices::{HasMeshVerts, HasVertices}; pub use self::visdata::HasVisData; diff --git a/stockton-levels/src/traits/textures.rs b/stockton-levels/src/traits/textures.rs index 4477fba..66c120c 100644 --- a/stockton-levels/src/traits/textures.rs +++ b/stockton-levels/src/traits/textures.rs @@ -160,5 +160,5 @@ pub trait HasTextures { type TexturesIter<'a>: Iterator<Item = &'a Texture>; fn textures_iter(&self) -> Self::TexturesIter<'_>; - fn get_texture(&self, idx: u32) -> &Texture; + fn get_texture(&self, idx: u32) -> Option<&Texture>; } diff --git a/stockton-levels/src/traits/tree.rs b/stockton-levels/src/traits/tree.rs index 253ae1b..5ca0d59 100644 --- a/stockton-levels/src/traits/tree.rs +++ b/stockton-levels/src/traits/tree.rs @@ -24,29 +24,29 @@ use na::Vector3; /// A node in a BSP tree. /// Either has two children *or* a leaf entry. #[derive(Debug, Clone)] -pub struct BSPNode { +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>), +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 struct BspLeaf { pub cluster_id: u32, pub area: i32, pub faces_idx: Box<[u32]>, pub brushes_idx: Box<[u32]>, } -pub trait HasBSPTree<S: CoordSystem>: HasFaces<S> + HasBrushes<S> + HasVisData { - fn get_bsp_root(&self) -> &BSPNode; +pub trait HasBspTree<S: CoordSystem>: HasFaces<S> + HasBrushes<S> + HasVisData { + fn get_bsp_root(&self) -> &BspNode; } diff --git a/stockton-levels/src/traits/vertices.rs b/stockton-levels/src/traits/vertices.rs index ff23785..44c3000 100644 --- a/stockton-levels/src/traits/vertices.rs +++ b/stockton-levels/src/traits/vertices.rs @@ -17,7 +17,7 @@ use crate::coords::CoordSystem; use crate::helpers::slice_to_f32; -use crate::types::RGBA; +use crate::types::Rgba; use na::Vector3; /// A vertex, used to describe a face. @@ -26,7 +26,7 @@ pub struct Vertex { pub position: Vector3<f32>, pub tex: TexCoord, pub normal: Vector3<f32>, - pub color: RGBA, + pub color: Rgba, } /// Represents a TexCoord. 0 = surface, 1= lightmap. diff --git a/stockton-levels/src/types.rs b/stockton-levels/src/types.rs index fa90398..4af0725 100644 --- a/stockton-levels/src/types.rs +++ b/stockton-levels/src/types.rs @@ -21,17 +21,17 @@ use std::convert::TryInto; /// RGBA Colour (0-255) #[derive(Debug, Clone, Copy, PartialEq)] -pub struct RGBA { +pub struct Rgba { pub r: u8, pub g: u8, pub b: u8, pub a: u8, } -impl RGBA { +impl Rgba { /// Interpret the given bytes as an RGBA colour. - pub fn from_bytes(bytes: [u8; 4]) -> RGBA { - RGBA { + pub fn from_bytes(bytes: [u8; 4]) -> Rgba { + Rgba { r: bytes[0], g: bytes[1], b: bytes[2], @@ -42,23 +42,23 @@ impl RGBA { /// Convert a slice to an RGBA colour /// # Panics /// If slice is not 4 bytes long. - pub fn from_slice(slice: &[u8]) -> RGBA { - RGBA::from_bytes(slice.try_into().unwrap()) + pub fn from_slice(slice: &[u8]) -> Rgba { + Rgba::from_bytes(slice.try_into().unwrap()) } } /// RGB Colour (0-255) #[derive(Debug, Clone, Copy, PartialEq)] -pub struct RGB { +pub struct Rgb { pub r: u8, pub g: u8, pub b: u8, } -impl RGB { +impl Rgb { /// 255, 255, 255 - pub fn white() -> RGB { - RGB { + pub fn white() -> Rgb { + Rgb { r: 255, g: 255, b: 255, @@ -66,8 +66,8 @@ impl RGB { } /// Interpret the given bytes as an RGB colour. - pub fn from_bytes(bytes: [u8; 3]) -> RGB { - RGB { + pub fn from_bytes(bytes: [u8; 3]) -> Rgb { + Rgb { r: bytes[0], g: bytes[1], b: bytes[2], @@ -77,8 +77,8 @@ impl RGB { /// Convert a slice to an RGB colour /// # Panics /// If slice is not 3 bytes long. - pub fn from_slice(slice: &[u8]) -> RGB { - RGB::from_bytes(slice.try_into().unwrap()) + pub fn from_slice(slice: &[u8]) -> Rgb { + Rgb::from_bytes(slice.try_into().unwrap()) } } |