diff --git a/Cargo.lock b/Cargo.lock index 2cb5ad62f6..89999392bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -243,9 +243,9 @@ checksum = "bbf56136a5198c7b01a49e3afcbef6cf84597273d298f54432926024107b0109" [[package]] name = "assets_manager" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8048fbc7e6314fa56e2c7faeb0e1c7be01d23c87bad301a7877afaa493ec3dbb" +checksum = "3593b8ddb9708251c7a57b07c917c77ecc685e804b697366d26fb4af64c9b960" dependencies = [ "ahash 0.6.2", "bincode", diff --git a/common/Cargo.toml b/common/Cargo.toml index 118388084b..9260c640a9 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -30,7 +30,7 @@ vek = { version = "0.12.0", features = ["serde"] } uuid = { version = "0.8.1", default-features = false, features = ["serde", "v4"] } # Assets -assets_manager = {version = "0.4.1", features = ["bincode", "ron", "json", "hot-reloading"]} +assets_manager = {version = "0.4.2", features = ["bincode", "ron", "json", "hot-reloading"]} directories-next = "2.0" dot_vox = "4.0" image = { version = "0.23.12", default-features = false, features = ["png"] } diff --git a/common/src/assets.rs b/common/src/assets.rs index 9ec243d2d8..871f924dc1 100644 --- a/common/src/assets.rs +++ b/common/src/assets.rs @@ -3,7 +3,6 @@ use dot_vox::DotVoxData; use image::DynamicImage; use lazy_static::lazy_static; -use serde::Deserialize; use std::{ borrow::Cow, fs, io, @@ -12,6 +11,7 @@ use std::{ }; pub use assets_manager::{ + asset::Ron, loader::{ self, BincodeLoader, BytesLoader, JsonLoader, LoadFrom, Loader, RonLoader, StringLoader, }, @@ -119,20 +119,6 @@ impl Loader for DotVoxLoader { } } -/// Load from an arbitrary RON file. -#[derive(Deserialize)] -#[serde(transparent)] -pub struct Ron(pub T); - -impl Asset for Ron -where - T: Send + Sync + for<'de> Deserialize<'de> + 'static, -{ - type Loader = RonLoader; - - const EXTENSION: &'static str = "ron"; -} - impl Asset for DotVoxAsset { type Loader = DotVoxLoader; diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index c1843360d5..729281ad6a 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -7,7 +7,7 @@ use crate::{ }; use hashbrown::HashMap; use serde::{Deserialize, Serialize}; -use std::{time::Duration}; +use std::time::Duration; use tracing::error; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/voxygen/src/i18n.rs b/voxygen/src/i18n.rs index 409032d7b2..d55f81637c 100644 --- a/voxygen/src/i18n.rs +++ b/voxygen/src/i18n.rs @@ -1,10 +1,8 @@ use common::assets::{self, AssetExt}; use deunicode::deunicode; -use serde::{Deserialize, Serialize}; -use std::{ - borrow::Cow, -}; use hashbrown::{HashMap, HashSet}; +use serde::{Deserialize, Serialize}; +use std::borrow::Cow; use tracing::warn; /// The reference language, aka the more up-to-date localization data. diff --git a/world/examples/settlement_viewer.rs b/world/examples/settlement_viewer.rs index 6f65677368..18b6fdc90c 100644 --- a/world/examples/settlement_viewer.rs +++ b/world/examples/settlement_viewer.rs @@ -8,7 +8,7 @@ const H: usize = 480; #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 fn main() { let seed = 1337; - let (ref index, colors) = Index::new(seed); + let index = &Index::new(seed); let mut win = minifb::Window::new("Settlement Viewer", W, H, minifb::WindowOptions::default()).unwrap(); @@ -17,7 +17,7 @@ fn main() { let mut focus = Vec2::::zero(); let mut zoom = 1.0; - let colors = &**colors.read(); + let colors = &**index.colors().read(); let index = IndexRef { colors, index }; while win.is_open() { diff --git a/world/src/index.rs b/world/src/index.rs index 928a51d371..cf20aafda7 100644 --- a/world/src/index.rs +++ b/world/src/index.rs @@ -14,6 +14,7 @@ pub struct Index { pub time: f32, pub noise: Noise, pub sites: Store, + colors: AssetHandle>, } /// An owned reference to indexed data. @@ -25,10 +26,6 @@ pub struct Index { pub struct IndexOwned { colors: Arc, index: Arc, - - /// Stored separatly so `colors` is only updated when - /// `reload_colors_if_changed` is called - colors_handle: AssetHandle>, } impl Deref for IndexOwned { @@ -54,27 +51,28 @@ impl<'a> Deref for IndexRef<'a> { impl Index { /// NOTE: Panics if the color manifest cannot be loaded. - pub fn new(seed: u32) -> (Self, AssetHandle>) { + pub fn new(seed: u32) -> Self { let colors = Arc::::load_expect(WORLD_COLORS_MANIFEST); - ( - Self { - seed, - time: 0.0, - noise: Noise::new(seed), - sites: Store::default(), - }, + Self { + seed, + time: 0.0, + noise: Noise::new(seed), + sites: Store::default(), colors, - ) + } } + + pub fn colors(&self) -> AssetHandle> { self.colors } } impl IndexOwned { - pub fn new(index: Index, colors: AssetHandle>) -> Self { + pub fn new(index: Index) -> Self { + let colors = index.colors.cloned(); + Self { index: Arc::new(index), - colors: colors.cloned(), - colors_handle: colors, + colors, } } @@ -89,9 +87,9 @@ impl IndexOwned { &mut self, reload: impl FnOnce(&mut Self) -> R, ) -> Option { - self.colors_handle.reloaded().then(move || { - // Reload the color from the asse handle, which is updated automatically - self.colors = self.colors_handle.cloned(); + self.index.colors.reloaded_global().then(move || { + // Reload the color from the asset handle, which is updated automatically + self.colors = self.index.colors.cloned(); reload(self) }) } diff --git a/world/src/lib.rs b/world/src/lib.rs index d93e5255f6..770be7c1d5 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -81,13 +81,13 @@ impl World { pub fn generate(seed: u32, opts: sim::WorldOpts) -> (Self, IndexOwned) { // NOTE: Generating index first in order to quickly fail if the color manifest // is broken. - let (mut index, colors) = Index::new(seed); + let mut index = Index::new(seed); let mut sim = sim::WorldSim::generate(seed, opts); let civs = civ::Civs::generate(seed, &mut sim, &mut index); sim2::simulate(&mut index, &mut sim); - (Self { sim, civs }, IndexOwned::new(index, colors)) + (Self { sim, civs }, IndexOwned::new(index)) } pub fn sim(&self) -> &sim::WorldSim { &self.sim }