diff options
Diffstat (limited to 'stockton-levels')
-rw-r--r-- | stockton-levels/Cargo.toml | 14 | ||||
-rw-r--r-- | stockton-levels/src/features.rs | 21 | ||||
-rw-r--r-- | stockton-levels/src/lib.rs | 20 | ||||
-rw-r--r-- | stockton-levels/src/parts/entities.rs | 36 | ||||
-rw-r--r-- | stockton-levels/src/parts/faces.rs | 43 | ||||
-rw-r--r-- | stockton-levels/src/parts/mod.rs | 17 | ||||
-rw-r--r-- | stockton-levels/src/parts/textures.rs | 83 | ||||
-rw-r--r-- | stockton-levels/src/parts/vertices.rs | 155 | ||||
-rw-r--r-- | stockton-levels/src/parts/visdata.rs | 8 | ||||
-rw-r--r-- | stockton-levels/src/prelude.rs | 16 | ||||
-rw-r--r-- | stockton-levels/src/types.rs | 67 |
11 files changed, 0 insertions, 480 deletions
diff --git a/stockton-levels/Cargo.toml b/stockton-levels/Cargo.toml deleted file mode 100644 index 448a8ba..0000000 --- a/stockton-levels/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "stockton-levels" -version = "0.1.0" -authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] -description = "Traits relating to levels renderable by stockton." -repository = "https://github.com/tcmal/stockton" -homepage = "https://github.com/tcmal/stockton" -edition = "2018" - -[dependencies] -nalgebra = "^0.20" -serde = { version = "1.0", features = ["derive"] } -stockton-skeleton = { path = "../stockton-skeleton" } -image = "0.23.11" diff --git a/stockton-levels/src/features.rs b/stockton-levels/src/features.rs deleted file mode 100644 index b4ddb99..0000000 --- a/stockton-levels/src/features.rs +++ /dev/null @@ -1,21 +0,0 @@ -// 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/>. -//! Marker traits for different feature sets - -use crate::parts::*; - -pub trait MinRenderFeatures<'a>: HasFaces + HasTextures + HasVisData<'a> + Send + Sync {} -impl<'a, T> MinRenderFeatures<'a> for T where - T: HasFaces + HasTextures + HasVisData<'a> + Send + Sync -{ -} diff --git a/stockton-levels/src/lib.rs b/stockton-levels/src/lib.rs deleted file mode 100644 index 49609c2..0000000 --- a/stockton-levels/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -// 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/>. -//! Interfaces & Data structures stockton expects when rendering a level. - -extern crate nalgebra as na; - -pub mod features; -pub mod parts; -pub mod prelude; -pub mod types; diff --git a/stockton-levels/src/parts/entities.rs b/stockton-levels/src/parts/entities.rs deleted file mode 100644 index 7a5ac74..0000000 --- a/stockton-levels/src/parts/entities.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::iter::Iterator; - -pub type EntityRef = u32; - -/// A game entity -pub trait IsEntity<C: HasEntities + ?Sized> { - fn get_attr(&self, container: &C) -> Option<&str>; -} - -pub trait HasEntities { - type Entity: IsEntity<Self>; - - fn get_entity(&self, idx: EntityRef) -> Option<&Self::Entity>; - fn iter_entities(&self) -> Entities<Self> { - Entities { - next: 0, - container: self, - } - } -} - -#[derive(Debug, Clone, Copy)] -pub struct Entities<'a, T: HasEntities + ?Sized> { - next: EntityRef, - container: &'a T, -} - -impl<'a, T: HasEntities> Iterator for Entities<'a, T> { - type Item = &'a T::Entity; - - fn next(&mut self) -> Option<Self::Item> { - let res = self.container.get_entity(self.next); - self.next += 1; - res - } -} diff --git a/stockton-levels/src/parts/faces.rs b/stockton-levels/src/parts/faces.rs deleted file mode 100644 index 1023af7..0000000 --- a/stockton-levels/src/parts/faces.rs +++ /dev/null @@ -1,43 +0,0 @@ -use super::{textures::TextureRef, vertices::Vertex}; -use serde::{Deserialize, Serialize}; - -pub type FaceRef = u32; - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub enum Geometry { - Vertices(Vertex, Vertex, Vertex), -} - -pub trait IsFace<C: HasFaces + ?Sized> { - fn index(&self, container: &C) -> FaceRef; - fn geometry(&self, container: &C) -> Geometry; - fn texture_idx(&self, container: &C) -> TextureRef; -} - -pub trait HasFaces { - type Face: IsFace<Self>; - - fn get_face(&self, index: FaceRef) -> Option<&Self::Face>; - fn iter_faces(&self) -> Faces<Self> { - Faces { - next: 0, - container: self, - } - } -} - -#[derive(Debug, Clone, Copy)] -pub struct Faces<'a, T: HasFaces + ?Sized> { - next: FaceRef, - container: &'a T, -} - -impl<'a, T: HasFaces> Iterator for Faces<'a, T> { - type Item = &'a T::Face; - - fn next(&mut self) -> Option<Self::Item> { - let res = self.container.get_face(self.next); - self.next += 1; - res - } -} diff --git a/stockton-levels/src/parts/mod.rs b/stockton-levels/src/parts/mod.rs deleted file mode 100644 index d164bc3..0000000 --- a/stockton-levels/src/parts/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -mod entities; -mod faces; -mod textures; -mod vertices; -mod visdata; - -pub mod data { - pub use super::entities::{Entities, EntityRef}; - pub use super::faces::{FaceRef, Faces, Geometry}; - pub use super::textures::{TextureRef, Textures}; - pub use super::vertices::{Vertex, VertexRef}; -} - -pub use entities::{HasEntities, IsEntity}; -pub use faces::{HasFaces, IsFace}; -pub use textures::{HasTextures, IsTexture, FsResolver}; -pub use visdata::HasVisData; diff --git a/stockton-levels/src/parts/textures.rs b/stockton-levels/src/parts/textures.rs deleted file mode 100644 index ae946fd..0000000 --- a/stockton-levels/src/parts/textures.rs +++ /dev/null @@ -1,83 +0,0 @@ -// 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, path::Path, sync::{Arc, RwLock}}; -use image::{RgbaImage, io::Reader}; -use stockton_skeleton::texture::TextureResolver; - -pub type TextureRef = u32; - -pub trait IsTexture { - fn name(&self) -> &str; -} - -pub trait HasTextures { - type Texture: IsTexture; - - fn get_texture(&self, idx: TextureRef) -> Option<&Self::Texture>; - fn iter_textures(&self) -> Textures<Self> { - Textures { - next: 0, - container: self, - } - } -} - -#[derive(Debug, Clone, Copy)] -pub struct Textures<'a, T: HasTextures + ?Sized> { - next: TextureRef, - container: &'a T, -} - -impl<'a, T: HasTextures> Iterator for Textures<'a, T> { - type Item = &'a T::Texture; - - fn next(&mut self) -> Option<Self::Item> { - let res = self.container.get_texture(self.next); - self.next += 1; - res - } -} - - -/// A basic filesystem resolver which gets the texture name from any HasTextures Object. -pub struct FsResolver<'a, T: HasTextures> { - path: &'a Path, - map_lock: Arc<RwLock<T>>, -} - -impl<'a, T: HasTextures> FsResolver<'a, T> { - pub fn new(path: &'a Path, map_lock: Arc<RwLock<T>>) -> Self { - FsResolver { path, map_lock } - } -} - -impl<'a, T: HasTextures> TextureResolver for FsResolver<'a, T> { - type Image = RgbaImage; - - fn resolve(&mut self, tex: u32) -> Option<Self::Image> { - let map = self.map_lock.read().unwrap(); - let tex = map.get_texture(tex)?; - let path = self.path.join(&tex.name()); - - if let Ok(file) = Reader::open(path) { - if let Ok(guessed) = file.with_guessed_format() { - if let Ok(decoded) = guessed.decode() { - return Some(decoded.into_rgba8()); - } - } - } - - None - } -} diff --git a/stockton-levels/src/parts/vertices.rs b/stockton-levels/src/parts/vertices.rs deleted file mode 100644 index d797afd..0000000 --- a/stockton-levels/src/parts/vertices.rs +++ /dev/null @@ -1,155 +0,0 @@ -use crate::types::Rgba; -use na::{Vector2, Vector3}; -use serde::de; -use serde::de::{Deserializer, MapAccess, SeqAccess, Visitor}; -use serde::ser::{Serialize, SerializeStruct, Serializer}; -use serde::Deserialize; -use std::fmt; - -pub type VertexRef = u32; - -/// A vertex, used to describe a face. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Vertex { - pub position: Vector3<f32>, - pub tex: Vector2<f32>, - pub color: Rgba, -} - -impl Serialize for Vertex { - fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { - let mut state = serializer.serialize_struct("Vertex", 5)?; - state.serialize_field("pos_x", &self.position.x)?; - state.serialize_field("pos_y", &self.position.y)?; - state.serialize_field("pos_z", &self.position.z)?; - state.serialize_field("tex_u", &self.tex.x)?; - state.serialize_field("tex_v", &self.tex.y)?; - state.serialize_field("color", &self.color)?; - - state.end() - } -} - -impl<'de> Deserialize<'de> for Vertex { - fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { - #[derive(Deserialize)] - #[serde(field_identifier, rename_all = "snake_case")] - enum Field { - PosX, - PosY, - PosZ, - TexU, - TexV, - Color, - } - const FIELDS: &[&str] = &["pos_x", "pos_y", "pos_z", "tex_x", "tex_y", "color"]; - - struct VertexVisitor; - - impl<'de> Visitor<'de> for VertexVisitor { - type Value = Vertex; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("struct Vertex") - } - - fn visit_seq<V>(self, mut seq: V) -> Result<Vertex, V::Error> - where - V: SeqAccess<'de>, - { - let pos_x = seq - .next_element()? - .ok_or_else(|| de::Error::invalid_length(0, &self))?; - let pos_y = seq - .next_element()? - .ok_or_else(|| de::Error::invalid_length(1, &self))?; - let pos_z = seq - .next_element()? - .ok_or_else(|| de::Error::invalid_length(2, &self))?; - let tex_u = seq - .next_element()? - .ok_or_else(|| de::Error::invalid_length(3, &self))?; - let tex_v = seq - .next_element()? - .ok_or_else(|| de::Error::invalid_length(4, &self))?; - let color = seq - .next_element()? - .ok_or_else(|| de::Error::invalid_length(5, &self))?; - Ok(Vertex { - position: Vector3::new(pos_x, pos_y, pos_z), - tex: Vector2::new(tex_u, tex_v), - color, - }) - } - - fn visit_map<V>(self, mut map: V) -> Result<Vertex, V::Error> - where - V: MapAccess<'de>, - { - let mut pos_x = None; - let mut pos_y = None; - let mut pos_z = None; - let mut tex_u = None; - let mut tex_v = None; - let mut color = None; - while let Some(key) = map.next_key()? { - match key { - Field::PosX => { - if pos_x.is_some() { - return Err(de::Error::duplicate_field("pos_x")); - } - pos_x = Some(map.next_value()?); - } - Field::PosY => { - if pos_y.is_some() { - return Err(de::Error::duplicate_field("pos_y")); - } - pos_y = Some(map.next_value()?); - } - Field::PosZ => { - if pos_z.is_some() { - return Err(de::Error::duplicate_field("pos_z")); - } - pos_z = Some(map.next_value()?); - } - Field::TexU => { - if tex_u.is_some() { - return Err(de::Error::duplicate_field("tex_u")); - } - tex_u = Some(map.next_value()?); - } - Field::TexV => { - if tex_v.is_some() { - return Err(de::Error::duplicate_field("tex_v")); - } - tex_v = Some(map.next_value()?); - } - Field::Color => { - if color.is_some() { - return Err(de::Error::duplicate_field("color")); - } - color = Some(map.next_value()?); - } - } - } - let position = Vector3::new( - pos_x.ok_or_else(|| de::Error::missing_field("pos_x"))?, - pos_y.ok_or_else(|| de::Error::missing_field("pos_y"))?, - pos_z.ok_or_else(|| de::Error::missing_field("pos_z"))?, - ); - let tex = Vector2::new( - tex_u.ok_or_else(|| de::Error::missing_field("tex_u"))?, - tex_v.ok_or_else(|| de::Error::missing_field("tex_v"))?, - ); - let color = color.ok_or_else(|| de::Error::missing_field("nanos"))?; - Ok(Vertex { - position, - tex, - color, - }) - } - } - - deserializer.deserialize_struct("Vertex", FIELDS, VertexVisitor) - } -} diff --git a/stockton-levels/src/parts/visdata.rs b/stockton-levels/src/parts/visdata.rs deleted file mode 100644 index 3e58d4c..0000000 --- a/stockton-levels/src/parts/visdata.rs +++ /dev/null @@ -1,8 +0,0 @@ -use super::faces::FaceRef; -use std::iter::Iterator; -use stockton_skeleton::components::{CameraSettings, Transform}; - -pub trait HasVisData<'a> { - type Faces: Iterator<Item = FaceRef>; - fn get_visible(&'a self, transform: &Transform, settings: &CameraSettings) -> Self::Faces; -} diff --git a/stockton-levels/src/prelude.rs b/stockton-levels/src/prelude.rs deleted file mode 100644 index 0da890b..0000000 --- a/stockton-levels/src/prelude.rs +++ /dev/null @@ -1,16 +0,0 @@ -// 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/>. -//! Common traits, etc. - -pub use crate::features::*; -pub use crate::parts::*; diff --git a/stockton-levels/src/types.rs b/stockton-levels/src/types.rs deleted file mode 100644 index dad824c..0000000 --- a/stockton-levels/src/types.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Various types used in parsed BSP files. - -use serde::{Deserialize, Serialize}; -use std::convert::TryInto; - -/// RGBA Colour (0-255) -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub struct Rgba { - pub r: u8, - pub g: u8, - pub b: u8, - pub a: u8, -} - -impl Rgba { - /// Interpret the given bytes as an RGBA colour. - pub fn from_bytes(bytes: [u8; 4]) -> Rgba { - Rgba { - r: bytes[0], - g: bytes[1], - b: bytes[2], - a: bytes[3], - } - } - - /// 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()) - } -} - -/// RGB Colour (0-255) -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub struct Rgb { - pub r: u8, - pub g: u8, - pub b: u8, -} - -impl Rgb { - /// 255, 255, 255 - pub fn white() -> Rgb { - Rgb { - r: 255, - g: 255, - b: 255, - } - } - - /// Interpret the given bytes as an RGB colour. - pub fn from_bytes(bytes: [u8; 3]) -> Rgb { - Rgb { - r: bytes[0], - g: bytes[1], - b: bytes[2], - } - } - - /// 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()) - } -} |