Skip to content

Commit

Permalink
Merge pull request amethyst#2695 from remilauzier/main
Browse files Browse the repository at this point in the history
Fix some clippy::pedantic warnings
  • Loading branch information
dawnlarsson authored Jul 5, 2021
2 parents abc8305 + e0f86fa commit 89ed34b
Show file tree
Hide file tree
Showing 126 changed files with 715 additions and 511 deletions.
7 changes: 4 additions & 3 deletions amethyst_animation/src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{hash::Hash, marker};

use amethyst_core::ecs::*;
use amethyst_core::ecs::{DispatcherBuilder, Resources, SystemBundle, World};
use derivative::Derivative;
use marker::PhantomData;

use crate::{resources::AnimationSampling, skinning::VertexSkinningSystem};
use crate::{resources::AnimationSampling, skinning::VertexSkinningSystem, bundle};

/// Bundle for vertex skinning
///
Expand All @@ -15,8 +15,9 @@ pub struct VertexSkinningBundle;

impl VertexSkinningBundle {
/// Create a new sampling bundle
#[must_use]
pub fn new() -> Self {
Default::default()
bundle::VertexSkinningBundle::default()
}
}

Expand Down
9 changes: 5 additions & 4 deletions amethyst_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@
html_logo_url = "https://amethyst.rs/brand/logo-standard.svg",
html_root_url = "https://docs.amethyst.rs/stable"
)]
#![warn(
#![deny(
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
rust_2018_compatibility
rust_2018_compatibility,
clippy::all
)]
#![warn(clippy::all)]
#![allow(clippy::new_without_default)]
#![warn(clippy::pedantic)]
#![allow(clippy::new_without_default, clippy::module_name_repetitions)]

pub use minterpolate::{InterpolationFunction, InterpolationPrimitive};

Expand Down
6 changes: 3 additions & 3 deletions amethyst_animation/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use uuid::Uuid;

impl TypeUuid for Sampler<MaterialPrimitive> {
const UUID: type_uuid::Bytes =
*Uuid::from_u128(241595315345789436729706626074361057644).as_bytes();
*Uuid::from_u128(241_595_315_345_789_436_729_706_626_074_361_057_644).as_bytes();
}
register_asset_type!(Sampler<MaterialPrimitive> => Sampler<MaterialPrimitive>; AssetProcessorSystem<Sampler<MaterialPrimitive>>);

