cargo fmt

This commit is contained in:
Benoît du Garreau 2020-12-13 02:09:57 +01:00 committed by Marcel Märtens
parent d090eefb00
commit 7b4aa6d4cc
30 changed files with 233 additions and 176 deletions

View File

@ -4,11 +4,18 @@ use dot_vox::DotVoxData;
use image::DynamicImage;
use lazy_static::lazy_static;
use serde::Deserialize;
use std::{borrow::Cow, fs, io, path::{Path, PathBuf}, sync::Arc};
use std::{
borrow::Cow,
fs, io,
path::{Path, PathBuf},
sync::Arc,
};
pub use assets_manager::{
Asset, AssetCache, BoxedError, Compound, Error, source,
loader::{self, BytesLoader, BincodeLoader, Loader, JsonLoader, LoadFrom, RonLoader, StringLoader},
loader::{
self, BincodeLoader, BytesLoader, JsonLoader, LoadFrom, Loader, RonLoader, StringLoader,
},
source, Asset, AssetCache, BoxedError, Compound, Error,
};
lazy_static! {
@ -16,9 +23,7 @@ lazy_static! {
static ref ASSETS: AssetCache = AssetCache::new(&*ASSETS_PATH).unwrap();
}
pub fn start_hot_reloading() {
ASSETS.enhance_hot_reloading();
}
pub fn start_hot_reloading() { ASSETS.enhance_hot_reloading(); }
pub type AssetHandle<T> = assets_manager::Handle<'static, T>;
pub type AssetDir<T> = assets_manager::DirReader<'static, T, source::FileSystem>;
@ -79,21 +84,15 @@ pub fn load_dir<T: Asset>(specifier: &str) -> Result<AssetDir<T>, Error> {
}
impl<T: Compound> AssetExt for T {
fn load(specifier: &str) -> Result<AssetHandle<Self>, Error> {
ASSETS.load(specifier)
}
fn load(specifier: &str) -> Result<AssetHandle<Self>, Error> { ASSETS.load(specifier) }
fn load_owned(specifier: &str) -> Result<Self, Error> {
ASSETS.load_owned(specifier)
}
fn load_owned(specifier: &str) -> Result<Self, Error> { ASSETS.load_owned(specifier) }
}
pub struct Image(pub Arc<DynamicImage>);
impl Image {
pub fn to_image(&self) -> Arc<DynamicImage> {
self.0.clone()
}
pub fn to_image(&self) -> Arc<DynamicImage> { self.0.clone() }
}
pub struct ImageLoader;
@ -105,8 +104,9 @@ impl Loader<Image> for ImageLoader {
}
impl Asset for Image {
const EXTENSIONS: &'static [&'static str] = &["png", "jpg"];
type Loader = ImageLoader;
const EXTENSIONS: &'static [&'static str] = &["png", "jpg"];
}
pub struct DotVoxAsset(pub DotVoxData);
@ -128,14 +128,15 @@ impl<T> Asset for Ron<T>
where
T: Send + Sync + for<'de> Deserialize<'de> + 'static,
{
const EXTENSION: &'static str = "ron";
type Loader = RonLoader;
const EXTENSION: &'static str = "ron";
}
impl Asset for DotVoxAsset {
const EXTENSION: &'static str = "vox";
type Loader = DotVoxLoader;
const EXTENSION: &'static str = "vox";
}
lazy_static! {
@ -242,9 +243,7 @@ fn get_dir_files(files: &mut Vec<String>, path: &Path, specifier: &str) -> io::R
pub struct Directory(Vec<String>);
impl Directory {
pub fn iter(&self) -> impl Iterator<Item=&String> {
self.0.iter()
}
pub fn iter(&self) -> impl Iterator<Item = &String> { self.0.iter() }
}
impl Compound for Directory {
@ -256,4 +255,4 @@ impl Compound for Directory {
Ok(Directory(files))
}
}
}

View File

