diff --git a/common/src/assets/mod.rs b/common/src/assets/mod.rs index d5713d8d6b..98228585b2 100644 --- a/common/src/assets/mod.rs +++ b/common/src/assets/mod.rs @@ -6,15 +6,13 @@ use std::{ collections::HashMap, fs::File, io::Read, - sync::{Arc, PoisonError, RwLock}, + sync::{Arc, RwLock}, }; -use crate::figure::Segment; #[derive(Debug, Clone)] pub enum Error { InvalidType, NotFound, - Poison, } impl From> for Error { @@ -29,12 +27,6 @@ impl From for Error { } } -impl From> for Error { - fn from(_err: PoisonError) -> Self { - Error::Poison - } -} - lazy_static! { static ref ASSETS: RwLock>> = RwLock::new(HashMap::new()); @@ -50,7 +42,7 @@ lazy_static! { // TODO: consider assets that we only need in one place or that don't need to be kept in memory? pub fn load(specifier: &str) -> Result, Error> { Ok(ASSETS - .write()? + .write().unwrap() .entry(specifier.to_string()) .or_insert(Arc::new(A::load(specifier)?)) .clone() @@ -64,7 +56,9 @@ pub trait Asset: Send + Sync + Sized { impl Asset for DynamicImage { fn load(specifier: &str) -> Result { - Ok(image::load_from_memory(load_from_path(specifier)?.as_slice()).unwrap()) + Ok(image::load_from_memory( + load_from_path(specifier)?.as_slice() + ).unwrap()) } } @@ -74,22 +68,16 @@ impl Asset for DotVoxData { } } -impl Asset for Segment { - fn load(specifier: &str) -> Result { - Ok(Segment::from(dot_vox::load_bytes(load_from_path(specifier)?.as_slice()).unwrap())) - } -} - // TODO: System to load file from specifiers (eg "core.ui.backgrounds.city") fn try_load_from_path(name: &str) -> Option { let basepaths = [ + [env!("CARGO_MANIFEST_DIR"), "/../assets"].concat(), // if it's stupid and it works.., "assets".to_string(), "../../assets".to_string(), "../assets".to_string(), /* optimizations */ [env!("CARGO_MANIFEST_DIR"), "/assets"].concat(), [env!("CARGO_MANIFEST_DIR"), "/../../assets"].concat(), - [env!("CARGO_MANIFEST_DIR"), "/../assets"].concat(), "../../../assets".to_string(), [env!("CARGO_MANIFEST_DIR"), "/../../../assets"].concat(), ]; @@ -97,11 +85,11 @@ fn try_load_from_path(name: &str) -> Option { let filename = [bp, name].concat(); match File::open(&filename) { Ok(f) => { - debug!("loading {} succedeed", filename); + debug!("Loading {} successful", filename); return Some(f); }, Err(e) => { - debug!("loading {} did not work with error: {}", filename, e); + debug!("Loading {} failed: {}", filename, e); } }; }; @@ -112,14 +100,10 @@ pub fn load_from_path(name: &str) -> Result, Error> { match try_load_from_path(name) { Some(mut f) => { let mut content: Vec = vec!(); - f.read_to_end(&mut content); - info!("loaded asset successful: {}", name); + f.read_to_end(&mut content)?; Ok(content) }, - None => { - warn!("Loading asset failed, wanted to load {} but could not load it, check debug log!", name); - Err(Error::NotFound) - } + None => Err(Error::NotFound), } } diff --git a/common/src/figure/mod.rs b/common/src/figure/mod.rs index 10e52cabcb..5d71237f58 100644 --- a/common/src/figure/mod.rs +++ b/common/src/figure/mod.rs @@ -18,8 +18,8 @@ use self::cell::Cell; /// Figures are used to represent things like characters, NPCs, mobs, etc. pub type Segment = Dyna; -impl From for Segment { - fn from(dot_vox_data: DotVoxData) -> Self { +impl From<&DotVoxData> for Segment { + fn from(dot_vox_data: &DotVoxData) -> Self { if let Some(model) = dot_vox_data.models.get(0) { let palette = dot_vox_data .palette diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 59751265f8..8196523fd6 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -207,7 +207,7 @@ widget_ids! { } image_ids! { - pub(self) struct Voxs { + struct Voxs { // Bag bag_contents: "/voxygen/element/frames/bag.vox", inv_grid: "/voxygen/element/frames/inv_grid.vox", diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index 057630c991..88d6163943 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -5,8 +5,18 @@ use crate::{ }; use common::{ assets, - comp::character::{Belt, Character, Chest, Foot, Gender, Hand, Head, Pants, Race, Weapon}, - figure::Segment, + comp::character::{ + Character, + Race, + Gender, + Head, + Chest, + Belt, + Pants, + Hand, + Foot, + Weapon, + } }; use conrod_core::{ color, @@ -235,14 +245,14 @@ impl Imgs { let load_img = |filename, ui: &mut Ui| { let fullpath: String = ["/voxygen/", filename].concat(); let image = assets::load::(fullpath.as_str()) - .expect("Error loading file"); + .unwrap(); ui.new_graphic(image.into()) }; let load_vox = |filename, ui: &mut Ui| { let fullpath: String = ["/voxygen/", filename].concat(); - let segment = assets::load::(fullpath.as_str()) - .expect("Error loading file"); - ui.new_graphic(segment.into()) + let dot_vox = assets::load::(fullpath.as_str()) + .unwrao(); + ui.new_graphic(dot_vox.into()) }; Imgs { v_logo: load_vox("element/v_logo.vox", ui), diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index 25ae3a0ee5..46d7ab313d 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -1,18 +1,16 @@ use crate::{ render::Renderer, ui::{self, ScaleMode, Ui}, - window::Window, GlobalState, DEFAULT_PUBLIC_SERVER, }; use common::{ assets, - figure::Segment, }; use conrod_core::{ color, color::TRANSPARENT, image::Id as ImgId, - position::{Dimension, Relative}, + position::Relative, text::font::Id as FontId, widget::{text_box::Event as TextBoxEvent, Button, Image, List, Rectangle, Text, TextBox}, widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, Widget, @@ -70,14 +68,14 @@ impl Imgs { let load_img = |filename, ui: &mut Ui| { let fullpath: String = ["/voxygen/", filename].concat(); let image = assets::load::(fullpath.as_str()) - .expect("Error loading file"); + .unwrap(); ui.new_graphic(image.into()) }; let load_vox = |filename, ui: &mut Ui| { let fullpath: String = ["/voxygen/", filename].concat(); - let segment = assets::load::(fullpath.as_str()) - .expect("Error loading file"); - ui.new_graphic(segment.into()) + let dot_vox = assets::load::(fullpath.as_str()) + .unwrap(); + ui.new_graphic(dot_vox.into()) }; Imgs { bg: load_img("background/bg_main.png", ui), diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 76a20ad743..ce51b1b2d5 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -98,10 +98,11 @@ impl FigureCache { .retain(|_, (_, last_used)| *last_used + 60 > tick); } - fn load_mesh(filename: &'static str, position: Vec3) -> Mesh { + fn load_mesh(filename: &str, position: Vec3) -> Mesh { let fullpath: String = ["/voxygen/voxel/", filename].concat(); - assets::load::(fullpath.as_str()) - .expect("Error loading file") + Segment::from( + assets::load::(fullpath.as_str()).unwrap().as_ref() + ) .generate_mesh(position) } diff --git a/voxygen/src/ui/graphic/graphic.rs b/voxygen/src/ui/graphic/graphic.rs index 8ecf0b4b04..d4f9ac7558 100644 --- a/voxygen/src/ui/graphic/graphic.rs +++ b/voxygen/src/ui/graphic/graphic.rs @@ -1,13 +1,13 @@ use std::sync::Arc; -use common::figure::Segment; use fnv::FnvHashMap; use guillotiere::{size2, Allocation, AtlasAllocator}; use image::DynamicImage; +use dot_vox::DotVoxData; use vek::*; pub enum Graphic { Image(Arc), - Voxel(Arc), + Voxel(Arc), Blank, } @@ -16,8 +16,8 @@ impl From> for Graphic { Graphic::Image(image) } } -impl From> for Graphic { - fn from(vox: Arc) -> Self { +impl From> for Graphic { + fn from(vox: Arc) -> Self { Graphic::Voxel(vox) } } @@ -105,8 +105,8 @@ impl GraphicCache { .pixels() .map(|p| p.data) .collect::>(), - Graphic::Voxel(vox) => { - super::renderer::draw_vox(&vox, aabr.size().into()) + Graphic::Voxel(ref vox) => { + super::renderer::draw_vox(&vox.as_ref().into(), aabr.size().into()) } Graphic::Blank => return None, };