Skip to content

Commit

Permalink
Fix some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Lauzier committed Jun 20, 2021
1 parent 8713588 commit 14ffe14
Show file tree
Hide file tree
Showing 35 changed files with 134 additions and 119 deletions.
5 changes: 1 addition & 4 deletions amethyst_animation/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use amethyst_assets::{
},
Asset, AssetStorage, Handle,
};
use amethyst_core::{
ecs::*,
Transform,
};
use amethyst_core::{ecs::*, Transform};
use derivative::Derivative;
use fnv::FnvHashMap;
use log::debug;
Expand Down
6 changes: 4 additions & 2 deletions amethyst_animation/src/systems/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ where

// sampling is running, update duration and check end condition
Running(duration) => {
let current_dur =
duration + Duration::from_secs_f32(time.delta_time().as_secs_f32() * control.rate_multiplier);
let current_dur = duration
+ Duration::from_secs_f32(
time.delta_time().as_secs_f32() * control.rate_multiplier,
);
let last_frame = sampler
.input
.last()
Expand Down
12 changes: 7 additions & 5 deletions amethyst_assets/src/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::{prefab::PrefabImporter, simple_importer::get_source_importers};
use amethyst_error::Error;
use distill::daemon::AssetDaemon as AtelierAssetDaemon;
use std::{
net::{AddrParseError, SocketAddr},
path::PathBuf,
thread::JoinHandle,
};

use amethyst_error::Error;
use distill::daemon::AssetDaemon as AtelierAssetDaemon;
use structopt::StructOpt;
use tokio::sync::oneshot::Sender;

use crate::{prefab::PrefabImporter, simple_importer::get_source_importers};

/// Parameters to the asset daemon.
///
/// # Examples
Expand Down Expand Up @@ -134,15 +136,15 @@ impl StartedDaemon {
fn stop_and_join(&mut self) -> AssetDaemonState {
self.shutdown
.take()
.ok_or(Error::from_string("Shutdown Sender not present"))
.ok_or_else(|| Error::from_string("Shutdown Sender not present"))
.and_then(|s| {
s.send(true)
.map_err(|_| Error::from_string("failure sending shutdown to assetdaemon"))
})
.and_then(|_| {
self.join_handle
.take()
.ok_or(Error::from_string("JoinHandle not present"))
.ok_or_else(|| Error::from_string("JoinHandle not present"))
})
.and_then(|h| {
h.join()
Expand Down
1 change: 0 additions & 1 deletion amethyst_assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ pub use {erased_serde, inventory, lazy_static};
#[cfg(feature = "asset-daemon")]
/// internal AssetDaemon control
pub use crate::daemon::AssetDaemon;

#[cfg(feature = "json")]
pub use crate::json::JsonFormat;
pub use crate::{
Expand Down
32 changes: 17 additions & 15 deletions amethyst_assets/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{
collections::HashMap,
error::Error,
fs::File,
path::PathBuf,
ops::{Deref, DerefMut},
path::PathBuf,
sync::Arc,
};

Expand All @@ -20,12 +20,12 @@ pub(crate) use distill_loader::LoadHandle;
use distill_loader::{
crossbeam_channel::{unbounded, Receiver, Sender, TryRecvError},
handle::{AssetHandle, GenericHandle, Handle, RefOp, SerdeContext, WeakHandle},
io::LoaderIO,
storage::{
AssetLoadOp, AtomicHandleAllocator, HandleAllocator, IndirectIdentifier, IndirectionTable,
LoaderInfoProvider,
},
io::LoaderIO,
AssetTypeId, Loader as DistillLoader, RpcIO, PackfileReader,
AssetTypeId, Loader as DistillLoader, PackfileReader, RpcIO,
};
pub use distill_loader::{storage::LoadStatus, AssetUuid};
use log::debug;
Expand Down Expand Up @@ -157,32 +157,35 @@ pub struct DefaultLoader {
pub(crate) indirection_table: IndirectionTable,
}


impl Default for DefaultLoader {
fn default() -> Self {
Self::new(true, None, None)
}
}


impl DefaultLoader {
fn new(loader_io_use_rpc: bool, connect_string: Option<String>, packfile_path: Option<PathBuf> ) -> Self {
fn new(
loader_io_use_rpc: bool,
connect_string: Option<String>,
packfile_path: Option<PathBuf>,
) -> Self {
let (tx, rx) = unbounded();
let handle_allocator = Arc::new(AtomicHandleAllocator::default());
let loader_io: Box<dyn LoaderIO> = if loader_io_use_rpc {
log::info!("Using RpcIO");
let rpc_io = connect_string.and_then(|cs| RpcIO::new(cs).ok()).unwrap_or_else(RpcIO::default);
let rpc_io = connect_string
.and_then(|cs| RpcIO::new(cs).ok())
.unwrap_or_else(RpcIO::default);
Box::new(rpc_io)
} else {
log::info!("Using PackfileIO");
let packfile_io = packfile_path.map(|pfp| File::open(pfp).expect("Could not open packfile"))
.and_then(|pf| PackfileReader::new(pf).ok()).expect("packfile not found");
let packfile_io = packfile_path
.map(|pfp| File::open(pfp).expect("Could not open packfile"))
.and_then(|pf| PackfileReader::new(pf).ok())
.expect("packfile not found");
Box::new(packfile_io)
};
let loader = DistillLoader::new_with_handle_allocator(
loader_io,
handle_allocator.clone(),
);
let loader = DistillLoader::new_with_handle_allocator(loader_io, handle_allocator.clone());
Self {
indirection_table: loader.indirection_table(),
loader,
Expand All @@ -194,7 +197,6 @@ impl DefaultLoader {
}
}


impl Loader for DefaultLoader {
fn load_asset_generic(&self, id: AssetUuid) -> GenericHandle {
GenericHandle::new(self.ref_sender.clone(), self.loader.add_ref(id))
Expand Down Expand Up @@ -393,8 +395,8 @@ impl AssetStorageMap {
storages_by_asset_uuid.insert(t.asset_uuid, t.clone());
}
AssetStorageMap {
storages_by_asset_uuid,
storages_by_data_uuid,
storages_by_asset_uuid,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion amethyst_assets/src/prefab/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn prefab_spawning_tick(world: &mut World, resources: &mut Resources) {
let entity_map = world.clone_from(
&prefab.world,
&query::any(),
&mut component_registry.spawn_clone_impl(&resources, &prev_entity_map),
&mut component_registry.spawn_clone_impl(resources, &prev_entity_map),
);

let live_entities: HashSet<Entity, EntityHasher> = entity_map.values().copied().collect();
Expand Down
2 changes: 1 addition & 1 deletion amethyst_assets/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl LoadNotifier {
}

if let Some(tracker) = self.tracker {
tracker.fail(self.load_handle.0, &"", "".to_string(), error);
tracker.fail(self.load_handle.0, "", "".to_string(), error);
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions amethyst_controls/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ impl System for FlyMovementSystem {
#[cfg(feature = "profiler")]
profile_scope!("fly_movement_system");

let x = get_input_axis_simple(&self.horizontal_axis, &input);
let y = get_input_axis_simple(&self.vertical_axis, &input);
let z = get_input_axis_simple(&self.longitudinal_axis, &input);
let x = get_input_axis_simple(&self.horizontal_axis, input);
let y = get_input_axis_simple(&self.vertical_axis, input);
let z = get_input_axis_simple(&self.longitudinal_axis, input);

if let Some(dir) = Unit::try_new(Vector3::new(x, y, z), convert(1.0e-6)) {
for (_, transform) in controls.iter_mut(world) {
Expand Down Expand Up @@ -80,14 +80,11 @@ impl System for ArcBallRotationSystem {
.0
.iter(world)
.map(|ctrl| {
match world
world
.entry_ref(ctrl.target)
.ok()
.and_then(|e| e.into_component::<Transform>().ok())
{
Some(trans) => Some((ctrl.target, *trans)),
None => None,
}
.map(|trans| (ctrl.target, *trans))
})
.filter(|t| t.is_some())
.map(|t| t.unwrap())
Expand Down
2 changes: 1 addition & 1 deletion amethyst_core/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where

/// Create a new `Plane` from a point normal representation
pub fn from_point_vectors(point: &Point3<T>, v1: &Vector3<T>, v2: &Vector3<T>) -> Self {
Self::from_point_normal(point, &v1.cross(&v2))
Self::from_point_normal(point, &v1.cross(v2))
}

/// Create a `Plane` which is facing along the X-Axis at the provided coordinate.
Expand Down
2 changes: 1 addition & 1 deletion amethyst_core/src/transform/parent_update_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl System for ParentUpdateSystem {
// Deleted `Parents` (ie. Entities with a `Children` but no `Transform`).
for (entity, children) in queries.2.iter(world) {
log::trace!("The entity {:?} doesn't have a Transform", entity);
if children_additions.remove(&entity).is_none() {
if children_additions.remove(entity).is_none() {
log::trace!(" > It needs to be remove from the ECS.");
for child_entity in children.0.iter() {
commands.remove_component::<Parent>(*child_entity);
Expand Down
10 changes: 6 additions & 4 deletions amethyst_core/src/transform/transform_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ impl System for TransformSystem {
transform.global_matrix = transform.matrix();
debug_assert!(
transform.is_finite(),
"Entity {:?} had a non-finite `Transform` {:?}",
entity, transform
"Entity {:?} had a non-finite `Transform` {:?}",
entity,
transform
);
}

Expand Down Expand Up @@ -73,8 +74,9 @@ impl System for TransformSystem {
transform.global_matrix = transform.parent_matrix * transform.matrix();
debug_assert!(
transform.is_finite(),
"Entity {:?} had a non-finite `Transform` {:?}",
entity, transform
"Entity {:?} had a non-finite `Transform` {:?}",
entity,
transform
);
}
},
Expand Down
45 changes: 27 additions & 18 deletions amethyst_gltf/src/importer/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,23 @@ fn load_texture_with_factor(
srgb: bool,
) -> Result<(TextureBuilder<'static>, [f32; 4]), Error> {
match texture {
Some(info) => Ok((
load_texture(&info.texture(), buffers, srgb)?.with_mip_levels(MipLevels::GenerateAuto),
factor,
)),
None => Ok((
if srgb {
load_from_srgba(Srgba::new(factor[0], factor[1], factor[2], factor[3]))
} else {
load_from_linear_rgba(LinSrgba::new(factor[0], factor[1], factor[2], factor[3]))
},
[1.0, 1.0, 1.0, 1.0],
)),
Some(info) => {
Ok((
load_texture(&info.texture(), buffers, srgb)?
.with_mip_levels(MipLevels::GenerateAuto),
factor,
))
}
None => {
Ok((
if srgb {
load_from_srgba(Srgba::new(factor[0], factor[1], factor[2], factor[3]))
} else {
load_from_linear_rgba(LinSrgba::new(factor[0], factor[1], factor[2], factor[3]))
},
[1.0, 1.0, 1.0, 1.0],
))
}
}
}

Expand Down Expand Up @@ -261,9 +266,11 @@ fn load_normal(
) -> (AssetUuid, ImportedAsset) {
let normal: TextureData = {
match normal_texture {
Some(normal_texture) => load_texture(&normal_texture.texture(), buffers, false)
.map(|data| data.into())
.expect("The mapping between the TextureBuilder and TextureDate did not work"),
Some(normal_texture) => {
load_texture(&normal_texture.texture(), buffers, false)
.map(|data| data.into())
.expect("The mapping between the TextureBuilder and TextureDate did not work")
}
None => {
// Default normal Texture
load_from_linear_rgba(LinSrgba::new(0.5, 0.5, 1.0, 1.0)).into()
Expand Down Expand Up @@ -298,9 +305,11 @@ fn load_occlusion(
) -> (AssetUuid, ImportedAsset) {
let occlusion: TextureData = {
match occlusion_texture {
Some(normal_texture) => load_texture(&normal_texture.texture(), buffers, false)
.map(|data| data.into())
.expect("The mapping between the TextureBuilder and TextureDate did not work"),
Some(normal_texture) => {
load_texture(&normal_texture.texture(), buffers, false)
.map(|data| data.into())
.expect("The mapping between the TextureBuilder and TextureDate did not work")
}
None => {
// Default occlusion Texture
load_from_linear_rgba(LinSrgba::new(1.0, 1.0, 1.0, 1.0)).into()
Expand Down
7 changes: 1 addition & 6 deletions amethyst_input/src/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,7 @@ impl InputHandler {
fn alloc_controller_id(&self) -> u32 {
let mut i = 0u32;
loop {
if self
.connected_controllers
.iter()
.find(|ids| ids.0 == i)
.is_none()
{
if !self.connected_controllers.iter().any(|ids| ids.0 == i) {
return i;
}
i += 1;
Expand Down
4 changes: 2 additions & 2 deletions amethyst_input/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ pub fn is_close_requested(event: &Event<'_, ()>) -> bool {
/// If the name is None, it will return the default value of the axis (0.0).
pub fn get_input_axis_simple(name: &Option<Cow<'static, str>>, input: &InputHandler) -> f32 {
name.as_ref()
.and_then(|ref n| input.axis_value(n))
.and_then(|n| input.axis_value(n))
.unwrap_or(0.0)
}

/// Gets the action active status from the `InputHandler`.
/// If the action name is None, it will default to false.
pub fn get_action_simple(name: &Option<Cow<'static, str>>, input: &InputHandler) -> bool {
name.as_ref()
.and_then(|ref n| input.action_is_down(n))
.and_then(|n| input.action_is_down(n))
.unwrap_or(false)
}

Expand Down
Loading

0 comments on commit 14ffe14

Please sign in to comment.