Skip to content

Commit

Permalink
Address clippy errors (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrea-c committed Dec 13, 2023
1 parent da13c69 commit cea139c
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 98 deletions.
8 changes: 3 additions & 5 deletions src/chaining/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ impl<T: TypePath + FromReflect + Clone> Chainable for ValueFrame<T> {
out_pose
} else if self.next_is_wrapped {
// First pose is active, but next pose wraps around
let out_pose = Self {
Self {
timestamp: self.timestamp,
prev: self.prev.clone(),
prev_timestamp: self.prev_timestamp,
next: other.prev.clone(),
next_timestamp: other.prev_timestamp + duration_first,
next_is_wrapped: false,
};

out_pose
}
} else {
self.clone()
}
Expand All @@ -51,7 +49,7 @@ impl<T: TypePath + FromReflect + Clone> Chainable for Option<ValueFrame<T>> {
let mut out = frame_1.clone();

if out.next_is_wrapped {
out.next_timestamp = out.next_timestamp + duration_second;
out.next_timestamp += duration_second;
}

Some(out)
Expand Down
1 change: 1 addition & 0 deletions src/core/animated_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub(crate) fn spawn_animated_scenes(
}
}

#[allow(clippy::type_complexity)]
pub(crate) fn process_animated_scenes(
mut commands: Commands,
unloaded_scenes: Query<
Expand Down
45 changes: 11 additions & 34 deletions src/core/animation_graph/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,10 @@ type Mapper<In, Out> =
fn(&AnimationNode, In, &EdgePath, &mut GraphContext, &mut GraphContextTmp) -> Out;
type ShortCircuit<Out> =
fn(&AnimationNode, &EdgePath, &mut GraphContext, &mut GraphContextTmp) -> Option<Out>;
type Combiner<Out> = fn(Out, Out) -> Out;

struct UpFns<In, Out> {
pub prepare: PrepareInput<In, Out>,
pub mapper: Mapper<HashMap<NodeInput, In>, Out>,
pub combiner: Combiner<Out>,
}

struct DownFns<In, Out> {
Expand All @@ -157,22 +155,15 @@ struct DownFns<In, Out> {

impl<I, O> Clone for UpFns<I, O> {
fn clone(&self) -> Self {
UpFns {
prepare: self.prepare,
mapper: self.mapper,
combiner: self.combiner,
}
*self
}
}

impl<I, O> Copy for UpFns<I, O> {}

impl<I, O> Clone for DownFns<I, O> {
fn clone(&self) -> Self {
DownFns {
prepare: self.prepare,
mapper: self.mapper,
}
*self
}
}

Expand Down Expand Up @@ -201,7 +192,7 @@ impl AnimationGraph {

pub fn add_node(&mut self, node: AnimationNode) {
let node_name = node.name.clone();
if &node_name == Self::INPUT_NODE || &node_name == Self::OUTPUT_NODE {
if node_name == Self::INPUT_NODE || node_name == Self::OUTPUT_NODE {
error!("Node name {node_name} is reserved");
panic!("Node name {node_name} is reserved")
}
Expand Down Expand Up @@ -294,6 +285,7 @@ impl AnimationGraph {
);
}

#[allow(clippy::too_many_arguments)]
fn map<SpecType, InputUp: Clone, OutputUp: Default, InputDown, OutputDown>(
&self,
node_name: &str,
Expand Down Expand Up @@ -336,7 +328,7 @@ impl AnimationGraph {

for k in recurse_spec.keys() {
let Some((in_node_name, in_edge_name)) =
self.node_edges.get(&(node_name.into(), k.into())).clone()
self.node_edges.get(&(node_name.into(), k.into()))
else {
continue;
};
Expand All @@ -351,7 +343,7 @@ impl AnimationGraph {
let new_down_input = down.map(|down| (down.prepare)(output_down.as_ref().unwrap(), k));

let output_up = self.map(
&in_node_name,
in_node_name,
new_path,
input_spec_extractor,
recurse_spec_extractor,
Expand All @@ -366,7 +358,7 @@ impl AnimationGraph {

if let Some(up) = up {
if in_spec.contains_key(k) {
let val = (up.prepare)(&output_up, &in_edge_name);
let val = (up.prepare)(&output_up, in_edge_name);
input_up.as_mut().unwrap().insert(k.clone(), val);
}
}
Expand All @@ -379,6 +371,7 @@ impl AnimationGraph {
}
}

#[allow(clippy::too_many_arguments)]
fn map_up<SpecType, InputUp: Clone, OutputUp: Default>(
&self,
node_name: &str,
Expand Down Expand Up @@ -406,6 +399,7 @@ impl AnimationGraph {
)
}

#[allow(clippy::too_many_arguments)]
fn map_down<SpecType, InputDown, OutputDown: Default>(
&self,
node_name: &str,
Expand Down Expand Up @@ -437,22 +431,10 @@ impl AnimationGraph {
fn prepare_input_index_hashmap<T: Clone>(outputs: &HashMap<NodeOutput, T>, edge: &str) -> T {
outputs
.get(edge)
.expect(&format!("Edge output {} not found!", edge))
.unwrap_or_else(|| panic!("Edge output {} not found!", edge))
.clone()
}

fn combiner_hashmap<T>(
mut master: HashMap<String, T>,
mut slave: HashMap<String, T>,
) -> HashMap<String, T> {
for (k, v) in slave.drain() {
if !master.contains_key(&k) {
master.insert(k, v);
}
}
master
}

/// Which inputs are needed to calculate parameter output of this node
fn parameter_input_spec_extractor(
n: &AnimationNode,
Expand All @@ -469,9 +451,7 @@ impl AnimationGraph {
context_tmp: &mut GraphContextTmp,
) -> HashMap<NodeInput, EdgeSpec> {
let mut spec = n.parameter_input_spec(context, context_tmp);
spec.fill_up(&n.time_dependent_input_spec(context, context_tmp), &|v| {
v.clone()
});
spec.fill_up(&n.time_dependent_input_spec(context, context_tmp), &|v| *v);
spec
}

Expand Down Expand Up @@ -552,7 +532,6 @@ impl AnimationGraph {
UpFns {
prepare: Self::prepare_input_index_hashmap,
mapper: Self::parameter_mapper,
combiner: Self::combiner_hashmap,
},
context,
context_tmp,
Expand Down Expand Up @@ -606,7 +585,6 @@ impl AnimationGraph {
UpFns {
prepare: Self::prepare_input_index_hashmap,
mapper: Self::duration_mapper,
combiner: Self::combiner_hashmap,
},
context,
context_tmp,
Expand Down Expand Up @@ -726,7 +704,6 @@ impl AnimationGraph {
UpFns {
prepare: Self::prepare_input_index_hashmap,
mapper: Self::time_dependent_mapper,
combiner: Self::combiner_hashmap,
},
context,
context_tmp,
Expand Down
12 changes: 5 additions & 7 deletions src/core/animation_graph/dot_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ pub trait ToDot {
let pdf_path_alt = "/tmp/bevy_animation_graph_dot.dot.pdf_alt";

{
let file = File::create(&path)?;
let file = File::create(path)?;
let mut writer = BufWriter::new(file);
self.to_dot(&mut writer, context, context_tmp)?;
}

{
let pdf_file_alt = File::create(&pdf_path_alt)?;
let pdf_file_alt = File::create(pdf_path_alt)?;
Command::new("dot")
.args([path, "-Tpdf"])
.stdout(pdf_file_alt)
Expand Down Expand Up @@ -225,7 +225,7 @@ fn write_debugdump(
write!(f, "<TR><TD COLSPAN=\"2\"><i>DebugDump</i></TD></TR>")?;
if let Some(param_cache) = context
.get_node_cache(&node.name)
.map_or(None, |nc| nc.parameter_cache.as_ref())
.and_then(|nc| nc.parameter_cache.as_ref())
{
write!(f, "<TR><TD COLSPAN=\"2\">Parameters</TD></TR>")?;
write!(f, "<TR>")?;
Expand All @@ -239,7 +239,7 @@ fn write_debugdump(
}
if let Some(duration_cache) = context
.get_node_cache(&node.name)
.map_or(None, |nc| nc.duration_cache.as_ref())
.and_then(|nc| nc.duration_cache.as_ref())
{
write!(f, "<TR><TD COLSPAN=\"2\">Durations</TD></TR>")?;
write!(f, "<TR>")?;
Expand Down Expand Up @@ -372,9 +372,7 @@ impl ToDot for AnimationGraph {
for ((end_node, end_edge), (start_node, start_edge)) in self.node_edges.iter() {
let node = self.nodes.get(start_node).unwrap();
let mut spec = node.parameter_output_spec(ctx, context_tmp);
spec.fill_up(&node.time_dependent_output_spec(ctx, context_tmp), &|v| {
v.clone()
});
spec.fill_up(&node.time_dependent_output_spec(ctx, context_tmp), &|v| *v);
let tp = spec.get(start_edge).unwrap();
let color = match tp {
EdgeSpec::PoseFrame => "chartreuse4",
Expand Down
10 changes: 5 additions & 5 deletions src/core/animation_graph/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ impl AssetLoader for GraphClipLoader {
let gltf: &Gltf = gltf_loaded_asset.get().unwrap();

let Some(clip_handle) = gltf.named_animations.get(&animation_name) else {
return Err(AssetLoaderError::GltfMissingLabel(animation_name.into()));
return Err(AssetLoaderError::GltfMissingLabel(animation_name));
};

let Some(clip_path) = clip_handle.path() else {
return Err(AssetLoaderError::GltfMissingLabel(animation_name.into()));
return Err(AssetLoaderError::GltfMissingLabel(animation_name));
};

let clip_bevy: bevy::animation::AnimationClip = gltf_loaded_asset
Expand Down Expand Up @@ -183,15 +183,15 @@ impl AssetLoader for AnimationGraphLoader {
}

for (td_name, td_spec) in &serial.input_time_dependent_spec {
graph.register_input_td(td_name, td_spec.clone());
graph.register_input_td(td_name, *td_spec);
}

for (p_name, p_spec) in &serial.output_parameter_spec {
graph.register_output_parameter(p_name, p_spec.clone());
graph.register_output_parameter(p_name, *p_spec);
}

for (td_name, td_spec) in &serial.output_time_dependent_spec {
graph.register_output_td(td_name, td_spec.clone());
graph.register_output_td(td_name, *td_spec);
}

for (parameter_name, (target_node, target_edge)) in &serial.input_edges {
Expand Down
16 changes: 12 additions & 4 deletions src/core/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ impl BoneFrame {
where
F: Fn(f32) -> f32,
{
self.rotation.as_mut().map(|v| v.map_ts(&f));
self.translation.as_mut().map(|v| v.map_ts(&f));
self.scale.as_mut().map(|v| v.map_ts(&f));
self.weights.as_mut().map(|v| v.map_ts(&f));
if let Some(v) = self.rotation.as_mut() {
v.map_ts(&f)
};
if let Some(v) = self.translation.as_mut() {
v.map_ts(&f)
};
if let Some(v) = self.scale.as_mut() {
v.map_ts(&f)
};
if let Some(v) = self.weights.as_mut() {
v.map_ts(&f)
};
}
}

Expand Down
16 changes: 3 additions & 13 deletions src/core/graph_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
};
use bevy::{asset::Assets, reflect::prelude::*, utils::HashMap};

#[derive(Reflect, Debug)]
#[derive(Reflect, Debug, Default)]
pub struct GraphContext {
/// Caches are double buffered
caches: [HashMap<String, AnimationCaches>; 2],
Expand All @@ -14,16 +14,6 @@ pub struct GraphContext {
subgraph_contexts: HashMap<String, GraphContext>,
}

impl Default for GraphContext {
fn default() -> Self {
Self {
caches: [HashMap::default(), HashMap::default()],
current_cache: 0,
subgraph_contexts: HashMap::default(),
}
}
}

/// Contains temprary data such as references to assets, gizmos, etc.
pub struct GraphContextTmp<'a> {
pub graph_clip_assets: &'a Assets<GraphClip>,
Expand Down Expand Up @@ -90,12 +80,12 @@ impl GraphContext {

pub fn get_other_parameters(&self, node: &str) -> Option<&ParameterCache> {
self.get_node_other_cache(node)
.map_or(None, |c| c.parameter_cache.as_ref())
.and_then(|c| c.parameter_cache.as_ref())
}

pub fn get_other_durations(&self, node: &str) -> Option<&DurationCache> {
self.get_node_other_cache(node)
.map_or(None, |c| c.duration_cache.as_ref())
.and_then(|c| c.duration_cache.as_ref())
}

pub fn get_other_times(&self, node: &str, path: &EdgePath) -> Option<&TimeCache> {
Expand Down
4 changes: 2 additions & 2 deletions src/core/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn run_animation_player(

let mut context_tmp = GraphContextTmp {
graph_clip_assets: graph_clips,
animation_graph_assets: &graphs,
animation_graph_assets: graphs,
};

let Some(out_pose) = player.query(&mut context_tmp) else {
Expand Down Expand Up @@ -232,7 +232,7 @@ fn apply_pose(
}
if let Some(weights) = &pose.weights {
if let Ok(morphs) = &mut morphs {
apply_morph_weights(morphs.weights_mut(), &weights);
apply_morph_weights(morphs.weights_mut(), weights);
}
}
}
Expand Down
Loading

0 comments on commit cea139c

Please sign in to comment.