Expand Down Expand Up @@ -110,7 +110,7 @@ fn texture_offset(u: (f32, f32), v: (f32, f32)) -> TextureOffset {

impl TypeUuid for Animation<Material> {
const UUID: type_uuid::Bytes =
*Uuid::from_u128(83822419317134738729184959262618377566).as_bytes();
*Uuid::from_u128(83_822_419_317_134_738_729_184_959_262_618_377_566).as_bytes();
}
register_asset_type!(Animation<Material> => Animation<Material>; AssetProcessorSystem<Animation<Material>>);

Expand Down Expand Up @@ -145,7 +145,7 @@ impl AnimationSampling for Material {
}

(MaterialChannel::UvOffset, MaterialPrimitive::Offset(u, v)) => {
self.uv_offset = texture_offset(*u, *v)
self.uv_offset = texture_offset(*u, *v);
}

_ => panic!("Bad combination of data in Material animation"),
Expand Down
72 changes: 43 additions & 29 deletions amethyst_animation/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use amethyst_assets::{
},
Asset, AssetStorage, Handle,
};
use amethyst_core::{ecs::*, Transform};
use amethyst_core::{
ecs::{CommandBuffer, Entity, EntityStore, SubWorld},
Transform,
};
use derivative::Derivative;
use fnv::FnvHashMap;
use log::debug;
Expand Down Expand Up @@ -144,11 +147,13 @@ where
T: AnimationSampling,
{
/// Create a new hierarchy
#[must_use]
pub fn new() -> Self {
Self::default()
}

/// Create a new hierarchy containing a single given entity
#[must_use]
pub fn new_single(index: usize, entity: Entity) -> Self {
AnimationHierarchy {
nodes: hashmap![index => entity],
Expand All @@ -157,6 +162,7 @@ where
}

/// Create a new hierarchy with the given entity map
#[must_use]
pub fn new_many(nodes: FnvHashMap<usize, Entity>) -> Self {
AnimationHierarchy {
nodes,
Expand Down Expand Up @@ -185,7 +191,7 @@ where
// d8d687ef-da49-a839-5066-c0d703b99bdc
impl TypeUuid for AnimationSet<usize, Transform> {
const UUID: type_uuid::Bytes =
*Uuid::from_u128(288227155745652393685123926184903154652).as_bytes();
*Uuid::from_u128(288_227_155_745_652_393_685_123_926_184_903_154_652).as_bytes();
}

impl SerdeDiff for AnimationSet<usize, Transform> {
Expand Down Expand Up @@ -241,6 +247,7 @@ where
T: AnimationSampling,
{
/// Create new empty animation
#[must_use]
pub fn new() -> Self {
Animation { nodes: vec![] }
}
Expand Down Expand Up @@ -307,11 +314,13 @@ pub enum ControlState {

impl ControlState {
/// Is the state `Running`
#[must_use]
pub fn is_running(&self) -> bool {
matches!(*self, ControlState::Running(_))
}

/// Is the state `Paused`
#[must_use]
pub fn is_paused(&self) -> bool {
matches!(*self, ControlState::Paused(_))
}
Expand Down Expand Up @@ -411,6 +420,7 @@ where
}

/// Check if set is empty
#[must_use]
pub fn is_empty(&self) -> bool {
self.samplers.is_empty()
}
Expand Down Expand Up @@ -479,6 +489,7 @@ where
}

/// Check if a control set can be terminated
#[must_use]
pub fn check_termination(&self, control_id: u64) -> bool {
self.samplers
.iter()
Expand Down Expand Up @@ -520,6 +531,7 @@ where
}

/// Get the max running duration of the control set
#[must_use]
pub fn get_running_duration(&self, control_id: u64) -> Option<f32> {
self.samplers
.iter()
Expand Down Expand Up @@ -548,10 +560,9 @@ fn set_step_state<T>(
(Some(index), &StepDirection::Forward) if index >= sampler.input.len() - 1 => {
sampler.input.len() - 1
}
(Some(0), &StepDirection::Backward) => 0,
(Some(0), &StepDirection::Backward) | (None, _) => 0,
(Some(index), &StepDirection::Forward) => index + 1,
(Some(index), &StepDirection::Backward) => index - 1,
(None, _) => 0,
};
control.state = ControlState::Running(Duration::from_secs_f32(sampler.input[new_index]));
}
Expand Down Expand Up @@ -623,6 +634,7 @@ where
T: AnimationSampling,
{
/// Creates a new `AnimationControl`
#[must_use]
pub fn new(
animation: Handle<Animation<T>>,
end: EndControl,
Expand Down Expand Up @@ -700,6 +712,7 @@ where
T: AnimationSampling,
{
/// Is the animation set empty?
#[must_use]
pub fn is_empty(&self) -> bool {
self.animations.is_empty() && self.deferred_animations.is_empty()
}
Expand All @@ -708,20 +721,20 @@ where
///
/// This should be used with care, as this will leave all linked samplers in place. If in
/// doubt, use `abort()` instead.
pub fn remove(&mut self, id: I) -> &mut Self {
if let Some(index) = self.animations.iter().position(|a| a.0 == id) {
pub fn remove(&mut self, id: &I) -> &mut Self {
if let Some(index) = self.animations.iter().position(|a| a.0 == *id) {
self.animations.remove(index);
}
self
}

fn set_command(&mut self, id: I, command: AnimationCommand<T>) -> &mut Self {
if let Some(&mut (_, ref mut control)) = self.animations.iter_mut().find(|a| a.0 == id) {
fn set_command(&mut self, id: &I, command: AnimationCommand<T>) -> &mut Self {
if let Some(&mut (_, ref mut control)) = self.animations.iter_mut().find(|a| a.0 == *id) {
control.command = command;
} else if let Some(ref mut control) = self
.deferred_animations
.iter_mut()
.find(|a| a.animation_id == id)
.find(|a| a.animation_id == *id)
{
control.control.command = command;
}
Expand All @@ -730,18 +743,18 @@ where
}

/// Start animation if it exists
pub fn start(&mut self, id: I) -> &mut Self {
self.set_command(id, AnimationCommand::Start)
pub fn start(&mut self, id: &I) -> &mut Self {
self.set_command(&id, AnimationCommand::Start)
}

/// Pause animation if it exists
pub fn pause(&mut self, id: I) -> &mut Self {
self.set_command(id, AnimationCommand::Pause)
pub fn pause(&mut self, id: &I) -> &mut Self {
self.set_command(&id, AnimationCommand::Pause)
}

/// Toggle animation if it exists
pub fn toggle(&mut self, id: I) -> &mut Self {
if let Some(&mut (_, ref mut control)) = self.animations.iter_mut().find(|a| a.0 == id) {
pub fn toggle(&mut self, id: &I) -> &mut Self {
if let Some(&mut (_, ref mut control)) = self.animations.iter_mut().find(|a| a.0 == *id) {
if control.state.is_running() {
control.command = AnimationCommand::Pause;
} else {
Expand All @@ -753,14 +766,14 @@ where
}

/// Set animation rate
pub fn set_rate(&mut self, id: I, rate_multiplier: f32) -> &mut Self {
if let Some(&mut (_, ref mut control)) = self.animations.iter_mut().find(|a| a.0 == id) {
pub fn set_rate(&mut self, id: &I, rate_multiplier: f32) -> &mut Self {
if let Some(&mut (_, ref mut control)) = self.animations.iter_mut().find(|a| a.0 == *id) {
control.rate_multiplier = rate_multiplier;
}
if let Some(ref mut control) = self
.deferred_animations
.iter_mut()
.find(|a| a.animation_id == id)
.find(|a| a.animation_id == *id)
{
control.control.rate_multiplier = rate_multiplier;
}
Expand All @@ -769,23 +782,23 @@ where
}

/// Step animation
pub fn step(&mut self, id: I, direction: StepDirection) -> &mut Self {
self.set_command(id, AnimationCommand::Step(direction))
pub fn step(&mut self, id: &I, direction: StepDirection) -> &mut Self {
self.set_command(&id, AnimationCommand::Step(direction))
}

/// Set animation input value (point of interpolation)
pub fn set_input(&mut self, id: I, input: f32) -> &mut Self {
self.set_command(id, AnimationCommand::SetInputValue(input))
pub fn set_input(&mut self, id: &I, input: f32) -> &mut Self {
self.set_command(&id, AnimationCommand::SetInputValue(input))
}

/// Set blend weights
pub fn set_blend_weight(&mut self, id: I, weights: Vec<(usize, T::Channel, f32)>) -> &mut Self {
self.set_command(id, AnimationCommand::SetBlendWeights(weights))
pub fn set_blend_weight(&mut self, id: &I, weights: Vec<(usize, T::Channel, f32)>) -> &mut Self {
self.set_command(&id, AnimationCommand::SetBlendWeights(weights))
}

/// Abort animation
pub fn abort(&mut self, id: I) -> &mut Self {
self.set_command(id, AnimationCommand::Abort)
pub fn abort(&mut self, id: &I) -> &mut Self {
self.set_command(&id, AnimationCommand::Abort)
}

/// Add animation with the given id, unless it already exists
Expand Down Expand Up @@ -849,8 +862,8 @@ where
}

/// Check if there is an animation with the given id in the set
pub fn has_animation(&self, id: I) -> bool {
self.animations.iter().any(|a| a.0 == id)
pub fn has_animation(&self, id: &I) -> bool {
self.animations.iter().any(|a| a.0 == *id)
}
}

Expand Down Expand Up @@ -888,6 +901,7 @@ where
T: AnimationSampling,
{
/// Create
#[must_use]
pub fn new() -> Self {
AnimationSet {
animations: FnvHashMap::default(),
Expand All @@ -911,7 +925,7 @@ register_component_type!(AnimationSet<usize, Transform>);
// d8160db6-6dc5-49fd-4c08-8b81739b175c
impl TypeUuid for AnimationHierarchy<Transform> {
const UUID: type_uuid::Bytes =
*Uuid::from_u128(287227755745252393685123926184901154652).as_bytes();
*Uuid::from_u128(287_227_755_745_252_393_685_123_926_184_901_154_652).as_bytes();
}

impl SerdeDiff for AnimationHierarchy<Transform> {
Expand Down
2 changes: 1 addition & 1 deletion amethyst_animation/src/skinning/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use amethyst_assets::{
SerdeDiff,
},
};
use amethyst_core::{ecs::*, math::Matrix4};
use amethyst_core::{ecs::Entity, math::Matrix4};
use type_uuid::TypeUuid;

/// Joint, attach to an entity with a `Transform`
Expand Down
9 changes: 4 additions & 5 deletions amethyst_animation/src/skinning/systems.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashSet;

use amethyst_core::{
ecs::*,
ecs::{Entity, EntityStore, IntoQuery, ParallelRunnable, Read, System, SystemBuilder, maybe_changed},
math::{convert, Matrix4},
transform::Transform,
};
Expand All @@ -10,7 +10,7 @@ use log::error;
#[cfg(feature = "profiler")]
use thread_profiler::profile_scope;

use super::resources::*;
use super::resources::{Joint, Skin};

/// System for performing vertex skinning.
///
Expand Down Expand Up @@ -50,7 +50,7 @@ impl System for VertexSkinningSystem {
let mut q = <(Entity, &Transform, &mut JointTransforms)>::query();
let (mut left, mut right) = world.split_for_query(&q);

for entity in updated_skins.iter() {
for entity in &updated_skins {
if let Ok(mut entry) = right.entry_mut(*entity) {
if let Ok(skin) = entry.get_component_mut::<Skin>() {
// Compute the joint global_transforms
Expand All @@ -60,7 +60,7 @@ impl System for VertexSkinningSystem {
skin.joints
.iter()
.zip(skin.inverse_bind_matrices.iter())
.map(|(joint_entity, inverse_bind_matrix)| {
.filter_map(|(joint_entity, inverse_bind_matrix)| {
if let Ok(transform) =
global_transforms.get(&left, *joint_entity)
{
Expand All @@ -70,7 +70,6 @@ impl System for VertexSkinningSystem {
None
}
})
.flatten()
.map(|(global, inverse_bind_matrix)| {
global.1.global_matrix()
* inverse_bind_matrix
Expand Down
6 changes: 3 additions & 3 deletions amethyst_animation/src/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};

use crate::{Animation, AnimationSampling, BlendMethod, Sampler};

/// Sampler primitive for SpriteRender animations
/// Sampler primitive for `SpriteRender` animations
/// Note that sprites can only ever be animated with `Step`, or a panic will occur.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub enum SpriteRenderPrimitive {
Expand All @@ -27,7 +27,7 @@ use uuid::Uuid;
// 8716643e-4d3a-11eb-bdd2-d7a177713b84
impl TypeUuid for Sampler<SpriteRenderPrimitive> {
const UUID: type_uuid::Bytes =
*Uuid::from_u128(179562043138858398183947466578368478084).as_bytes();
*Uuid::from_u128(179_562_043_138_858_398_183_947_466_578_368_478_084).as_bytes();
}
#[typetag::serde]
impl SerdeImportable for Sampler<SpriteRenderPrimitive> {}
Expand Down Expand Up @@ -75,7 +75,7 @@ pub enum SpriteRenderChannel {
// 9ef0c4bb-45d2-8d45-b418-5001f89cbb0d
impl TypeUuid for Animation<SpriteRender> {
const UUID: type_uuid::Bytes =
*Uuid::from_u128(211268164769622779683751576167574715149).as_bytes();
*Uuid::from_u128(211_268_164_769_622_779_683_751_576_167_574_715_149).as_bytes();
}
register_asset_type!(Animation<SpriteRender> => Animation<SpriteRender>; AssetProcessorSystem<Animation<SpriteRender>>);

Expand Down
Loading

0 comments on commit 89ed34b

Please sign in to comment.