From 6367a9ba5a549b62f01da61fb50323877b9f52ff Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 17:44:24 +0100 Subject: refactor(all): move types to -skeleton --- stockton-skeleton/src/texture/image.rs | 8 +++++ stockton-skeleton/src/texture/load.rs | 2 +- stockton-skeleton/src/texture/loader.rs | 2 +- stockton-skeleton/src/texture/mod.rs | 3 +- stockton-skeleton/src/texture/repo.rs | 2 +- stockton-skeleton/src/texture/resolver.rs | 55 ------------------------------- 6 files changed, 12 insertions(+), 60 deletions(-) delete mode 100644 stockton-skeleton/src/texture/resolver.rs (limited to 'stockton-skeleton/src/texture') 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; +} 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; -} - -/// 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>, -} - -impl<'a, T: HasTextures> FsResolver<'a, T> { - pub fn new(path: &'a Path, map_lock: Arc>) -> Self { - FsResolver { path, map_lock } - } -} - -impl<'a, T: HasTextures> TextureResolver for FsResolver<'a, T> { - type Image = RgbaImage; - - fn resolve(&mut self, tex: u32) -> Option { - 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 - } -} -- cgit v1.2.3