@ -16,8 +16,8 @@ use arraygen::Arraygen;
use serde::{Deserialize, Serialize};
use specs::{Component, FlaggedStorage};
use specs_idvs::IdvStorage;
use tracing::error;
use std::time::Duration;
use tracing::error;
use vek::Vec3;
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Serialize, Deserialize)]
@ -239,14 +239,14 @@ impl Default for CharacterAbility {
}
impl Asset for CharacterAbility {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
fn default_value(specifier: &str, err: assets::Error) -> Result<Self, assets::Error> {
error!(
?err,
"Error loading CharacterAbility: {} for the ability \
map: replacing with default",
"Error loading CharacterAbility: {} for the ability map: replacing with default",
specifier
);

View File

@ -126,8 +126,9 @@ impl<
SpeciesMeta: Send + Sync + for<'de> serde::Deserialize<'de> + 'static,
> Asset for AllBodies<BodyMeta, SpeciesMeta>
{
const EXTENSION: &'static str = "json";
type Loader = assets::JsonLoader;
const EXTENSION: &'static str = "json";
}
impl Body {

View File

@ -159,13 +159,27 @@ impl PartialEq for Item {
}
impl assets::Compound for ItemDef {
fn load<S: assets_manager::source::Source>(cache: &assets_manager::AssetCache<S>, specifier: &str) -> Result<Self, Error> {
fn load<S: assets_manager::source::Source>(
cache: &assets_manager::AssetCache<S>,
specifier: &str,
) -> Result<Self, Error> {
let raw = cache.load_owned::<RawItemDef>(specifier)?;
let RawItemDef { name, description, kind, quality} = raw;
let RawItemDef {
name,
description,
kind,
quality,
} = raw;
let item_definition_id = specifier.replace('\\', ".");
Ok(ItemDef { item_definition_id, name, description, kind, quality })
Ok(ItemDef {
item_definition_id,
name,
description,
kind,
quality,
})
}
}
@ -179,16 +193,15 @@ struct RawItemDef {
}
impl assets::Asset for RawItemDef {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
}
impl Item {
// TODO: consider alternatives such as default abilities that can be added to a
// loadout when no weapon is present
pub fn empty() -> Self {
Item::new_from_asset_expect("common.items.weapons.empty.empty")
}
pub fn empty() -> Self { Item::new_from_asset_expect("common.items.weapons.empty.empty") }
pub fn new(inner_item: Arc<ItemDef>) -> Self {
Item {
@ -212,7 +225,8 @@ impl Item {
let specifiers = assets::Directory::load(asset_glob)?;
specifiers.read()
specifiers
.read()
.iter()
.map(|spec| Self::new_from_asset(&spec))
.collect()
@ -334,7 +348,8 @@ impl Item {
3 => "common.loot_tables.loot_table_armor_cloth",
4 => "common.loot_tables.loot_table_armor_heavy",
_ => "common.loot_tables.loot_table_armor_misc",
}).read();
})
.read();
chosen.choose()
},
SpriteKind::ChestBurried => {
@ -343,7 +358,8 @@ impl Item {
2 => "common.loot_tables.loot_table_armor_light",
3 => "common.loot_tables.loot_table_armor_cloth",
_ => "common.loot_tables.loot_table_armor_misc",
}).read();
})
.read();
chosen.choose()
},
SpriteKind::Mud => {
@ -352,14 +368,16 @@ impl Item {
1 => "common.loot_tables.loot_table_weapon_common",
2 => "common.loot_tables.loot_table_armor_misc",
_ => "common.loot_tables.loot_table_rocks",
}).read();
})
.read();
chosen.choose()
},
SpriteKind::Crate => {
chosen = Lottery::<String>::load_expect(match rng.gen_range(0, 4) {
0 => "common.loot_tables.loot_table_crafting",
_ => "common.loot_tables.loot_table_food",
}).read();
})
.read();
chosen.choose()
},
SpriteKind::Beehive => "common.items.crafting_ing.honey",

View File

