diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:24 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:24 +0100 |
commit | 6367a9ba5a549b62f01da61fb50323877b9f52ff (patch) | |
tree | eb83ed6487f2ec35f9ea1e97124c9a173b8ceef0 | |
parent | f84ec1a3e077fa0f2e9cd310b6e32e81f1bc1129 (diff) |
refactor(all): move types to -skeleton
32 files changed, 92 insertions, 137 deletions
@@ -1,6 +1,5 @@ [workspace] members = [ - "stockton-types", "stockton-input", "stockton-input-codegen", "stockton-skeleton", diff --git a/examples/render-quad/Cargo.toml b/examples/render-quad/Cargo.toml index 0c4306d..99cf38e 100644 --- a/examples/render-quad/Cargo.toml +++ b/examples/render-quad/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" stockton-skeleton = { path = "../../stockton-skeleton", features = ["vulkan"] } stockton-input = { path = "../../stockton-input" } stockton-input-codegen = { path = "../../stockton-input-codegen" } -stockton-types = { path = "../../stockton-types" } stockton-levels = { path = "../../stockton-levels" } stockton-contrib = { path = "../../stockton-contrib", features = ["delta_time", "flycam"] } stockton-render = { path = "../../stockton-render" } diff --git a/examples/render-quad/src/level.rs b/examples/render-quad/src/level.rs index d10c3b6..74d1cc3 100644 --- a/examples/render-quad/src/level.rs +++ b/examples/render-quad/src/level.rs @@ -2,6 +2,7 @@ use stockton_levels::parts::{ data::{FaceRef, Geometry, TextureRef}, HasFaces, HasTextures, HasVisData, IsFace, IsTexture, }; +use stockton_skeleton::components::{CameraSettings, Transform}; pub struct DemoLevel { pub faces: Box<[Face]>, @@ -70,8 +71,8 @@ impl<'a> HasVisData<'a> for DemoLevel { fn get_visible( &'a self, - _transform: &stockton_types::components::Transform, - _settings: &stockton_types::components::CameraSettings, + _transform: &Transform, + _settings: &CameraSettings, ) -> Self::Faces { 0..self.faces.len() as u32 } diff --git a/examples/render-quad/src/main.rs b/examples/render-quad/src/main.rs index 0b7f3be..c5d52a9 100644 --- a/examples/render-quad/src/main.rs +++ b/examples/render-quad/src/main.rs @@ -15,7 +15,7 @@ use std::{ use stockton_contrib::{delta_time::*, flycam::*}; use stockton_input::{Axis, InputManager, Mouse}; use stockton_levels::{ - parts::data::{Geometry, Vertex}, + parts::{data::{Geometry, Vertex}, FsResolver}, types::Rgba, }; use stockton_render::{ @@ -24,11 +24,9 @@ use stockton_render::{ window::{process_window_events_system, UiState, WindowEvent, WindowFlow}, }; use stockton_skeleton::{ - draw_passes::ConsDrawPass, error::full_error_display, texture::resolver::FsResolver, Renderer, -}; -use stockton_types::{ + draw_passes::ConsDrawPass, error::full_error_display, Renderer, + Session, types::*, components::{CameraSettings, Transform}, - Session, Vector2, Vector3, }; use anyhow::{Context, Result}; diff --git a/stockton-contrib/Cargo.toml b/stockton-contrib/Cargo.toml index b06afc1..c6630e2 100644 --- a/stockton-contrib/Cargo.toml +++ b/stockton-contrib/Cargo.toml @@ -7,8 +7,8 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +stockton-skeleton = { path = "../stockton-skeleton" } stockton-input = { path = "../stockton-input" } -stockton-types = { path = "../stockton-types" } legion = { version = "^0.3" } [features] diff --git a/stockton-contrib/src/flycam.rs b/stockton-contrib/src/flycam.rs index 591b28e..42b80f6 100644 --- a/stockton-contrib/src/flycam.rs +++ b/stockton-contrib/src/flycam.rs @@ -1,8 +1,7 @@ use std::f32::consts::PI; use stockton_input::{Axis, InputManager, Mouse}; -use stockton_types::components::Transform; -use stockton_types::Vector3; +use stockton_skeleton::{types::Vector3, components::Transform}; use crate::delta_time::Timing; diff --git a/stockton-input/Cargo.toml b/stockton-input/Cargo.toml index 57ea6e1..92fcaac 100644 --- a/stockton-input/Cargo.toml +++ b/stockton-input/Cargo.toml @@ -5,5 +5,5 @@ authors = ["Oscar Shrimpton <oscar.shrimpton.personal@gmail.com>"] edition = "2018" [dependencies] -stockton-types = { path = "../stockton-types" } +stockton-skeleton = { path = "../stockton-skeleton" } egui = "^0.2" diff --git a/stockton-input/src/mouse.rs b/stockton-input/src/mouse.rs index ed02989..fe3efd9 100644 --- a/stockton-input/src/mouse.rs +++ b/stockton-input/src/mouse.rs @@ -1,4 +1,4 @@ -use stockton_types::Vector2; +use stockton_skeleton::types::Vector2; #[derive(Debug, Clone)] pub struct Mouse { diff --git a/stockton-levels/Cargo.toml b/stockton-levels/Cargo.toml index b70268b..448a8ba 100644 --- a/stockton-levels/Cargo.toml +++ b/stockton-levels/Cargo.toml @@ -10,4 +10,5 @@ edition = "2018" [dependencies] nalgebra = "^0.20" serde = { version = "1.0", features = ["derive"] } -stockton-types = { path = "../stockton-types" } +stockton-skeleton = { path = "../stockton-skeleton" } +image = "0.23.11" diff --git a/stockton-levels/src/parts/mod.rs b/stockton-levels/src/parts/mod.rs index 05697f0..d164bc3 100644 --- a/stockton-levels/src/parts/mod.rs +++ b/stockton-levels/src/parts/mod.rs @@ -13,5 +13,5 @@ pub mod data { pub use entities::{HasEntities, IsEntity}; pub use faces::{HasFaces, IsFace}; -pub use textures::{HasTextures, IsTexture}; +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 index 8e6cb9a..ae946fd 100644 --- a/stockton-levels/src/parts/textures.rs +++ b/stockton-levels/src/parts/textures.rs @@ -11,7 +11,9 @@ // 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::{iter::Iterator, path::Path, sync::{Arc, RwLock}}; +use image::{RgbaImage, io::Reader}; +use stockton_skeleton::texture::TextureResolver; pub type TextureRef = u32; @@ -46,3 +48,36 @@ impl<'a, T: HasTextures> Iterator for Textures<'a, T> { 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/visdata.rs b/stockton-levels/src/parts/visdata.rs index aa2ec3d..3e58d4c 100644 --- a/stockton-levels/src/parts/visdata.rs +++ b/stockton-levels/src/parts/visdata.rs @@ -1,6 +1,6 @@ use super::faces::FaceRef; use std::iter::Iterator; -use stockton_types::components::{CameraSettings, Transform}; +use stockton_skeleton::components::{CameraSettings, Transform}; pub trait HasVisData<'a> { type Faces: Iterator<Item = FaceRef>; diff --git a/stockton-render/Cargo.toml b/stockton-render/Cargo.toml index 1329443..3ba8c01 100644 --- a/stockton-render/Cargo.toml +++ b/stockton-render/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" [dependencies] stockton-skeleton = { path = "../stockton-skeleton" } -stockton-types = { path = "../stockton-types" } stockton-levels = { path = "../stockton-levels" } stockton-input = { path = "../stockton-input" } anyhow = "1.0.40" diff --git a/stockton-render/src/level.rs b/stockton-render/src/level.rs index f577569..dd4d61a 100644 --- a/stockton-render/src/level.rs +++ b/stockton-render/src/level.rs @@ -13,17 +13,16 @@ use stockton_skeleton::{ AttachmentSpec, CompletePipeline, PipelineSpecBuilder, RenderpassSpec, ShaderDesc, VertexBufferSpec, VertexPrimitiveAssemblerSpec, }, - context::RenderingContext, - draw_passes::{util::TargetSpecificResources, DrawPass, IntoDrawPass, PassPosition}, + RenderingContext, + Session, + DrawPass, IntoDrawPass, PassPosition, + draw_passes::{util::TargetSpecificResources}, error::LockPoisoned, mem::{DataPool, DepthBufferPool, StagingPool, TexturesPool}, queue_negotiator::QueueFamilyNegotiator, - texture::{resolver::TextureResolver, TexLoadQueue, TextureLoadConfig, TextureRepo}, + texture::{TextureResolver, TexLoadQueue, TextureLoadConfig, TextureRepo}, types::*, -}; -use stockton_types::{ components::{CameraSettings, Transform}, - *, }; use anyhow::{Context, Result}; diff --git a/stockton-render/src/ui.rs b/stockton-render/src/ui.rs index 91e1b4b..981be02 100644 --- a/stockton-render/src/ui.rs +++ b/stockton-render/src/ui.rs @@ -7,16 +7,16 @@ use stockton_skeleton::{ AttachmentSpec, CompletePipeline, PipelineSpecBuilder, RenderpassSpec, ShaderDesc, VertexBufferSpec, VertexPrimitiveAssemblerSpec, }, - context::RenderingContext, + RenderingContext, + Session, draw_passes::{util::TargetSpecificResources, DrawPass, IntoDrawPass, PassPosition}, mem::{DataPool, StagingPool, TexturesPool}, queue_negotiator::QueueFamilyNegotiator, texture::{ - resolver::TextureResolver, LoadableImage, TexLoadQueue, TextureLoadConfig, TextureRepo, + TextureResolver, LoadableImage, TexLoadQueue, TextureLoadConfig, TextureRepo, }, types::*, }; -use stockton_types::{Session, Vector2}; use std::{ array::IntoIter, diff --git a/stockton-skeleton/Cargo.toml b/stockton-skeleton/Cargo.toml index d7f4a99..f0edf6d 100644 --- a/stockton-skeleton/Cargo.toml +++ b/stockton-skeleton/Cargo.toml @@ -5,9 +5,6 @@ authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] edition = "2018" [dependencies] -stockton-input = { path = "../stockton-input" } -stockton-levels = { path = "../stockton-levels" } -stockton-types = { path = "../stockton-types" } winit = "^0.21" gfx-hal = "^0.8.0" arrayvec = "0.4.10" diff --git a/stockton-types/src/components/mod.rs b/stockton-skeleton/src/components/mod.rs index a90f5e8..74e5a69 100644 --- a/stockton-types/src/components/mod.rs +++ b/stockton-skeleton/src/components/mod.rs @@ -1,7 +1,7 @@ use na::{Mat4, Vec4}; use std::f32::consts::PI; -use crate::Vector3; +use crate::types::Vector3; /// 90 degrees in radians const R89: f32 = (PI / 180.0) * 89.0; diff --git a/stockton-skeleton/src/context.rs b/stockton-skeleton/src/context.rs index 72b15c7..943e0dc 100644 --- a/stockton-skeleton/src/context.rs +++ b/stockton-skeleton/src/context.rs @@ -35,10 +35,9 @@ use crate::{ mem::MemoryPool, queue_negotiator::{QueueFamilyNegotiator, QueueFamilySelector, SharedQueue}, types::*, + session::Session }; -use stockton_types::Session; - /// The actual data behind [`StatefulRenderingContext`] struct InnerRenderingContext { /// Vulkan Instance diff --git a/stockton-skeleton/src/draw_passes/cons.rs b/stockton-skeleton/src/draw_passes/cons.rs index dea42af..f6c3d1b 100644 --- a/stockton-skeleton/src/draw_passes/cons.rs +++ b/stockton-skeleton/src/draw_passes/cons.rs @@ -2,8 +2,7 @@ //! Note that this can be extended to an arbitrary amount of draw passes. use super::{Beginning, DrawPass, End, IntoDrawPass, Middle, Singular}; -use crate::{context::RenderingContext, queue_negotiator::QueueFamilyNegotiator, types::*}; -use stockton_types::Session; +use crate::{session::Session, context::RenderingContext, queue_negotiator::QueueFamilyNegotiator, types::*}; use anyhow::Result; diff --git a/stockton-skeleton/src/draw_passes/mod.rs b/stockton-skeleton/src/draw_passes/mod.rs index 5b138c2..9a13c73 100644 --- a/stockton-skeleton/src/draw_passes/mod.rs +++ b/stockton-skeleton/src/draw_passes/mod.rs @@ -1,12 +1,11 @@ //! Traits and common draw passes. use std::ops::Range; -use crate::{context::RenderingContext, queue_negotiator::QueueFamilyNegotiator, types::*}; +use crate::{context::RenderingContext, queue_negotiator::QueueFamilyNegotiator, types::*, session::Session}; use hal::{ image::Layout, pass::{AttachmentLoadOp, AttachmentOps, AttachmentStoreOp}, }; -use stockton_types::Session; use anyhow::Result; diff --git a/stockton-skeleton/src/lib.rs b/stockton-skeleton/src/lib.rs index 2b6fe70..d57c5f6 100644 --- a/stockton-skeleton/src/lib.rs +++ b/stockton-skeleton/src/lib.rs @@ -17,15 +17,17 @@ mod target; pub mod texture; pub mod types; pub mod utils; +pub mod components; +pub mod session; -use std::mem::ManuallyDrop; - -use context::RenderingContext; -use draw_passes::{DrawPass, IntoDrawPass, Singular}; +pub use context::RenderingContext; +pub use session::Session; +pub use draw_passes::{DrawPass, IntoDrawPass, PassPosition}; +pub use anyhow::Result; -use anyhow::{Context, Result}; - -use stockton_types::Session; +use draw_passes::Singular; +use std::mem::ManuallyDrop; +use anyhow::{Context}; use winit::window::Window; /// Renders a world to a window when you tell it to. diff --git a/stockton-types/src/session.rs b/stockton-skeleton/src/session.rs index 5b91739..5b91739 100644 --- a/stockton-types/src/session.rs +++ b/stockton-skeleton/src/session.rs diff --git a/stockton-skeleton/src/target.rs b/stockton-skeleton/src/target.rs index 647aa96..23f56b9 100644 --- a/stockton-skeleton/src/target.rs +++ b/stockton-skeleton/src/target.rs @@ -5,8 +5,8 @@ use crate::{ context::ContextProperties, draw_passes::{DrawPass, Singular}, types::*, + session::Session }; -use stockton_types::Session; use std::{ borrow::Borrow, diff --git a/stockton-skeleton/src/texture/image.rs b/stockton-skeleton/src/texture/image.rs index f984b72..6ccd22a 100644 --- a/stockton-skeleton/src/texture/image.rs +++ b/stockton-skeleton/src/texture/image.rs @@ -41,3 +41,11 @@ impl LoadableImage for RgbaImage { copy_nonoverlapping(row.as_ptr(), ptr, row.len()); } } + +/// An object that can be used to resolve a texture from a BSP File +pub trait TextureResolver { + type Image: LoadableImage; + + /// Get the given texture, or None if it's corrupt/not there. + fn resolve(&mut self, texture_id: u32) -> Option<Self::Image>; +} diff --git a/stockton-skeleton/src/texture/load.rs b/stockton-skeleton/src/texture/load.rs index c4d3b72..80c332e 100644 --- a/stockton-skeleton/src/texture/load.rs +++ b/stockton-skeleton/src/texture/load.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, RwLock}; -use super::{block::TexturesBlock, repo::BLOCK_SIZE, resolver::TextureResolver, LoadableImage}; +use super::{block::TexturesBlock, repo::BLOCK_SIZE, TextureResolver, LoadableImage}; use crate::{ buffers::{ image::{ImageSpec, SampledImage, COLOR_RESOURCES}, diff --git a/stockton-skeleton/src/texture/loader.rs b/stockton-skeleton/src/texture/loader.rs index 6de4a4d..6212492 100644 --- a/stockton-skeleton/src/texture/loader.rs +++ b/stockton-skeleton/src/texture/loader.rs @@ -6,7 +6,7 @@ use super::{ load_image, QueuedLoad, TextureLoadConfig, TextureLoadError, FORMAT, LAYERS, RESOURCES, }, repo::BLOCK_SIZE, - resolver::TextureResolver, + TextureResolver, PIXEL_SIZE, }; use crate::{ diff --git a/stockton-skeleton/src/texture/mod.rs b/stockton-skeleton/src/texture/mod.rs index 10fbbad..c5306ce 100644 --- a/stockton-skeleton/src/texture/mod.rs +++ b/stockton-skeleton/src/texture/mod.rs @@ -5,10 +5,9 @@ mod image; mod load; mod loader; mod repo; -pub mod resolver; pub use self::block::TexturesBlock; -pub use self::image::LoadableImage; +pub use self::image::{LoadableImage, TextureResolver}; pub use self::load::TextureLoadConfig; pub use self::loader::BlockRef; pub use self::repo::{TexLoadQueue, TextureRepo}; diff --git a/stockton-skeleton/src/texture/repo.rs b/stockton-skeleton/src/texture/repo.rs index 22fc099..bd36a1e 100644 --- a/stockton-skeleton/src/texture/repo.rs +++ b/stockton-skeleton/src/texture/repo.rs @@ -2,7 +2,7 @@ use super::{ block::TexturesBlock, load::TextureLoadConfig, loader::{BlockRef, LoaderRequest, TextureLoader, TextureLoaderRemains, NUM_SIMULTANEOUS_CMDS}, - resolver::TextureResolver, + TextureResolver, }; use crate::types::*; use crate::{context::RenderingContext, error::LockPoisoned, mem::MappableBlock}; diff --git a/stockton-skeleton/src/texture/resolver.rs b/stockton-skeleton/src/texture/resolver.rs deleted file mode 100644 index f66b724..0000000 --- a/stockton-skeleton/src/texture/resolver.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! Resolves a texture in a BSP File to an image - -use crate::texture::image::LoadableImage; -use stockton_levels::{parts::IsTexture, prelude::HasTextures}; - -use std::{ - path::Path, - sync::{Arc, RwLock}, -}; - -use image::{io::Reader, RgbaImage}; - -/// An object that can be used to resolve a texture from a BSP File -pub trait TextureResolver { - type Image: LoadableImage; - - /// Get the given texture, or None if it's corrupt/not there. - fn resolve(&mut self, texture_id: u32) -> Option<Self::Image>; -} - -/// 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()); - - // drop(tex); - // drop(map); - - 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()); - } - } - } - - log::warn!("Couldn't resolve texture {:?}", tex.name()); - None - } -} diff --git a/stockton-skeleton/src/types.rs b/stockton-skeleton/src/types.rs index 03c6e37..d3cf316 100644 --- a/stockton-skeleton/src/types.rs +++ b/stockton-skeleton/src/types.rs @@ -33,3 +33,11 @@ pub type DynamicAllocator = rendy_memory::DynamicAllocator<back::Backend>; pub type DynamicBlock = rendy_memory::DynamicBlock<back::Backend>; pub type RDescriptorSet = rendy_descriptor::DescriptorSet<back::Backend>; + +pub type Vector2 = na::Vec2; +pub type Vector3 = na::Vec3; + +pub type Vector2i = na::IVec2; +pub type Vector3i = na::IVec3; + +pub type Matrix4 = na::Mat4x4; diff --git a/stockton-types/Cargo.toml b/stockton-types/Cargo.toml deleted file mode 100644 index 13f1014..0000000 --- a/stockton-types/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "stockton-types" -version = "0.1.0" -authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] -edition = "2018" - -[dependencies] -nalgebra-glm = "^0.6" -legion = { version = "^0.3" } diff --git a/stockton-types/src/lib.rs b/stockton-types/src/lib.rs deleted file mode 100644 index 1b965a0..0000000 --- a/stockton-types/src/lib.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Common types for all stockton crates. - -extern crate nalgebra_glm as na; - -pub mod components; -pub mod session; - -pub use session::Session; - -/// Alias for convenience -pub type Vector2 = na::Vec2; -/// Alias for convenience -pub type Vector3 = na::Vec3; - -/// Alias for convenience -pub type Vector2i = na::IVec2; - -/// Alias for convenience -pub type Vector3i = na::IVec3; - -/// Alias for convenience -pub type Matrix4 = na::Mat4x4; |