@ -144,26 +144,31 @@ impl Default for AbilitySet<CharacterAbility> {
pub struct AbilityMap<T = CharacterAbility>(HashMap<ToolKind, AbilitySet<T>>);
impl Asset for AbilityMap<String> {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
}
impl assets::Compound for AbilityMap {
fn load<S: assets_manager::source::Source>(cache: &assets_manager::AssetCache<S>, specifier: &str) -> Result<Self, assets::Error> {
fn load<S: assets_manager::source::Source>(
cache: &assets_manager::AssetCache<S>,
specifier: &str,
) -> Result<Self, assets::Error> {
let manifest = cache.load::<AbilityMap<String>>(specifier)?.read();
Ok(AbilityMap(
manifest.0
manifest
.0
.iter()
.map(|(kind, set)| {
(
kind.clone(),
// expect cannot fail because CharacterAbility always
// provides a default value in case of failure
set.map_ref(|s| cache.load_expect(&s).cloned())
set.map_ref(|s| cache.load_expect(&s).cloned()),
)
})
.collect()
.collect(),
))
}
}

View File

@ -9,8 +9,9 @@ pub struct Lottery<T> {
}
impl<T: DeserializeOwned + Send + Sync + 'static> assets::Asset for Lottery<T> {
const EXTENSION: &'static str = "ron";
type Loader = assets::LoadFrom<Vec<(f32, T)>, assets::RonLoader>;
const EXTENSION: &'static str = "ron";
}
impl<T> From<Vec<(f32, T)>> for Lottery<T> {

View File

@ -88,7 +88,10 @@ pub fn get_npc_name(npc_type: NpcKind) -> String {
let BodyNames { keyword, names } = &npc_names[npc_type];
// If no pretty name is found, fall back to the keyword.
names.choose(&mut rand::thread_rng()).unwrap_or(keyword).clone()
names
.choose(&mut rand::thread_rng())
.unwrap_or(keyword)
.clone()
}
/// Randomly generates a body associated with this NPC kind.

View File

@ -70,13 +70,16 @@ impl RecipeBook {
struct RawRecipeBook(HashMap<String, ((String, u32), Vec<(String, u32)>)>);
impl assets::Asset for RawRecipeBook {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
}
impl assets::Compound for RecipeBook {
fn load<S: assets_manager::source::Source>(cache: &assets_manager::AssetCache<S>, specifier: &str) -> Result<Self, assets_manager::Error> {
fn load<S: assets_manager::source::Source>(
cache: &assets_manager::AssetCache<S>,
specifier: &str,
) -> Result<Self, assets_manager::Error> {
#[inline]
fn load_item_def(spec: &(String, u32)) -> Result<(Arc<ItemDef>, u32), assets::Error> {
let def = Arc::<ItemDef>::load_cloned(&spec.0)?;
@ -85,11 +88,11 @@ impl assets::Compound for RecipeBook {
let raw = cache.load::<RawRecipeBook>(specifier)?.read();
let recipes = raw.0.iter()
let recipes = raw
.0
.iter()
.map(|(name, (output, inputs))| {
let inputs = inputs.iter()
.map(load_item_def)
.collect::<Result<_, _>>()?;
let inputs = inputs.iter().map(load_item_def).collect::<Result<_, _>>()?;
let output = load_item_def(output)?;
Ok((name.clone(), Recipe { inputs, output }))
})

View File

@ -53,17 +53,20 @@ pub struct StructuresGroup(Vec<Structure>);
impl std::ops::Deref for StructuresGroup {
type Target = [Structure];
fn deref(&self) -> &[Structure] {
&self.0
}
fn deref(&self) -> &[Structure] { &self.0 }
}
impl assets::Compound for StructuresGroup {
fn load<S: assets_manager::source::Source>(cache: &assets_manager::AssetCache<S>, specifier: &str) -> Result<Self, Error> {
fn load<S: assets_manager::source::Source>(
cache: &assets_manager::AssetCache<S>,
specifier: &str,
) -> Result<Self, Error> {
let specs = cache.load::<StructuresGroupSpec>(specifier)?.read();
Ok(StructuresGroup(
specs.0.iter()
specs
.0
.iter()
.map(|sp| {
let base = cache.load::<Arc<BaseStructure>>(&sp.specifier)?.cloned();
Ok(Structure {
@ -71,7 +74,7 @@ impl assets::Compound for StructuresGroup {
base,
})
})
.collect::<Result<_, Error>>()?
.collect::<Result<_, Error>>()?,
))
}
}
@ -112,7 +115,10 @@ impl ReadVol for Structure {
}
impl assets::Compound for BaseStructure {
fn load<S: assets_manager::source::Source>(cache: &assets_manager::AssetCache<S>, specifier: &str) -> Result<Self, Error> {
fn load<S: assets_manager::source::Source>(
cache: &assets_manager::AssetCache<S>,
specifier: &str,
) -> Result<Self, Error> {
let dot_vox_data = cache.load::<DotVoxAsset>(specifier)?.read();
let dot_vox_data = &dot_vox_data.0;
@ -182,6 +188,7 @@ struct StructureSpec {
struct StructuresGroupSpec(Vec<StructureSpec>);
impl assets::Asset for StructuresGroupSpec {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
}
const EXTENSION: &'static str = "ron";
}

View File

@ -4,7 +4,10 @@ use crate::{
scene::Camera,
};
use client::Client;
use common::{assets::{self, AssetExt, AssetHandle}, vol::ReadVol};
use common::{
assets::{self, AssetExt, AssetHandle},
vol::ReadVol,
};
use common_sys::state::State;
use serde::Deserialize;
use std::time::Instant;
@ -130,14 +133,16 @@ impl AmbientMgr {
}
impl assets::Asset for AmbientCollection {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
fn default_value(_: &str, error: assets::Error) -> Result<Self, assets::Error> {
warn!(
"Error reading music config file, music will not be available: {:#?}", error
"Error reading music config file, music will not be available: {:#?}",
error
);
Ok(AmbientCollection::default())
}
}
}

View File

@ -232,14 +232,16 @@ impl MusicMgr {
}
impl assets::Asset for SoundtrackCollection {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
fn default_value(_: &str, error: assets::Error) -> Result<Self, assets::Error> {
warn!(
"Error reading music config file, music will not be available: {:#?}", error
"Error reading music config file, music will not be available: {:#?}",
error
);
Ok(SoundtrackCollection::default())
}
}
}

View File

@ -368,14 +368,16 @@ impl SfxMgr {
}
impl assets::Asset for SfxTriggers {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
fn default_value(_: &str, error: assets::Error) -> Result<Self, assets::Error> {
warn!(
"Error reading sfx config file, sfx will not be available: {:#?}", error
"Error reading sfx config file, sfx will not be available: {:#?}",
error
);
Ok(SfxTriggers::default())
}
}
}

View File

@ -23,9 +23,10 @@ impl assets::Loader<WavSound> for SoundLoader {
}
impl assets::Asset for WavSound {
const EXTENSION: &'static str = "wav";
type Loader = SoundLoader;
const EXTENSION: &'static str = "wav";
fn default_value(specifier: &str, error: assets::Error) -> Result<Self, assets::Error> {
warn!(?specifier, ?error, "Failed to load sound");
@ -40,9 +41,9 @@ impl WavSound {
rodio::Decoder::new(cursor).unwrap()
}
/// Returns a `WavSound` containing empty .wav data. This intentionally doesn't
/// load from the filesystem so we have a reliable fallback when there
/// is a failure to read a file.
/// Returns a `WavSound` containing empty .wav data. This intentionally
/// doesn't load from the filesystem so we have a reliable fallback when
/// there is a failure to read a file.
///
/// The data below is the result of passing a very short, silent .wav file
/// to `Sound::load()`.
@ -69,8 +70,9 @@ impl assets::Loader<OggSound> for SoundLoader {
}
impl assets::Asset for OggSound {
const EXTENSION: &'static str = "ogg";
type Loader = SoundLoader;
const EXTENSION: &'static str = "ogg";
}
/// Wrapper for decoded audio data
@ -79,4 +81,4 @@ impl OggSound {
let cursor = io::Cursor::new(self);
rodio::Decoder::new(cursor).unwrap()
}
}
}

View File

@ -84,8 +84,9 @@ impl ImageSpec {
#[derive(Serialize, Deserialize)]
struct ItemImagesSpec(HashMap<ItemKey, ImageSpec>);
impl assets::Asset for ItemImagesSpec {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
}
// TODO: when there are more images don't load them all into memory
@ -97,7 +98,7 @@ pub struct ItemImgs {
impl ItemImgs {
pub fn new(ui: &mut Ui, not_found: Id) -> Self {
let manifest = ItemImagesSpec::load_expect("voxygen.item_image_manifest");
let manifest = ItemImagesSpec::load_expect("voxygen.item_image_manifest");
let map = manifest
.read()
.0

View File

@ -659,7 +659,8 @@ impl Hud {
// Load item images.
let item_imgs = ItemImgs::new(&mut ui, imgs.not_found);
// Load fonts.
let fonts = Fonts::load(&global_state.i18n.read().fonts, &mut ui).expect("Impossible to load fonts!");
let fonts = Fonts::load(&global_state.i18n.read().fonts, &mut ui)
.expect("Impossible to load fonts!");
// Get the server name.
let server = &client.server_info().name;
// Get the id, unwrap is safe because this CANNOT be None at this
@ -2289,9 +2290,7 @@ impl Hud {
}
if self.show.esc_menu {
match EscMenu::new(&self.imgs, &self.fonts, i18n)
.set(self.ids.esc_menu, ui_widgets)
{
match EscMenu::new(&self.imgs, &self.fonts, i18n).set(self.ids.esc_menu, ui_widgets) {
Some(esc_menu::Event::OpenSettings(tab)) => {
self.show.open_setting_tab(tab);
},

View File

@ -135,8 +135,9 @@ impl Localization {
}
impl assets::Asset for Localization {
const EXTENSION: &'static str = "ron";
type Loader = LocalizationLoader;
const EXTENSION: &'static str = "ron";
}
pub struct LocalizationLoader;
@ -166,9 +167,7 @@ pub fn list_localizations() -> Vec<LanguageMetadata> {
assets::load_dir::<Localization>("voxygen.i18n")
.unwrap()
.iter_all()
.filter_map(|(_, lang)| {
lang.ok().map(|e| e.read().metadata.clone())
})
.filter_map(|(_, lang)| lang.ok().map(|e| e.read().metadata.clone()))
.collect()
}

View File

@ -157,19 +157,17 @@ fn main() {
// Load the profile.
let profile = Profile::load();
let i18n = Localization::load(
&i18n_asset_key(&settings.language.selected_language),
)
.unwrap_or_else(|error| {
let selected_language = &settings.language.selected_language;
warn!(
?error,
?selected_language,
"Impossible to load language: change to the default language (English) instead.",
);
settings.language.selected_language = i18n::REFERENCE_LANG.to_owned();
Localization::load_expect(&i18n_asset_key(&settings.language.selected_language))
});
let i18n = Localization::load(&i18n_asset_key(&settings.language.selected_language))
.unwrap_or_else(|error| {
let selected_language = &settings.language.selected_language;
warn!(
?error,
?selected_language,
"Impossible to load language: change to the default language (English) instead.",
);
settings.language.selected_language = i18n::REFERENCE_LANG.to_owned();
Localization::load_expect(&i18n_asset_key(&settings.language.selected_language))
});
i18n.read().log_missing_entries();
// Create window

View File

@ -263,11 +263,7 @@ enum Message {
}
impl Controls {
fn new(
fonts: Fonts,
imgs: Imgs,
selected: Option<CharacterId>,
) -> Self {
fn new(fonts: Fonts, imgs: Imgs, selected: Option<CharacterId>) -> Self {
let version = common::util::DISPLAY_VERSION_LONG.clone();
let alpha = format!("Veloren {}", common::util::DISPLAY_VERSION.as_str());
@ -1467,8 +1463,8 @@ impl CharSelectionUi {
let font = ui::ice::load_font(&i18n.fonts.get("cyri").unwrap().asset_key);
self.ui.clear_fonts(font);
self.controls.fonts = Fonts::load(&i18n.fonts, &mut self.ui)
.expect("Impossible to load fonts!");
self.controls.fonts =
Fonts::load(&i18n.fonts, &mut self.ui).expect("Impossible to load fonts!");
}
pub fn set_scale_mode(&mut self, scale_mode: ui::ScaleMode) {

View File

@ -48,7 +48,8 @@ impl PlayState for MainMenuState {
}
// Updated localization in case the selected language was changed
self.main_menu_ui.update_language(global_state.i18n, &global_state.settings);
self.main_menu_ui
.update_language(global_state.i18n, &global_state.settings);
// Set scale mode in case it was change
self.main_menu_ui
.set_scale_mode(global_state.settings.gameplay.ui_scale);
@ -264,10 +265,8 @@ impl PlayState for MainMenuState {
&global_state.settings.language.selected_language,
));
global_state.i18n.read().log_missing_entries();
self.main_menu_ui.update_language(
global_state.i18n,
&global_state.settings,
);
self.main_menu_ui
.update_language(global_state.i18n, &global_state.settings);
},
#[cfg(feature = "singleplayer")]
MainMenuEvent::StartSingleplayer => {

View File

@ -10,7 +10,7 @@ use crate::{
ui::{
self,
fonts::IcedFonts as Fonts,
ice::{style, widget, Element, IcedUi as Ui, load_font},
ice::{load_font, style, widget, Element, IcedUi as Ui},
img_ids::{ImageGraphic, VoxelGraphic},
Graphic,
},
@ -513,8 +513,8 @@ impl<'a> MainMenuUi {
let i18n = &*i18n.read();
let font = load_font(&i18n.fonts.get("cyri").unwrap().asset_key);
self.ui.clear_fonts(font);
self.controls.fonts = Fonts::load(&i18n.fonts, &mut self.ui)
.expect("Impossible to load fonts!");
self.controls.fonts =
Fonts::load(&i18n.fonts, &mut self.ui).expect("Impossible to load fonts!");
let language_metadatas = crate::i18n::list_localizations();
self.controls.selected_language_index = language_metadatas
.iter()

View File

@ -102,14 +102,13 @@ pub type ColLightInfo = (
pub struct Glsl(String);
impl From<String> for Glsl {
fn from(s: String) -> Glsl {
Glsl(s)
}
fn from(s: String) -> Glsl { Glsl(s) }
}
impl assets::Asset for Glsl {
const EXTENSION: &'static str = "glsl";
type Loader = assets::LoadFrom<String, assets::StringLoader>;
const EXTENSION: &'static str = "glsl";
}
struct Shaders {
@ -164,7 +163,10 @@ struct Shaders {
impl assets::Compound for Shaders {
// TODO: Taking the specifier argument as a base for shaders specifiers
// would allow to use several shaders groups easily
fn load<S: assets::source::Source>(_: &assets::AssetCache<S>, _: &str) -> Result<Shaders, assets::Error> {
fn load<S: assets::source::Source>(
_: &assets::AssetCache<S>,
_: &str,
) -> Result<Shaders, assets::Error> {
Ok(Shaders {
constants: AssetExt::load("voxygen.shaders.include.constants")?,
globals: AssetExt::load("voxygen.shaders.include.globals")?,
@ -185,8 +187,12 @@ impl assets::Compound for Shaders {
figure_vert: AssetExt::load("voxygen.shaders.figure-vert")?,
terrain_point_shadow_vert: AssetExt::load("voxygen.shaders.light-shadows-vert")?,
terrain_directed_shadow_vert: AssetExt::load("voxygen.shaders.light-shadows-directed-vert")?,
figure_directed_shadow_vert: AssetExt::load("voxygen.shaders.light-shadows-figure-vert")?,
terrain_directed_shadow_vert: AssetExt::load(
"voxygen.shaders.light-shadows-directed-vert",
)?,
figure_directed_shadow_vert: AssetExt::load(
"voxygen.shaders.light-shadows-figure-vert",
)?,
directed_shadow_frag: AssetExt::load("voxygen.shaders.light-shadows-directed-frag")?,
skybox_vert: AssetExt::load("voxygen.shaders.skybox-vert")?,
@ -323,12 +329,7 @@ impl Renderer {
point_shadow_pipeline,
terrain_directed_shadow_pipeline,
figure_directed_shadow_pipeline,
) = create_pipelines(
&mut factory,
&shaders.read(),
&mode,
shadow_views.is_some(),
)?;
) = create_pipelines(&mut factory, &shaders.read(), &mode, shadow_views.is_some())?;
let (
tgt_color_view,
@ -1994,7 +1995,9 @@ fn create_pipelines(
&match mode.fluid {
FluidMode::Cheap => shaders.fluid_frag_cheap,
FluidMode::Shiny => shaders.fluid_frag_shiny,
}.read().0,
}
.read()
.0,
&include_ctx,
gfx::state::CullFace::Nothing,
)?;

View File

@ -128,8 +128,9 @@ struct SpriteConfig<Model> {
struct SpriteSpec(sprite::sprite_kind::PureCases<Option<SpriteConfig<String>>>);
impl assets::Asset for SpriteSpec {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
}
/// Function executed by worker threads dedicated to chunk meshing.
@ -276,7 +277,8 @@ impl<V: RectRasterableVol> Terrain<V> {
#[allow(clippy::float_cmp)] // TODO: Pending review in #587
pub fn new(renderer: &mut Renderer) -> Self {
// Load all the sprite config data.
let sprite_config = Arc::<SpriteSpec>::load_expect("voxygen.voxel.sprite_manifest").cloned();
let sprite_config =
Arc::<SpriteSpec>::load_expect("voxygen.voxel.sprite_manifest").cloned();
// Create a new mpsc (Multiple Produced, Single Consumer) pair for communicating
// with worker threads that are meshing chunks.

View File

@ -119,11 +119,7 @@ impl SessionState {
self.hud.new_message(m);
},
client::Event::InventoryUpdated(inv_event) => {
let sfx_triggers = self
.scene
.sfx_mgr
.triggers
.read();
let sfx_triggers = self.scene.sfx_mgr.triggers.read();
let sfx_trigger_item = sfx_triggers.get_key_value(&SfxEvent::from(&inv_event));
global_state.audio.emit_sfx_item(sfx_trigger_item);
@ -167,7 +163,11 @@ impl SessionState {
client::Event::Kicked(reason) => {
global_state.info_message = Some(format!(
"{}: {}",
global_state.i18n.read().get("main.login.kicked").to_string(),
global_state
.i18n
.read()
.get("main.login.kicked")
.to_string(),
reason
));
return Ok(TickAction::Disconnect);
@ -674,8 +674,13 @@ impl PlayState for SessionState {
Ok(TickAction::Continue) => {}, // Do nothing
Ok(TickAction::Disconnect) => return PlayStateResult::Pop, // Go to main menu
Err(err) => {
global_state.info_message =
Some(global_state.i18n.read().get("common.connection_lost").to_owned());
global_state.info_message = Some(
global_state
.i18n
.read()
.get("common.connection_lost")
.to_owned(),
);
error!("[session] Failed to tick the scene: {:?}", err);
return PlayStateResult::Pop;
@ -1010,9 +1015,9 @@ impl PlayState for SessionState {
HudEvent::ChangeLanguage(new_language) => {
global_state.settings.language.selected_language =
new_language.language_identifier;
global_state.i18n = Localization::load_expect(
&i18n_asset_key(&global_state.settings.language.selected_language),
);
global_state.i18n = Localization::load_expect(&i18n_asset_key(
&global_state.settings.language.selected_language,
));
global_state.i18n.read().log_missing_entries();
self.hud.update_fonts(&global_state.i18n.read());
},

View File

@ -5,7 +5,10 @@ use crate::{
};
use common::assets::{self, AssetExt};
use glyph_brush::GlyphBrushBuilder;
use std::{borrow::Cow, cell::{RefCell, RefMut}};
use std::{
borrow::Cow,
cell::{RefCell, RefMut},
};
use vek::*;
// Multiplied by current window size
@ -31,13 +34,12 @@ impl assets::Loader<FontAsset> for FontLoader {
}
impl assets::Asset for FontAsset {
const EXTENSION: &'static str = "ttf";
type Loader = FontLoader;
const EXTENSION: &'static str = "ttf";
}
pub fn load_font(specifier: &str) -> Font {
FontAsset::load_expect(specifier).read().0.clone()
}
pub fn load_font(specifier: &str) -> Font { FontAsset::load_expect(specifier).read().0.clone() }
#[derive(Clone, Copy, Default)]
pub struct FontId(pub(super) glyph_brush::FontId);
@ -142,12 +144,11 @@ impl Cache {
pub struct RawFont(pub Vec<u8>);
impl From<Vec<u8>> for RawFont {
fn from(raw: Vec<u8>) -> RawFont {
RawFont(raw)
}
fn from(raw: Vec<u8>) -> RawFont { RawFont(raw) }
}
impl assets::Asset for RawFont {
const EXTENSION: &'static str = "ttf";
type Loader = assets::LoadFrom<Vec<u8>, assets::BytesLoader>;
const EXTENSION: &'static str = "ttf";
}

View File

@ -4,7 +4,7 @@ pub mod component;
mod renderer;
pub mod widget;
pub use cache::{Font, FontId, RawFont, load_font};
pub use cache::{load_font, Font, FontId, RawFont};
pub use graphic::{Id, Rotation};
pub use iced::Event;
pub use iced_winit::conversion::window_event;

View File

@ -26,8 +26,8 @@ pub struct IndexOwned {
colors: Arc<Colors>,
index: Arc<Index>,
/// Stored separatly so `colors` is only updated when `reload_colors_if_changed`
/// is called
/// Stored separatly so `colors` is only updated when
/// `reload_colors_if_changed` is called
colors_handle: AssetHandle<Arc<Colors>>,
}

View File

@ -183,7 +183,8 @@ pub fn apply_caves_to(canvas: &mut Canvas) {
&& cave_base < surface_z as i32 - 25
{
let lottery = Lottery::<SpriteKind>::load_expect("common.cave_scatter").read();
let kind = *lottery.choose_seeded(RandomField::new(info.index().seed + 1).get(wpos2d.into()));
let kind = *lottery
.choose_seeded(RandomField::new(info.index().seed + 1).get(wpos2d.into()));
canvas.map(Vec3::new(wpos2d.x, wpos2d.y, cave_base), |block| {
block.with_sprite(kind)
});

View File

@ -7,7 +7,7 @@ use crate::{
};
use common::{
assets::AssetHandle,
terrain::{Structure, StructuresGroup, Block, BlockKind},
terrain::{Block, BlockKind, Structure, StructuresGroup},
vol::ReadVol,
};
use hashbrown::HashMap;
@ -24,7 +24,8 @@ lazy_static! {
static ref BAOBABS: AssetHandle<StructuresGroup> = Structure::load_group("baobabs");
static ref FRUIT_TREES: AssetHandle<StructuresGroup> = Structure::load_group("fruit_trees");
static ref BIRCHES: AssetHandle<StructuresGroup> = Structure::load_group("birch");
static ref MANGROVE_TREES: AssetHandle<StructuresGroup> = Structure::load_group("mangrove_trees");
static ref MANGROVE_TREES: AssetHandle<StructuresGroup> =
Structure::load_group("mangrove_trees");
static ref QUIRKY: AssetHandle<StructuresGroup> = Structure::load_group("quirky");
static ref QUIRKY_DRY: AssetHandle<StructuresGroup> = Structure::load_group("quirky_dry");
static ref SWAMP_TREES: AssetHandle<StructuresGroup> = Structure::load_group("swamp_trees");

View File

@ -72,8 +72,9 @@ pub struct Colors {
}
impl assets::Asset for Colors {
const EXTENSION: &'static str = "ron";
type Loader = assets::RonLoader;
const EXTENSION: &'static str = "ron";
}
impl World {

View File

@ -246,8 +246,9 @@ pub enum WorldFile {
}
impl assets::Asset for WorldFile {
const EXTENSION: &'static str = "bin";
type Loader = assets::BincodeLoader;
const EXTENSION: &'static str = "bin";
}
/// Data for the most recent map type. Update this when you add a new map
@ -413,22 +414,24 @@ impl WorldSim {
map.into_modern()
},
FileOpts::LoadAsset(ref specifier) => {
match WorldFile::load_owned(&specifier) {
Ok(map) => map.into_modern(),
Err(err) => {
match err {
assets::Error::Io(e) => {
warn!(?e, ?specifier, "Couldn't read asset specifier for maps");
}
assets::Error::Conversion(e) => {
warn!(?e, "Couldn't parse modern map. Maybe you meant to try a legacy load?");
}
assets::Error::NoDefaultValue => unreachable!(),
}
return None;
FileOpts::LoadAsset(ref specifier) => match WorldFile::load_owned(&specifier) {
Ok(map) => map.into_modern(),
Err(err) => {
match err {
assets::Error::Io(e) => {
warn!(?e, ?specifier, "Couldn't read asset specifier for maps");
},
assets::Error::Conversion(e) => {
warn!(
?e,
"Couldn't parse modern map. Maybe you meant to try a legacy \
load?"
);
},
assets::Error::NoDefaultValue => unreachable!(),
}
}
return None;
},
},
FileOpts::Generate | FileOpts::Save => return None,
};